We can't use a pointer that was input to realloc(3), nor any pointers
that point to reallocated memory, without making sure that the memory
wasn't moved. If we do, the Behavior is Undefined.
Signed-off-by: Alejandro Colomar <alx@kernel.org>
*/
if ((newenvc & (NEWENVP_STEP - 1)) == 0) {
- char **__newenvp;
+ bool update_environ;
+ char **__newenvp;
/*
* If the resize operation succeeds we can
* happily go on, else print a message.
*/
+ update_environ = (environ == newenvp);
__newenvp = REALLOCARRAY(newenvp, newenvc + NEWENVP_STEP, char *);
* environ so that it doesn't point to some
* free memory area (realloc() could move it).
*/
- if (environ == newenvp) {
+ if (update_environ)
environ = __newenvp;
- }
newenvp = __newenvp;
} else {
(void) fputs (_("Environment overflow\n"), log_get_logfd());