Skip to content

Commit 49d3582

Browse files
pmundkurAlasdair
authored andcommitted
Fix error check in load_elf().
If load_elf is erroneously given the name of a directory as an input stream, fread returns 0 while feof indicates no error, resulting in an infinite loop. Augmenting the error check with ferror fixes the problem.
1 parent b036bae commit 49d3582

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/elf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ void load_elf(char *filename, bool *is32bit_p, uint64_t *entry) {
439439
if (buffer == NULL) { goto fail; }
440440

441441
int s = fread(buffer+read, 1, size - read, in);
442-
if (s < 0) { goto fail; }
442+
if (s < 0 || ferror(in)) { goto fail; }
443443
read += s;
444444
}
445445
fclose(in);

0 commit comments

Comments
 (0)