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

ChangeLog
lib/striconveha.c

index 48fe27441efec06da4e926cd411fb050c219d2d3..69e7f19cea4212f17821a24fc2dc56ed6f603788 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-06-02  Bruno Haible  <bruno@clisp.org>
+
+       striconveha: Don't crash if malloc() returns NULL.
+       * lib/striconveha.c (mem_iconveha, str_iconveha): Check malloca() return
+       value.
+
 2023-06-02  Bruno Haible  <bruno@clisp.org>
 
        setenv: Don't crash if malloc() returns NULL.
index ed88c84c1999d394d80654ec86cb94d87e9bc4bd..f388c9f09528428e1838c1acbfd6b69209719895 100644 (file)
@@ -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);