Fix SEGV by setting msg_controllen earlier.
authorPeter Griess <pg@std.in>
Tue, 4 May 2010 16:26:23 +0000 (11:26 -0500)
committerRyan Dahl <ry@tinyclouds.org>
Tue, 4 May 2010 17:32:01 +0000 (10:32 -0700)
- Some implementations of CMSG_FIRSTHDR() rely on msg_controllen being
  set correctly, else it returns NULL: see <linux/socket.h>.

src/node_net2.cc

index 2958e03..865bf7c 100644 (file)
@@ -671,12 +671,12 @@ static Handle<Value> SendFD(const Arguments& args) {
   msg.msg_namelen = 0;
   msg.msg_flags = 0;
   msg.msg_control = (void *) control_msg;
+  msg.msg_controllen = CMSG_LEN(sizeof(fd_to_send));
   cmsg = CMSG_FIRSTHDR(&msg);
   cmsg->cmsg_level = SOL_SOCKET;
   cmsg->cmsg_type = SCM_RIGHTS;
-  cmsg->cmsg_len = CMSG_LEN(sizeof(fd_to_send));
+  cmsg->cmsg_len = msg.msg_controllen;
   *(int*) CMSG_DATA(cmsg) = fd_to_send;
-  msg.msg_controllen = cmsg->cmsg_len;
 
   ssize_t written = sendmsg(fd, &msg, 0);