aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2022-04-28 19:39:28 +0200
committerJohannes Stoelp <johannes.stoelp@gmail.com>2022-04-28 19:39:28 +0200
commit15f13f74b67a8d46d8429d7f53128a167c84eebd (patch)
treeff96a16293d88f822859fc79bc45c58d33a56f85
parentb368a18a914a44fd74896b7b1ac7a2530b2bdcb3 (diff)
downloadelfload-15f13f74b67a8d46d8429d7f53128a167c84eebd.tar.gz
elfload-15f13f74b67a8d46d8429d7f53128a167c84eebd.zip
check mul/add when indexing into phdr
-rw-r--r--src/lib.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index d3f5b4e..a5d3a7c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -242,7 +242,8 @@ impl Elf<'_> {
let phoff = usize::try_from(phoff).expect("phoff too large!");
for ph in 0..phnum {
- let pos = phoff + usize::from(ph * phentsize);
+ let off = ph.checked_mul(phentsize).map(usize::from).expect("phdr offset overflowed");
+ let pos = phoff.checked_add(off).expect("phdr position overflowed");
r.set_pos(pos);
// We only care about load segments.