Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid overflow when header.n_namesz is 0 #256

Merged
merged 1 commit into from Jan 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)))?;
m4b marked this conversation as resolved.
Show resolved Hide resolved
if (header.n_namesz > 0) {
*offset += 1;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup i think this is the right thing to do, the offset is used in subsequent notes, via NoteIterator

}
align(alignment, offset);
debug!("note name {} - {:#x}", name, *offset);
let desc = bytes.gread_with::<&'a [u8]>(offset, header.n_descsz)?;
Expand Down