1
1

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.
Этот коммит содержится в:
Benno Schulenberg 2021-08-20 10:28:42 +02:00
родитель 51eb938fea
Коммит 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;
}