summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2021-05-01 01:03:41 +0200
committerBruno Haible <bruno@clisp.org>2021-05-01 01:04:23 +0200
commit751e83501400fa62d3e9834da0cf91f2d145e1d2 (patch)
tree87bcc870cfbc203f82005578296272edeb8d655b
parentafeeb21058d15e5250fff9fbea2c1fec011c061a (diff)
downloadgnulib-751e83501400fa62d3e9834da0cf91f2d145e1d2.tar.gz
gnulib-751e83501400fa62d3e9834da0cf91f2d145e1d2.tar.bz2
supersede: Fix crash when malloc() fails.
Found by GCC 11 '-fanalyzer'. * lib/supersede.c (create_temp_file): Don't crash when malloc() fails.
-rw-r--r--ChangeLog6
-rw-r--r--lib/supersede.c2
2 files changed, 8 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index a110509f6e..cb2c68df68 100644
--- 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
diff --git a/lib/supersede.c b/lib/supersede.c
index 7371e20e2b..61b4f04347 100644
--- a/lib/supersede.c
+++ b/lib/supersede.c
@@ -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);

Return to:

Send suggestions and report system problems to the System administrator.