files: check the result of fdopen(), to avoid a possible crash
When safe_tempfile() returns a valid filename, it should also
return a valid open stream.
This fixes https://savannah.gnu.org/bugs/?61064.
Bug existed since version 1.3.8, commit 5e068c60
.
master
parent
51eb938fea
commit
eaff5ec9e5
|
@ -1469,13 +1469,15 @@ char *safe_tempfile(FILE **stream)
|
|||
|
||||
fd = mkstemp(tempfile_name);
|
||||
|
||||
if (fd == -1) {
|
||||
*stream = (fd > 0) ? fdopen(fd, "r+b") : NULL;
|
||||
|
||||
if (*stream == NULL) {
|
||||
if (fd > 0)
|
||||
close(fd);
|
||||
free(tempfile_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*stream = fdopen(fd, "r+b");
|
||||
|
||||
return tempfile_name;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue