From 54e1cabce616d89ad657731531620b7cd88fb8e2 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Fri, 21 Feb 2003 01:52:32 +0000 Subject: Update. * inet/rcmd.c (rresvport_af): Avoid using invliad values. Wrap around in search if port IPPORT_RESERVED/2 has been test. 2002-02-20 Paolo Bonzini * posix/regcomp.c: Remove inclusions. * posix/regexec.c: Likewise. * posix/regex_internal.c: Likewise. * posix/regex_internal.h: Add inclusions here. * posix/regex.c: Only include sys/types.h before regex.h. Include regex_internal.h here. Include regex_internal.c before regcomp.c and regexec.c (might expose more opportunities to the C compiler). * posix/regcomp.c (parse_expression): Fix construct rejected by SGI CC. * posix/regex_internal.h [!_LIBC] (__mempcpy): Fix typo. [!_LIBC] (__wcrtomb): New definition. [!_LIBC]: Conditionalize enabling of I18N on HAVE_WCSCOLL and HAVE_LOCALE_H as well. 2003-02-20 Ulrich Drepper --- inet/rcmd.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'inet') diff --git a/inet/rcmd.c b/inet/rcmd.c index 4737e6e..42871f7 100644 --- a/inet/rcmd.c +++ b/inet/rcmd.c @@ -464,7 +464,14 @@ rresvport_af(alport, family) #endif ss.ss_family = family; - for (;;) { + /* Ignore invalid values. */ + if (*alport < IPPORT_RESERVED / 2) + *alport = IPPORT_RESERVED / 2; + else if (*alport >= IPPORT_RESERVED) + *alport = IPPORT_RESERVED - 1; + + int start = *alport; + do { *sport = htons((uint16_t) *alport); if (__bind(s, (struct sockaddr *)&ss, len) >= 0) return s; @@ -472,10 +479,9 @@ rresvport_af(alport, family) (void)__close(s); return -1; } - (*alport)--; - if (*alport == IPPORT_RESERVED/2) - break; - } + if ((*alport)-- == IPPORT_RESERVED/2) + *alport = IPPORT_RESERVED - 1; + } while (*alport != start); (void)__close(s); __set_errno (EAGAIN); return -1; -- cgit v1.1