From: Tobias Stoeckmann Date: Sun, 31 Mar 2024 10:14:04 +0000 (+0200) Subject: lib/env.c: treat out of memory condition as error X-Git-Tag: 4.15.2~55 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5f5b21fd5cbf9ef3d19d3a5f1eb24bdc301bbbd7;p=thirdparty%2Fshadow.git lib/env.c: treat out of memory condition as error If not enough memory is available for more environment variables, treat it exactly like not enough memory for new environment variable content. Reviewed-by: Alejandro Colomar Signed-off-by: Tobias Stoeckmann --- diff --git a/lib/env.c b/lib/env.c index f2d35d71f..9b5fd32f5 100644 --- a/lib/env.c +++ b/lib/env.c @@ -127,30 +127,18 @@ void addenv (const char *string, /*@null@*/const char *value) if ((newenvc & (NEWENVP_STEP - 1)) == 0) { bool update_environ; - char **__newenvp; - /* - * If the resize operation succeeds we can - * happily go on, else print a message. - */ update_environ = (environ == newenvp); - __newenvp = REALLOC(newenvp, newenvc + NEWENVP_STEP, char *); - - if (NULL != __newenvp) { - /* - * If this is our current environment, update - * environ so that it doesn't point to some - * free memory area (realloc() could move it). - */ - if (update_environ) - environ = __newenvp; - newenvp = __newenvp; - } else { - (void) fputs (_("Environment overflow\n"), log_get_logfd()); - newenvc--; - free (newenvp[newenvc]); - } + newenvp = XREALLOC(newenvp, newenvc + NEWENVP_STEP, char *); + + /* + * If this is our current environment, update + * environ so that it doesn't point to some + * free memory area (realloc() could move it). + */ + if (update_environ) + environ = newenvp; } /*