Skip to content

Commit c932d6b

Browse files
authored
Merge pull request google#367 from bsilver8192/master
Don't crash on some forms of invalid ELF files
2 parents 65c554f + 857f1b2 commit c932d6b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/symbolize.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ GetSectionHeaderByType(const int fd, ElfW(Half) sh_num, const off_t sh_offset,
209209
(sizeof(buf) > num_bytes_left) ? num_bytes_left : sizeof(buf);
210210
const ssize_t len = ReadFromOffset(fd, buf, num_bytes_to_read,
211211
sh_offset + i * sizeof(buf[0]));
212+
if (len == -1) {
213+
return false;
214+
}
212215
SAFE_ASSERT(len % sizeof(buf[0]) == 0);
213216
const ssize_t num_headers_in_buf = len / sizeof(buf[0]);
214217
SAFE_ASSERT(num_headers_in_buf <= sizeof(buf) / sizeof(buf[0]));
@@ -299,6 +302,9 @@ FindSymbol(uint64_t pc, const int fd, char *out, int out_size,
299302
// Read at most NUM_SYMBOLS symbols at once to save read() calls.
300303
ElfW(Sym) buf[NUM_SYMBOLS];
301304
const ssize_t len = ReadFromOffset(fd, &buf, sizeof(buf), offset);
305+
if (len == -1) {
306+
return false;
307+
}
302308
SAFE_ASSERT(len % sizeof(buf[0]) == 0);
303309
const ssize_t num_symbols_in_buf = len / sizeof(buf[0]);
304310
SAFE_ASSERT(num_symbols_in_buf <= sizeof(buf)/sizeof(buf[0]));

0 commit comments

Comments
 (0)