]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/env.c: treat out of memory condition as error
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 31 Mar 2024 10:14:04 +0000 (12:14 +0200)
committerAlejandro Colomar <alx@kernel.org>
Thu, 4 Apr 2024 18:12:03 +0000 (20:12 +0200)
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 <alx@kernel.org>
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
lib/env.c

index f2d35d71fe150506cbbaedbca0e50cc6f1e062eb..9b5fd32f50a3d47c502167005a6c70c6ce4929c9 100644 (file)
--- 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;
        }
 
        /*