Skip to content

elf.c: Check e_shstrndx against sections' length, not capacity #5136

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

Merged
merged 1 commit into from
May 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions librz/bin/format/elf/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,12 @@
return true;
}

Elf_(Shdr) *section = rz_vector_index_ptr(sections, bin->ehdr.e_shstrndx);
if (!section) {
RZ_LOG_WARN("Invalid ELF header e_shstrndx value.\n");
if (bin->ehdr.e_shstrndx >= rz_vector_len(sections)) {
RZ_LOG_WARN("ELF header e_shstrndx value (%" PFMT32u ") >= number of sections (%" PFMTSZu ").\n",

Check warning on line 200 in librz/bin/format/elf/elf.c

View check run for this annotation

Codecov / codecov/patch

librz/bin/format/elf/elf.c#L200

Added line #L200 was not covered by tests
bin->ehdr.e_shstrndx, rz_vector_len(sections));
return false;
}
Elf_(Shdr) *section = rz_vector_index_ptr(sections, bin->ehdr.e_shstrndx);

bin->shstrtab = Elf_(rz_bin_elf_strtab_new)(bin, section->sh_offset, section->sh_size);
if (!bin->shstrtab) {
Expand Down
Loading