This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH][BZ #14806] Fix stack overflow in getaddrinfo() if host has many addresses.
- From: Michal Kubecek <mkubecek at suse dot cz>
- To: Ondřej Bílka <neleai at seznam dot cz>
- Cc: libc-alpha at sourceware dot org
- Date: Thu, 30 May 2013 18:20:49 +0200
- Subject: Re: [PATCH][BZ #14806] Fix stack overflow in getaddrinfo() if host has many addresses.
- References: <20130530135411 dot B8F9062C80 at unicorn dot suse dot cz> <20130530151841 dot GA6234 at domone dot kolej dot mff dot cuni dot cz>
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