svn commit: r316613 - in stable/11/lib/libc: gen iconv net regex rpc stdio stdlib
Pedro Giffuni
pfg at FreeBSD.org
Sat Apr 8 01:39:57 UTC 2017
Hello;
On 7/4/2017 19:19, Rodney W. Grimes wrote:
> [ Charset UTF-8 unsupported, converting... ]
>> ...
>> @@ -306,8 +306,8 @@ __enlarge_env(void)
>> envVarsTotal++;
>> if (envVarsTotal > envVarsSize) {
>> newEnvVarsSize = envVarsTotal * 2;
>> - tmpEnvVars = realloc(envVars, sizeof (*envVars) *
>> - newEnvVarsSize);
>> + tmpEnvVars = reallocarray(envVars, newEnvVarsSize,
>> + sizeof(*envVars));
>> if (tmpEnvVars == NULL) {
>> envVarsTotal--;
>> return (false);
>>
>>
> I am not sure, but isnt this a code pessimization as you now push
> an extra arg on the stack, and also remove the possiblity of compile
> time const calculation of foo * bar?
>
The implementation is simply a bounds-check around realloc().
I guess you could compare it with the result and effects of using calloc
(a, b)
instead of malloc (a*b) and a memset.
Oh, it *is* a pessimization, but it is insignificant, and it happens at
the precise
but rare time when something rather important (memory allocation) is
about to
happen. In a world full of malicious users that are actually looking for
new ways to
cause such overflows I think it's a pretty cheap price to pay.
I have stopped extending it through the tree for now due to 2 issues:
- Portability, it has been adopted by all the BSDs, newlib, and even
illumos
so it's less of an issue but perhaps it's better to wait some more.
- Compiler bugs: clang generated broken code when I tried to use it in
libpam
so I ended up reverting it (r315164). I can't really investigate it or
hunt down
other places where it may happen but it appears to happen only when one
of the parameters is signed!
Pedro.
More information about the svn-src-stable
mailing list