From 69cf03b2365d8fda5e4f71f2827cad6938e65b0e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 2 Jun 2023 20:11:41 +0200 Subject: [PATCH] striconveha: Don't crash if malloc() returns NULL. * lib/striconveha.c (mem_iconveha, str_iconveha): Check malloca() return value. --- ChangeLog | 6 ++++++ lib/striconveha.c | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/ChangeLog b/ChangeLog index 80db20dee3..d21e60b5c1 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); -- 2.39.5