From: Bruno Haible Date: Fri, 2 Jun 2023 18:11:41 +0000 (+0200) Subject: striconveha: Don't crash if malloc() returns NULL. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=8c91d2ff2a7f6c6ece7c40c7588acdf29bdd6aba;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 fcdea885de..dce81056f4 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 66bff72172..f388c9f095 100644 --- a/lib/striconveha.c +++ b/lib/striconveha.c @@ -1,5 +1,5 @@ /* Character set conversion with error handling and autodetection. - Copyright (C) 2002, 2005, 2007, 2009-2022 Free Software Foundation, Inc. + Copyright (C) 2002, 2005, 2007, 2009-2023 Free Software Foundation, Inc. Written by Bruno Haible. This file is free software: you can redistribute it and/or modify @@ -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);