summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar David Majnemer <majnemer@google.com>2022-07-18 22:24:32 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2022-07-18 22:25:22 -0700
commit0c8bd82e90bac01f8afc6afdd5754d9d9b16cf68 (patch)
treeeaba32198ac0e0806dea3f4e89dc41d7eb5b6c12
parente633c7110967b6d3e72c34266cd18a6db4ccfe38 (diff)
Check for negative return values from ReadFromOffset
In some places, we check if the amount we read is a multiple of some amount we are interested in. However, ReadFromOffset returns -1 when it errors. Certain record sizes can cause ReadFromOffset to cause us to think that we succeeded when we did not. It also results in confusing messages in logs. PiperOrigin-RevId: 461798762 Change-Id: I8c9c7f2cea4d1789e95e50833d5405239a47f02e
-rw-r--r--absl/debugging/symbolize_elf.inc8
1 files changed, 8 insertions, 0 deletions
diff --git a/absl/debugging/symbolize_elf.inc b/absl/debugging/symbolize_elf.inc
index 5d6c8df3..fa401ae8 100644
--- a/absl/debugging/symbolize_elf.inc
+++ b/absl/debugging/symbolize_elf.inc
@@ -489,6 +489,13 @@ static ABSL_ATTRIBUTE_NOINLINE bool GetSectionHeaderByType(
(buf_bytes > num_bytes_left) ? num_bytes_left : buf_bytes;
const off_t offset = sh_offset + i * sizeof(buf[0]);
const ssize_t len = ReadFromOffset(fd, buf, num_bytes_to_read, offset);
+ if (len < 0) {
+ ABSL_RAW_LOG(
+ WARNING,
+ "Reading %zd bytes from offset %ju returned %zd which is negative.",
+ num_bytes_to_read, static_cast<intmax_t>(offset), len);
+ return false;
+ }
if (len % sizeof(buf[0]) != 0) {
ABSL_RAW_LOG(
WARNING,
@@ -693,6 +700,7 @@ static ABSL_ATTRIBUTE_NOINLINE FindSymbolResult FindSymbol(
const int entries_in_chunk = std::min(num_remaining_symbols, buf_entries);
const int bytes_in_chunk = entries_in_chunk * sizeof(buf[0]);
const ssize_t len = ReadFromOffset(fd, buf, bytes_in_chunk, offset);
+ SAFE_ASSERT(len >= 0);
SAFE_ASSERT(len % sizeof(buf[0]) == 0);
const ssize_t num_symbols_in_buf = len / sizeof(buf[0]);
SAFE_ASSERT(num_symbols_in_buf <= entries_in_chunk);