]> Savannah Git Hosting - gnulib.git/commitdiff
setenv: Don't crash if malloc() returns NULL.
authorBruno Haible <bruno@clisp.org>
Fri, 2 Jun 2023 18:11:36 +0000 (20:11 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 4 Jun 2023 19:20:22 +0000 (21:20 +0200)
* lib/setenv.c (rpl_setenv): Check malloca() return value.

ChangeLog
lib/setenv.c

index a133b4c6b5d68990bc501e473e9812d46113657b..fcdea885ded32d713ef136f19b40a2da6099b6bb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2023-06-02  Bruno Haible  <bruno@clisp.org>
+
+       setenv: Don't crash if malloc() returns NULL.
+       * lib/setenv.c (rpl_setenv): Check malloca() return value.
+
 2023-06-01  Bruno Haible  <bruno@clisp.org>
 
        getprogname: Add support for ASCII-compatible environments in z/OS.
index ebfd4e550e8ea49de87ff0b2b94a788da1514eba..22b12fd01845f6df374f22d0e6ba69c00665786c 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992, 1995-2003, 2005-2022 Free Software Foundation, Inc.
+/* Copyright (C) 1992, 1995-2003, 2005-2023 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    This file is free software: you can redistribute it and/or modify
@@ -375,6 +375,11 @@ rpl_setenv (const char *name, const char *value, int replace)
           int saved_errno;
           size_t len = strlen (value);
           tmp = malloca (len + 2);
+          if (tmp == NULL)
+            {
+              errno = ENOMEM;
+              return -1;
+            }
           /* Since leading '=' is eaten, double it up.  */
           *tmp = '=';
           memcpy (tmp + 1, value, len + 1);