This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On 6/6/12, Carlos O'Donell <carlos_odonell@mentor.com> wrote:
> On 6/5/2012 8:46 PM, Petr Baudis wrote:
>> 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.)
>
> This function is not listed as being thread-safe or async-signal safe
> in any API that I've seen documented.

If this really doesn't need to be thread-safe, then you could get rid
of the buffer completely using the non-reentrant getservbyport. It
would simplify the code some.

--
Dan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]