From a746481903d0f693c12d8c8045a10c8299476a29 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 2 Jun 2023 20:11:36 +0200 Subject: [PATCH] setenv: Don't crash if malloc() returns NULL. * lib/setenv.c (rpl_setenv): Check malloca() return value. --- ChangeLog | 5 +++++ lib/setenv.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index 9cb9ad7ba7..80db20dee3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2023-06-02 Bruno Haible + + setenv: Don't crash if malloc() returns NULL. + * lib/setenv.c (rpl_setenv): Check malloca() return value. + 2023-06-01 Bruno Haible getprogname: Add support for ASCII-compatible environments in z/OS. diff --git a/lib/setenv.c b/lib/setenv.c index f0b889969f..22b12fd018 100644 --- a/lib/setenv.c +++ b/lib/setenv.c @@ -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); -- 2.39.5