From 6eb0b6ac2774bc10d7f6a86b8019bbdc6339f34a Mon Sep 17 00:00:00 2001 From: Peter Griess Date: Mon, 12 Jul 2010 08:48:33 -0700 Subject: [PATCH] Coverity fixes: src/node_net --- src/node_net.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/node_net.cc b/src/node_net.cc index 3f2597a064..0e8ad81971 100644 --- a/src/node_net.cc +++ b/src/node_net.cc @@ -35,6 +35,8 @@ #include #endif +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a))) + namespace node { @@ -61,8 +63,6 @@ static Persistent recv_msg_template; String::New("Bad file descriptor argument"))); \ } - - static inline bool SetCloseOnExec(int fd) { return (fcntl(fd, F_SETFD, FD_CLOEXEC) != -1); } @@ -197,13 +197,13 @@ static inline Handle ParseAddressArgs(Handle first, // UNIX String::Utf8Value path(first->ToString()); - if (path.length() > sizeof un.sun_path) { + if (path.length() >= ARRAY_SIZE(un.sun_path)) { return Exception::Error(String::New("Socket path too long")); } - memset(&un, 0, sizeof un); un.sun_family = AF_UNIX; - strcpy(un.sun_path, *path); + strncpy(un.sun_path, *path, ARRAY_SIZE(un.sun_path) - 1); + un.sun_path[ARRAY_SIZE(un.sun_path) - 1] = '\0'; addr = (struct sockaddr*)&un; addrlen = path.length() + sizeof(un.sun_family) + 1; @@ -628,6 +628,7 @@ static Handle RecvMsg(const Arguments& args) { iov[0].iov_len = len; struct msghdr msg; + msg.msg_flags = 0; msg.msg_iov = iov; msg.msg_iovlen = 1; msg.msg_name = NULL;