From f6da27e53695ad1cc0e2a9490358decbbfdff5e5 Mon Sep 17 00:00:00 2001 From: Peng Haitao Date: Mon, 19 Nov 2012 01:53:07 -0500 Subject: 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 Reviewed-by: Carlos O'Donell --- sunrpc/bindrsvprt.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'sunrpc/bindrsvprt.c') 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 #include #include +#include + +/* + * 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) -- cgit v1.1