Waterbox: Fix various problems with 0 length sections and segments (#3586)

* waterbox: fix crash when init_array is size 0

* also handle 0 len segments
This commit is contained in:
nattthebear 2023-03-18 19:50:32 -04:00 committed by GitHub
parent 291a14315d
commit eb5ebda53f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 5 deletions

Binary file not shown.

Binary file not shown.

View File

@ -145,11 +145,13 @@ impl ElfLoader {
if segment.is_executable() { "X" } else { " " }, if segment.is_executable() { "X" } else { " " },
addr.size addr.size
); );
if prot_addr.size != 0 {
// TODO: Using no_replace false here because the linker puts eh_frame_hdr in a separate segment that overlaps the other RO segment??? // TODO: Using no_replace false here because the linker puts eh_frame_hdr in a separate segment that overlaps the other RO segment???
b.mmap_fixed(prot_addr, Protection::RW, false)?; b.mmap_fixed(prot_addr, Protection::RW, false)?;
b.copy_from_external(&data[segment.file_range()], addr.start)?; b.copy_from_external(&data[segment.file_range()], addr.start)?;
b.mprotect(prot_addr, prot)?; b.mprotect(prot_addr, prot)?;
} }
}
match info_area_opt { match info_area_opt {
Some(i) => { Some(i) => {
@ -184,7 +186,7 @@ impl ElfLoader {
} }
pub fn seal(&mut self, b: &mut MemoryBlock) { pub fn seal(&mut self, b: &mut MemoryBlock) {
for section in self.sections.iter() { for section in self.sections.iter() {
if section_name_is_readonly(section.name.as_str()) { if section.addr.align_expand().size != 0 && section_name_is_readonly(section.name.as_str()) {
b.mprotect(section.addr.align_expand(), Protection::R).unwrap(); b.mprotect(section.addr.align_expand(), Protection::R).unwrap();
} }
} }