Add some missing fdopen(3) checks (Domingo Alvarez Duarte)
This commit is contained in:
parent
308d8d17dc
commit
917aad3bcf
2 changed files with 3 additions and 5 deletions
5
tccelf.c
5
tccelf.c
|
@ -2423,11 +2423,10 @@ static int tcc_write_elf_file(TCCState *s1, const char *filename, int phnum,
|
||||||
mode = 0777;
|
mode = 0777;
|
||||||
unlink(filename);
|
unlink(filename);
|
||||||
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
|
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
|
||||||
if (fd < 0) {
|
if (fd < 0 || (f = fdopen(fd, "wb")) == NULL) {
|
||||||
tcc_error_noabort("could not write '%s'", filename);
|
tcc_error_noabort("could not write or fdopen '%s'", filename);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
f = fdopen(fd, "wb");
|
|
||||||
if (s1->verbose)
|
if (s1->verbose)
|
||||||
printf("<- %s\n", filename);
|
printf("<- %s\n", filename);
|
||||||
|
|
||||||
|
|
|
@ -795,11 +795,10 @@ ST_FUNC int macho_output_file(TCCState *s1, const char *filename)
|
||||||
mode = 0777;
|
mode = 0777;
|
||||||
unlink(filename);
|
unlink(filename);
|
||||||
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
|
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));
|
tcc_error_noabort("could not write '%s: %s'", filename, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
fp = fdopen(fd, "wb");
|
|
||||||
if (s1->verbose)
|
if (s1->verbose)
|
||||||
printf("<- %s\n", filename);
|
printf("<- %s\n", filename);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue