summaryrefslogtreecommitdiff
path: root/lib/socket.c
diff options
context:
space:
mode:
authorAndrew Rybchenko <Andrew.Rybchenko@oktetlabs.ru>2011-08-30 09:27:37 +0400
committerThomas Graf <tgraf@lsx.localdomain>2011-08-30 09:55:46 +0200
commitb367024167f15513a564b5834d31ec186ca79665 (patch)
tree7e8c70807b94ae32308c884c2c0d1a90eaa98d0c /lib/socket.c
parent4be7adbb71b3f4f31aecb46c9dbfaa4b1fa45009 (diff)
downloadlibnl-b367024167f15513a564b5834d31ec186ca79665.tar.gz
Local port leak on nl_socket_alloc/nl_socket_set_local_port(, 0)
I've found a bug in the following scenario (fragment of code): while (1) { struct nl_sock *sk = nl_socket_alloc(); if (sk == NULL) { fprintf(stderr, "Failed to allocate nl socket\n"); break; } nl_socket_set_local_port(sk, 0); nl_socket_free(sk); } The problem is that nl_socket_set_local_port(, 0) does not release local port if it is allocated before.
Diffstat (limited to 'lib/socket.c')
-rw-r--r--lib/socket.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/socket.c b/lib/socket.c
index 461cd418..60120fb2 100644
--- a/lib/socket.c
+++ b/lib/socket.c
@@ -268,7 +268,14 @@ void nl_socket_set_local_port(struct nl_sock *sk, uint32_t port)
{
if (port == 0) {
port = generate_local_port();
- sk->s_flags &= ~NL_OWN_PORT;
+ /*
+ * Release local port after generation of a new one to be
+ * able to change local port using nl_socket_set_local_port(, 0)
+ */
+ if (!(sk->s_flags & NL_OWN_PORT))
+ release_local_port(sk->s_local.nl_pid);
+ else
+ sk->s_flags &= ~NL_OWN_PORT;
} else {
if (!(sk->s_flags & NL_OWN_PORT))
release_local_port(sk->s_local.nl_pid);