Add some missing fdopen(3) checks (Domingo Alvarez Duarte)

This commit is contained in:
Steffen Nurpmeso 2022-02-28 21:19:41 +01:00
parent 308d8d17dc
commit 917aad3bcf
2 changed files with 3 additions and 5 deletions

View File

@ -2423,11 +2423,10 @@ static int tcc_write_elf_file(TCCState *s1, const char *filename, int phnum,
mode = 0777;
unlink(filename);
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
if (fd < 0) {
tcc_error_noabort("could not write '%s'", filename);
if (fd < 0 || (f = fdopen(fd, "wb")) == NULL) {
tcc_error_noabort("could not write or fdopen '%s'", filename);
return -1;
}
f = fdopen(fd, "wb");
if (s1->verbose)
printf("<- %s\n", filename);

View File

@ -795,11 +795,10 @@ ST_FUNC int macho_output_file(TCCState *s1, const char *filename)
mode = 0777;
unlink(filename);
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
if (fd < 0) {
if (fd < 0 || (fp = fdopen(fd, "wb")) == NULL) {
tcc_error_noabort("could not write '%s: %s'", filename, strerror(errno));
return -1;
}
fp = fdopen(fd, "wb");
if (s1->verbose)
printf("<- %s\n", filename);