summaryrefslogtreecommitdiff
path: root/src/elf.rs
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-11-06 22:53:44 -0500
committerpommicket <pommicket@gmail.com>2022-11-06 22:53:44 -0500
commit2c068ecc21a972aa00f2871a4405e31547bf765a (patch)
tree94442139f33b5c33482fae6007298e6526dc5dce /src/elf.rs
parent000f57e11cf3272951cd3463f5d8bb82bc8e3903 (diff)
overflow checking
Diffstat (limited to 'src/elf.rs')
-rw-r--r--src/elf.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/elf.rs b/src/elf.rs
index 41ce491..01386f2 100644
--- a/src/elf.rs
+++ b/src/elf.rs
@@ -109,8 +109,8 @@ impl Default for Ehdr32 {
}
impl Ehdr32 {
- pub fn size_of() -> usize {
- mem::size_of::<Self>()
+ pub fn size_of() -> u8 {
+ mem::size_of::<Self>() as u8
}
}
@@ -537,7 +537,8 @@ impl Reader for Reader32LE {
let name = bytes_to_string(bytes)?;
if name == ".strtab" {
- strtab_idx = Some(s_idx as u16);
+ // since shdrs.len() == ehdr.shnum, this should never panic.
+ strtab_idx = Some(s_idx.try_into().unwrap());
}
}