[PATCH] Fix for localalias.c bug

Jakub Jelinek jakub@redhat.com
Tue Oct 10 14:16:00 GMT 2000


Hi!

Below are two possible solutions for a pretty old bug in localealias.c which
is visible under ElectricFence:
If the string_space pool is too small, it is realloced, but realloc does not
guarantee it will return the same pointer as was passed to it, but we
already stored many string pointers to the old pool into the map array.
One fix I see is (assuming realloc usually will give the same address as
seems is the case in the common usage of setlocale in glibc, otherwise this
bug would have been noticed far before) in P2, basically we check if the
address changed and in the unlikely case that it changed we adjust the so
far created map[] entries.
The other fix is killing the realloc and replacing it with malloc - the
string pool does not have to be contiguous. I keep a linked list in the
first sizeof(char *) bytes of string pools so that they can be freed by
free_mem. This has the disadvantage of slightly higher overhead if realloc
would give the same address (at least because now we have to call free more
times) but big advantage if it would not (as there is no realloc, it does
not have to copy those thousands of bytes again and again, plus we don't
have to fix map[] entries).
Neither of these was tested, if you pick one solution you like, I'll test it
out.

	Jakub


More information about the Libc-hacker mailing list