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

fix: remove a potential overflow before conversion #1062

Merged
merged 2 commits into from
Oct 28, 2024
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
24 changes: 14 additions & 10 deletions src/modulefinder/sentry_modulefinder_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,11 @@ get_code_id_from_program_header(const sentry_module_t *module, size_t *size_out)
Elf64_Ehdr elf;
ENSURE(sentry__module_read_safely(&elf, module, 0, sizeof(Elf64_Ehdr)));

for (int i = 0; i < elf.e_phnum; i++) {
for (uint32_t i = 0; i < elf.e_phnum; i++) {
Elf64_Phdr header;
ENSURE(sentry__module_read_safely(&header, module,
elf.e_phoff + elf.e_phentsize * i, sizeof(Elf64_Phdr)));
elf.e_phoff + (uint64_t)elf.e_phentsize * i,
sizeof(Elf64_Phdr)));

// we are only interested in notes
if (header.p_type != PT_NOTE) {
Expand All @@ -326,10 +327,11 @@ get_code_id_from_program_header(const sentry_module_t *module, size_t *size_out)
Elf32_Ehdr elf;
ENSURE(sentry__module_read_safely(&elf, module, 0, sizeof(Elf32_Ehdr)));

for (int i = 0; i < elf.e_phnum; i++) {
for (uint32_t i = 0; i < elf.e_phnum; i++) {
Elf32_Phdr header;
ENSURE(sentry__module_read_safely(&header, module,
elf.e_phoff + elf.e_phentsize * i, sizeof(Elf32_Phdr)));
elf.e_phoff + (uint64_t)elf.e_phentsize * i,
sizeof(Elf32_Phdr)));

// we are only interested in notes
if (header.p_type != PT_NOTE) {
Expand Down Expand Up @@ -360,13 +362,14 @@ get_code_id_from_program_header(const sentry_module_t *module, size_t *size_out)
\
Elf64_Shdr strheader; \
ENSURE(sentry__module_read_safely(&strheader, module, \
elf.e_shoff + elf.e_shentsize * elf.e_shstrndx, \
elf.e_shoff + (uint64_t)elf.e_shentsize * elf.e_shstrndx, \
sizeof(Elf64_Shdr))); \
\
for (int i = 0; i < elf.e_shnum; i++) { \
for (uint32_t i = 0; i < elf.e_shnum; i++) { \
Elf64_Shdr header; \
ENSURE(sentry__module_read_safely(&header, module, \
elf.e_shoff + elf.e_shentsize * i, sizeof(Elf64_Shdr))); \
elf.e_shoff + (uint64_t)elf.e_shentsize * i, \
sizeof(Elf64_Shdr))); \
\
char name[6]; \
ENSURE(sentry__module_read_safely(name, module, \
Expand All @@ -382,13 +385,14 @@ get_code_id_from_program_header(const sentry_module_t *module, size_t *size_out)
\
Elf32_Shdr strheader; \
ENSURE(sentry__module_read_safely(&strheader, module, \
elf.e_shoff + elf.e_shentsize * elf.e_shstrndx, \
elf.e_shoff + (uint64_t)elf.e_shentsize * elf.e_shstrndx, \
sizeof(Elf32_Shdr))); \
\
for (int i = 0; i < elf.e_shnum; i++) { \
for (uint32_t i = 0; i < elf.e_shnum; i++) { \
Elf32_Shdr header; \
ENSURE(sentry__module_read_safely(&header, module, \
elf.e_shoff + elf.e_shentsize * i, sizeof(Elf32_Shdr))); \
elf.e_shoff + (uint64_t)elf.e_shentsize * i, \
sizeof(Elf32_Shdr))); \
\
char name[6]; \
ENSURE(sentry__module_read_safely(name, module, \
Expand Down
Loading