]> xenbits.xensource.com Git - xcp/xen-api-libs.git/commitdiff
CA-38105: Fix segfault in fork-and-exec-daemon.
authorJon Ludlam <Jonathan.Ludlam@eu.citrix.com <Jon Ludlam <Jonathan.Ludlam@eu.citrix.com>
Mon, 8 Mar 2010 11:28:56 +0000 (11:28 +0000)
committerJon Ludlam <Jonathan.Ludlam@eu.citrix.com <Jon Ludlam <Jonathan.Ludlam@eu.citrix.com>
Mon, 8 Mar 2010 11:28:56 +0000 (11:28 +0000)
The segfault would have happened when a message was receieved on this socket without an associated fd being sent. This is bad behaviour on the part of the client, but shouldn't cause a segfault. This patch fixes the segfault, but we'll need to fix the client too!

Signed-off-by: Jon Ludlam <Jonathan.Ludlam@eu.citrix.com
stdext/unixext_stubs.c

index a01de8ff4b8d6a7d1a3334dd355c0a64c99972e5..7941b5a1c98f22b62d89f809601b46dca74603e9 100644 (file)
@@ -382,7 +382,7 @@ CAMLprim value stub_unix_recv_fd(value sock, value buff, value ofs, value len, v
   if(ret == -1) 
     unixext_error(errno);
 
-  if(ret> 0) {
+  if(ret>0 && msg.msg_controllen>0) {
     cmsg = CMSG_FIRSTHDR(&msg);
     if(cmsg->cmsg_level == SOL_SOCKET && (cmsg->cmsg_type == SCM_RIGHTS)) {
       fd=Val_int(*(int*)CMSG_DATA(cmsg));