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][BZ #14806] Fix stack overflow in getaddrinfo() if host has many addresses.


On Thu, May 30, 2013 at 05:18:41PM +0200, Ondřej Bílka wrote:
> 
> > +/* The list of IPv6 addresses is usually very short but on some systems, it
> > +   can be very long (thousands of entries). So we want the implementation to
> > +   be fast for short lists but able to handle arbitrary length. Therefore we
> > +   keep one block of IN6AI_FIXED_SIZE entries on the stack and a linked list
> > +   of blocks of IN6AI_CHUNK_SIZE entries allocated by malloc() */
> 
> Is there external pointer to in6addrinfo structures? 

No, this is just a temporary storage. If we knew the number of them in
advance, we could directly allocate a contiguous block and we wouldn't
need this temporary storage at all.

> If not then doubling allocated amount is simpler to write and faster.

Do you mean keeping just one contiguous block and reallocating it to
twice of its size when we find it's not sufficient? This could lead to
copying already allocated entries several times but even so it could
be faster. Of course, in worst case we would use almost twice the space
we really need but current solution in fact always does that. We could
also substantially reduce the need of reallocations by starting with the
number of entries we had last time (plus some reserve) as the list of
addresses usually doesn't change too often (and too much).

I'm going to send a version working this way when I have it tested.

                                                         Michal Kubeček


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