Skip to content

Commit

Permalink
Avoid overflow when header.n_namesz is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Jan 29, 2021
1 parent 8d91dd7 commit 6f54fca
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/elf/note.rs
Expand Up @@ -205,8 +205,10 @@ if_alloc! {
};
debug!("{:?} - {:#x}", header, *offset);
// -1 because includes \0 terminator
let name = bytes.gread_with::<&'a str>(offset, ctx::StrCtx::Length(header.n_namesz - 1))?;
*offset += 1;
let name = bytes.gread_with::<&'a str>(offset, ctx::StrCtx::Length(header.n_namesz.saturating_sub(1)))?;
if (header.n_namesz > 0) {
*offset += 1;
}
align(alignment, offset);
debug!("note name {} - {:#x}", name, *offset);
let desc = bytes.gread_with::<&'a [u8]>(offset, header.n_descsz)?;
Expand Down

0 comments on commit 6f54fca

Please sign in to comment.