From: Bruno Haible Date: Fri, 30 Apr 2021 23:03:41 +0000 (+0200) Subject: supersede: Fix crash when malloc() fails. X-Git-Tag: v1.0~2910 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=751e83501400fa62d3e9834da0cf91f2d145e1d2;p=thirdparty%2Fgnulib.git 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/ChangeLog b/ChangeLog index a110509f6e..cb2c68df68 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2021-04-30 Bruno Haible + + 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 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);