Skip to content

Commit 857f1b2

Browse files
committed
Don't crash on some forms of invalid ELF files
With a few tweaks, it will fail to look up symbol names in these cases instead.
1 parent 39318b6 commit 857f1b2

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)