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
2423 mode = 0777;2423 mode = 0777;
2424 unlink(filename);2424 unlink(filename);
2425 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);2425 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);
2426 if (fd < 0) {2426 if (fd < 0 || (f = fdopen(fd, "wb")) == NULL) {
2427 tcc_error_noabort("could not write '%s'", filename);2427 tcc_error_noabort("could not write or fdopen '%s'", filename);
2428 return -1;2428 return -1;
2429 }2429 }
2430 f = fdopen(fd, "wb");
2431 if (s1->verbose)2430 if (s1->verbose)
2432 printf("<- %s\n", filename);2431 printf("<- %s\n", filename);
2433 2432
tccmacho.c+1−2
@@ -795,11 +795,10 @@ ST_FUNC int macho_output_file(TCCState *s1, const char *filename) · 794 unmodified lines
795 mode = 0777;795 mode = 0777;
796 unlink(filename);796 unlink(filename);
797 fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode);797 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) {
799 tcc_error_noabort("could not write '%s: %s'", filename, strerror(errno));799 tcc_error_noabort("could not write '%s: %s'", filename, strerror(errno));
800 return -1;800 return -1;
801 }801 }
802 fp = fdopen(fd, "wb");
803 if (s1->verbose)802 if (s1->verbose)
804 printf("<- %s\n", filename);803 printf("<- %s\n", filename);
805 804

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