History

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

Steffen Nurpmeso committed 4 years ago

Commit 917aad31 parent 308d8d12 files · +3 −5Browse files

Unified · Split

2 files
  1. tccelf.c +2 −3
  2. tccmacho.c +1 −2
tccelf.c+2−3
@@ -2423,11 +2423,10 @@ static int tcc_write_elf_file(TCCState *s1, const char *filename, int phnum, · 2422 unmodified lines
24232423 mode = 0777;
24242424 unlink(filename);
24252425 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
2426− if (fd < 0) {
2427− tcc_error_noabort("could not write '%s'", filename);
2426+ if (fd < 0 || (f = fdopen(fd, "wb")) == NULL) {
2427+ tcc_error_noabort("could not write or fdopen '%s'", filename);
24282428 return -1;
24292429 }
2430− f = fdopen(fd, "wb");
24312430 if (s1->verbose)
24322431 printf("<- %s\n", filename);
24332432
tccmacho.c+1−2
@@ -795,11 +795,10 @@ ST_FUNC int macho_output_file(TCCState *s1, const char *filename) · 794 unmodified lines
795795 mode = 0777;
796796 unlink(filename);
797797 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
798− if (fd < 0) {
798+ if (fd < 0 || (fp = fdopen(fd, "wb")) == NULL) {
799799 tcc_error_noabort("could not write '%s: %s'", filename, strerror(errno));
800800 return -1;
801801 }
802− fp = fdopen(fd, "wb");
803802 if (s1->verbose)
804803 printf("<- %s\n", filename);
805804

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t