diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2015-09-11 01:39:08 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2015-09-11 01:39:08 +0200 |
commit | 280e26f17906c2c2fb39c33bee797e90f5cf0c40 (patch) | |
tree | e2d04ae635a852deb007cdce5d8f41440a747f5b /pflocal | |
parent | 5e8e02f53c47bcf108c64263249795f702b8b19a (diff) |
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.
Diffstat (limited to 'pflocal')
-rw-r--r-- | pflocal/sock.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/pflocal/sock.c b/pflocal/sock.c index 8076dd36..ef70d2c8 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; } |