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 9163d15
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/elf/note.rs
Expand Up @@ -205,7 +205,7 @@ 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))?;
let name = bytes.gread_with::<&'a str>(offset, ctx::StrCtx::Length(header.n_namesz.saturating_sub(1)))?;
*offset += 1;
align(alignment, offset);
debug!("note name {} - {:#x}", name, *offset);
Expand Down

0 comments on commit 9163d15

Please sign in to comment.