[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
supersede: Fix crash when malloc() fails
From: |
Bruno Haible |
Subject: |
supersede: Fix crash when malloc() fails |
Date: |
Sat, 01 May 2021 01:04:57 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-206-generic; KDE/5.18.0; x86_64; ; ) |
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);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- supersede: Fix crash when malloc() fails,
Bruno Haible <=