Skip to content

Commit b1e300b

Browse files
committed
Prevent potential panic when slicing .reginfo
1 parent 0f4904a commit b1e300b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

objdiff-core/src/arch/mips.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ impl ObjArchMips {
6464
// Parse the ri_gp_value stored in .reginfo to be able to correctly
6565
// calculate R_MIPS_GPREL16 relocations later. The value is stored
6666
// 0x14 bytes into .reginfo (on 32 bit platforms)
67-
let ri_gp_value = match object.section_by_name(".reginfo").and_then(|s| s.data().ok()) {
68-
Some(reginfo) => {
69-
let gp_ri_value_bytes = reginfo[0x14..0x18].try_into().unwrap_or([0u8; 4]);
70-
object.endianness().read_i32_bytes(gp_ri_value_bytes)
71-
}
72-
None => 0,
73-
};
67+
let ri_gp_value = object
68+
.section_by_name(".reginfo")
69+
.and_then(|section| section.data().ok())
70+
.and_then(|data| data.get(0x14..0x18))
71+
.and_then(|s| s.try_into().ok())
72+
.map(|bytes| object.endianness().read_i32_bytes(bytes))
73+
.unwrap_or(0);
7474

7575
Ok(Self { endianness: object.endianness(), abi, instr_category, ri_gp_value })
7676
}

0 commit comments

Comments
 (0)