This is the mail archive of the cygwin-developers@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: cygwin_bind bug.


On Thu, Nov 25, 1999 at 10:38:28AM +0900, Kazuhiro Fujieda wrote:
>>>> On Wed, 24 Nov 1999 19:24:13 -0500
>>>> Chris Faylor <cgf@cygnus.com> said:
>
>> Is this patch against the latest snapshot?  Corinna has submitted
>> some changes to some of this code recently.  It is in the latest
>> snapshot.
>
>Yes, it is against the latest snapshot. Corinna's changes can't
>work properly by this bug. In her changes, cygwin_bind returns 0
>even though _open fails. Because `res' is set to 0 by `getsockname'.

In that case, why even use an intermediate variable?  Why not just check
the results from bind and getsockname directly?

cgf
Index: net.cc
===================================================================
RCS file: /cvs/cvsfiles/devo/winsup/net.cc,v
retrieving revision 1.84
diff -u -p -r1.84 net.cc
--- net.cc	1999/11/23 22:55:27	1.84
+++ net.cc	1999/11/25 01:56:21
@@ -766,18 +766,16 @@ cygwin_bind (int fd, struct sockaddr *my
 	  sin.sin_family = AF_INET;
 	  sin.sin_port = 0;
 	  sin.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
-	  res = bind (sock->get_socket (), (sockaddr *) &sin, len);
-	  if (res)
+	  if (bind (sock->get_socket (), (sockaddr *) &sin, len))
 	    {
-	      set_winsock_errno ();
 	      syscall_printf ("AF_UNIX: bind failed %d", get_errno ());
+	      set_winsock_errno ();
 	      goto out;
 	    }
-	  res = getsockname (sock->get_socket (), (sockaddr *) &sin, &len);
-	  if (res)
+	  if (getsockname (sock->get_socket (), (sockaddr *) &sin, &len))
 	    {
-	      set_winsock_errno ();
 	      syscall_printf ("AF_UNIX: getsockname failed %d", get_errno ());
+	      set_winsock_errno ();
 	      goto out;
 	    }
 
@@ -803,27 +801,25 @@ cygwin_bind (int fd, struct sockaddr *my
           /* Note that the terminating nul is written.  */
           if (_write (fd, buf, len) != len)
             {
-              int saved_errno = get_errno ();
+	      save_errno here;
               _close (fd);
               _unlink (un_addr->sun_path);
-              set_errno (saved_errno);
             }
           else
             {
               _close (fd);
               chmod (un_addr->sun_path,
                 (S_IFSOCK | S_IRWXU | S_IRWXG | S_IRWXO) & ~myself->umask);
-              res = 0;
             }
 #undef un_addr
 	}
-      else
+      else if (bind (sock->get_socket (), my_addr, addrlen))
 	{
-	  res = bind (sock->get_socket (), my_addr, addrlen);
-	  if (res)
-	    set_winsock_errno ();
+	  set_winsock_errno ();
+	  goto out;
 	}
     }
+
 out:
   syscall_printf ("%d = bind (%d, %x, %d)", res, fd, my_addr, addrlen);
   return res;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]