[PATCH] Don't bind to registered ports in bindresvport

Petr Baudis pasky@ucw.cz
Wed Jun 6 00:46:00 GMT 2012


On Fri, Jun 01, 2012 at 11:03:53PM -0400, Carlos O'Donell wrote:
> On Fri, Jun 1, 2012 at 4:01 PM, Dan Nicholson <dbn.lists@gmail.com> wrote:
> > @@ -74,24 +76,50 @@ bindresvport (int sd, struct sockaddr_in *sin)
> >
> >   int nports = ENDPORT - startport + 1;
> >   int endport = ENDPORT;
> > +  bool_t chkport = TRUE;
> > +  struct servent serv;
> > +  char buf[1024];
> 
> A global static buffer of this size should come from malloc (and get
> allocated once).

  Is there a reason for explicitly making this non-thread-safe? Won't
that break existing programs?

  (The current code also uses two statics, but running the function
multiple times in parallel shouldn't result in anything worse than
slightly scattered port allocations, if I read the code right.)

> There is precedence for using alloca, but I'd like to avoid that.

  Why? __MAX_ALLOCA_CUTOFF is currently at 65536, so 1024 bytes on
stack should be a non-issue.

-- 
				Petr "Pasky" Baudis
	Smart data structures and dumb code works a lot better
	than the other way around.  -- Eric S. Raymond



More information about the Libc-alpha mailing list