]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
bindresvport() uses two static variables port and startport which are not
authorPeng Haitao <penght@cn.fujitsu.com>
Mon, 19 Nov 2012 06:53:07 +0000 (01:53 -0500)
committerCarlos O'Donell <carlos@systemhalted.org>
Mon, 19 Nov 2012 07:05:12 +0000 (02:05 -0500)
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>
ChangeLog
NEWS
sunrpc/bindrsvprt.c

index 63e00edcb151b97188cd133cc9170f10c190bd1a..8f2f6d221c42b2e5b974848c600633c35fedfce9 100644 (file)
--- 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 6e8c6c28d677bfab8a9932c48c391994c8d9511f..d3e64c40d85dd72b71abbb756aae5205266cf01f 100644 (file)
--- 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.
 
index d493c9f23e19377904a9050d54d5e0c24ff96864..e6a1b0b0b35e301b3cbe5a68edcc536b0105d05a 100644 (file)
 #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)