aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeng Haitao <penght@cn.fujitsu.com>2012-11-19 01:53:07 -0500
committerCarlos O'Donell <carlos@systemhalted.org>2012-11-19 02:05:12 -0500
commitf6da27e53695ad1cc0e2a9490358decbbfdff5e5 (patch)
treeee71c15d35def733fe7580fa7a5d3a2813ff1a2d
parent1f51ee9246b048d8966c36ddd2c26d7e0f927d83 (diff)
downloadglibc-f6da27e53695ad1cc0e2a9490358decbbfdff5e5.zip
glibc-f6da27e53695ad1cc0e2a9490358decbbfdff5e5.tar.gz
glibc-f6da27e53695ad1cc0e2a9490358decbbfdff5e5.tar.bz2
bindresvport() uses two static variables port and startport which are not
protected. It is not safe when in multithread circumstance. bindresvport() select a port number from the range 512 to 1023, when in multithread circumstance, the port may be 1024. So the static variables will be protected. Signed-off-by: Peng Haitao <penght@cn.fujitsu.com> Reviewed-by: Carlos O'Donell <carlos@systemhalted.org>
-rw-r--r--ChangeLog5
-rw-r--r--NEWS18
-rw-r--r--sunrpc/bindrsvprt.c11
3 files changed, 25 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 63e00ed..8f2f6d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2012-11-19 Peng Haitao <penght@cn.fujitsu.com>
+
+ [BZ #13763]
+ * sunrpc/bindrsvprt.c: Add lock to protect static variable.
+
2012-11-19 Steve McIntyre <steve.mcintyre@linaro.org>
* sysdeps/generic/ldconfig.h (FLAG_AARCH64_LIB64): New macro.
diff --git a/NEWS b/NEWS
index 6e8c6c2..d3e64c4 100644
--- a/NEWS
+++ b/NEWS
@@ -12,15 +12,15 @@ Version 2.17
1349, 3439, 3479, 3665, 5044, 5246, 5298, 5400, 6530, 6778, 6808, 9685,
9914, 10014, 10038, 10631, 10873, 11438, 11607, 11638, 11741, 12140,
13412, 13542, 13601, 13603, 13604, 13629, 13679, 13696, 13698, 13717,
- 13741, 13939, 13950, 13952, 13966, 14042, 14047, 14090, 14150, 14151,
- 14152, 14154, 14157, 14166, 14173, 14195, 14237, 14251, 14252, 14283,
- 14298, 14303, 14307, 14328, 14331, 14336, 14337, 14347, 14349, 14368,
- 14376, 14417, 14459, 14476, 14477, 14501, 14505, 14510, 14516, 14518,
- 14519, 14530, 14532, 14538, 14543, 14544, 14545, 14557, 14562, 14568,
- 14576, 14579, 14583, 14587, 14595, 14602, 14610, 14621, 14638, 14645,
- 14648, 14652, 14660, 14661, 14669, 14672, 14683, 14694, 14716, 14743,
- 14767, 14783, 14784, 14785, 14793, 14796, 14797, 14801, 14805, 14807,
- 14809, 14811, 14815, 14821, 14824, 14828, 14831, 14838.
+ 13741, 13763, 13939, 13950, 13952, 13966, 14042, 14047, 14090, 14150,
+ 14151, 14152, 14154, 14157, 14166, 14173, 14195, 14237, 14251, 14252,
+ 14283, 14298, 14303, 14307, 14328, 14331, 14336, 14337, 14347, 14349,
+ 14368, 14376, 14417, 14459, 14476, 14477, 14501, 14505, 14510, 14516,
+ 14518, 14519, 14530, 14532, 14538, 14543, 14544, 14545, 14557, 14562,
+ 14568, 14576, 14579, 14583, 14587, 14595, 14602, 14610, 14621, 14638,
+ 14645, 14648, 14652, 14660, 14661, 14669, 14672, 14683, 14694, 14716,
+ 14743, 14767, 14783, 14784, 14785, 14793, 14796, 14797, 14801, 14805,
+ 14807, 14809, 14811, 14815, 14821, 14824, 14828, 14831, 14838.
* Port to ARM AArch64 contributed by Linaro.
diff --git a/sunrpc/bindrsvprt.c b/sunrpc/bindrsvprt.c
index d493c9f..e6a1b0b 100644
--- a/sunrpc/bindrsvprt.c
+++ b/sunrpc/bindrsvprt.c
@@ -35,6 +35,12 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
+#include <bits/libc-lock.h>
+
+/*
+ * Locks the static variables in this file.
+ */
+__libc_lock_define_initialized (static, lock);
/*
* Bind a socket to a privileged IP port
@@ -74,6 +80,9 @@ bindresvport (int sd, struct sockaddr_in *sin)
int nports = ENDPORT - startport + 1;
int endport = ENDPORT;
+
+ __libc_lock_lock (lock);
+
again:
for (i = 0; i < nports; ++i)
{
@@ -94,6 +103,8 @@ bindresvport (int sd, struct sockaddr_in *sin)
goto again;
}
+ __libc_lock_unlock (lock);
+
return res;
}
libc_hidden_def (bindresvport)