commit-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[hurd] 23/30: Fix sock_bind(sock,NULL) support


From: Samuel Thibault
Subject: [hurd] 23/30: Fix sock_bind(sock,NULL) support
Date: Tue, 22 Sep 2015 21:51:59 +0000

This is an automated email from the git hooks/post-receive script.

sthibault pushed a commit to branch upstream
in repository hurd.

commit 280e26f17906c2c2fb39c33bee797e90f5cf0c40
Author: Samuel Thibault <address@hidden>
Date:   Fri Sep 11 01:39:08 2015 +0200

    Fix sock_bind(sock,NULL) support
    
    * pflocal/sock.c (sock_bind): When addr is NULL, do not take/release its
    mutex. When old_addr is also NULL, return EINVAL. When old_addr is not NULL,
    deref old_addr instead of addr.
---
 pflocal/sock.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/pflocal/sock.c b/pflocal/sock.c
index 8076dd3..ef70d2c 100644
--- a/pflocal/sock.c
+++ b/pflocal/sock.c
@@ -277,12 +277,15 @@ sock_bind (struct sock *sock, struct addr *addr)
   error_t err = 0;
   struct addr *old_addr;
 
-  pthread_mutex_lock (&addr->lock);
+  if (addr)
+    pthread_mutex_lock (&addr->lock);
   pthread_mutex_lock (&sock->lock);
 
   old_addr = sock->addr;
   if (addr && old_addr)
     err = EINVAL;              /* SOCK already bound.  */
+  else if (!addr && !old_addr)
+    err = EINVAL;              /* SOCK already bound.  */
   else if (addr && addr->sock)
     err = EADDRINUSE;          /* Something else already bound ADDR.  */
   else if (addr)
@@ -303,13 +306,14 @@ sock_bind (struct sock *sock, struct addr *addr)
          /* Note that we don't have to worry about SOCK's ref count going to
             zero because whoever's calling us should be holding a ref.  */
          sock->refs--;
-         ports_port_deref_weak (addr);
+         ports_port_deref_weak (old_addr);
          assert (sock->refs > 0);      /* But make sure... */
        }
     }
 
   pthread_mutex_unlock (&sock->lock);
-  pthread_mutex_unlock (&addr->lock);
+  if (addr)
+    pthread_mutex_unlock (&addr->lock);
 
   return err;
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-hurd/hurd.git



reply via email to

[Prev in Thread] Current Thread [Next in Thread]