]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
libgrep: Don't crash upon out-of-memory.
authorBruno Haible <bruno@clisp.org>
Fri, 2 Jun 2023 23:22:53 +0000 (01:22 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 2 Jun 2023 23:22:53 +0000 (01:22 +0200)
Pinpointed by gcc 13 warning:
warning: use of possibly-NULL ‘mb_properties’ where non-null expected [CWE-690] [-Wanalyzer-possible-null-argument]

* gettext-tools/libgrep/m-fgrep.c (check_multibyte_string): Check the malloc()
return value.

gettext-tools/libgrep/m-fgrep.c

index 3589675baf3e8fcc5ff18e2d9cfa6be1df3bc366..6ae822f6a8416bc40392df3c7da5aba3519d477d 100644 (file)
@@ -112,10 +112,14 @@ Fcompile (const char *pattern, size_t pattern_size,
 static char*
 check_multibyte_string (const char *buf, size_t buf_size)
 {
-  char *mb_properties = (char *) malloc (buf_size);
+  char *mb_properties;
   mbstate_t cur_state;
   int i;
 
+  mb_properties = (char *) malloc (buf_size);
+  if (mb_properties == NULL)
+    error (exit_failure, 0, _("memory exhausted"));
+
   memset (&cur_state, 0, sizeof (mbstate_t));
   memset (mb_properties, 0, sizeof (char) * buf_size);
   for (i = 0; i < buf_size ;)