From: Bruno Haible Date: Fri, 2 Jun 2023 18:11:41 +0000 (+0200) Subject: striconveha: Don't crash if malloc() returns NULL. X-Git-Tag: v1.0~1268 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=fce9817d48c97339c3f66a92e72faba8e69d405c;p=gnulib.git striconveha: Don't crash if malloc() returns NULL. * lib/striconveha.c (mem_iconveha, str_iconveha): Check malloca() return value. --- diff --git a/ChangeLog b/ChangeLog index 48fe27441e..69e7f19cea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2023-06-02 Bruno Haible + + striconveha: Don't crash if malloc() returns NULL. + * lib/striconveha.c (mem_iconveha, str_iconveha): Check malloca() return + value. + 2023-06-02 Bruno Haible setenv: Don't crash if malloc() returns NULL. diff --git a/lib/striconveha.c b/lib/striconveha.c index ed88c84c19..f388c9f095 100644 --- a/lib/striconveha.c +++ b/lib/striconveha.c @@ -234,6 +234,11 @@ mem_iconveha (const char *src, size_t srclen, int retval; size_t len = strlen (to_codeset); char *to_codeset_suffixed = (char *) malloca (len + 10 + 1); + if (to_codeset_suffixed == NULL) + { + errno = ENOMEM; + return -1; + } memcpy (to_codeset_suffixed, to_codeset, len); memcpy (to_codeset_suffixed + len, "//TRANSLIT", 10 + 1); @@ -336,6 +341,11 @@ str_iconveha (const char *src, char *result; size_t len = strlen (to_codeset); char *to_codeset_suffixed = (char *) malloca (len + 10 + 1); + if (to_codeset_suffixed == NULL) + { + errno = ENOMEM; + return NULL; + } memcpy (to_codeset_suffixed, to_codeset, len); memcpy (to_codeset_suffixed + len, "//TRANSLIT", 10 + 1);