]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
supersede: Fix crash when malloc() fails.
authorBruno Haible <bruno@clisp.org>
Fri, 30 Apr 2021 23:03:41 +0000 (01:03 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 30 Apr 2021 23:04:23 +0000 (01:04 +0200)
Found by GCC 11 '-fanalyzer'.

* lib/supersede.c (create_temp_file): Don't crash when malloc() fails.

ChangeLog
lib/supersede.c

index a110509f6eb9d33219cf25b959966f05214e6dc6..cb2c68df6817bd1b712f44dc5212d0c4832d7c1e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2021-04-30  Bruno Haible  <bruno@clisp.org>
+
+       supersede: Fix crash when malloc() fails.
+       Found by GCC 11 '-fanalyzer'.
+       * lib/supersede.c (create_temp_file): Don't crash when malloc() fails.
+
 2021-04-27  Paul Eggert  <eggert@cs.ucla.edu>
 
        libc-config: fix include problem on older Debian
index 7371e20e2b25ae45c2958ce2e49d3162fc815bfb..61b4f04347378663aa45e62d7538629f97f6a6a4 100644 (file)
@@ -60,6 +60,8 @@ create_temp_file (char *canon_filename, int flags, mode_t mode,
   /* The temporary file needs to be in the same directory, otherwise the
      final rename may fail.  */
   char *temp_filename = (char *) malloc (canon_filename_length + 7 + 1);
+  if (temp_filename == NULL)
+    return -1;
   memcpy (temp_filename, canon_filename, canon_filename_length);
   memcpy (temp_filename + canon_filename_length, ".XXXXXX", 7 + 1);