* supersede: Fix crash when malloc() fails
@ 2021-04-30 23:04 Bruno Haible
0 siblings, 0 replies; only message in thread
From: Bruno Haible @ 2021-04-30 23:04 UTC (permalink / raw)
To: bug-gnulib
Compiling a testdir with CC="gcc -fanalyzer" produced this warning:
gllib/supersede.c:63:3: warning: use of possibly-NULL 'temp_filename' where non-null expected [CWE-690] [-Wanalyzer-possible-null-argument]
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.
diff --git a/lib/supersede.c b/lib/supersede.c
index 7371e20..61b4f04 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);
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-04-30 23:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-30 23:04 supersede: Fix crash when malloc() fails Bruno Haible
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).