]> 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>
Sun, 4 Jun 2023 19:20:52 +0000 (21:20 +0200)
* lib/striconveha.c (mem_iconveha, str_iconveha): Check malloca() return
value.

ChangeLog
lib/striconveha.c

index fcdea885ded32d713ef136f19b40a2da6099b6bb..dce81056f4e1d5c7726040750f717106f6cbf5b6 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 66bff72172cdb09d140d5a0924f3bc3f18c4299b..f388c9f09528428e1838c1acbfd6b69209719895 100644 (file)
@@ -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);