dyld: more fine grained errors

This commit is contained in:
Sebastien Bourdeauducq 2020-04-18 18:04:46 +08:00
parent e1190ec76c
commit c0aa4f78c2
1 changed files with 5 additions and 3 deletions

View File

@ -233,9 +233,11 @@ impl<'a> Library<'a> {
match phdr.p_type {
PT_LOAD => {
if (phdr.p_vaddr + phdr.p_filesz) as usize > image.len() ||
(phdr.p_offset + phdr.p_filesz) as usize > data.len() {
return Err("program header requests an out of bounds load")?
if (phdr.p_vaddr + phdr.p_filesz) as usize > image.len() {
return Err("program header requests an out of bounds load (in image)")?
}
if (phdr.p_offset + phdr.p_filesz) as usize > data.len() {
return Err("program header requests an out of bounds load (in data)")?
}
let dst = image.get_mut(phdr.p_vaddr as usize..
(phdr.p_vaddr + phdr.p_filesz) as usize)