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

util_lib: add multiplication overflow check in elf_info #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 13 additions & 2 deletions util_lib/elf_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,13 @@ static void dump_dmesg_lockless(int fd, void (*handler)(char*, unsigned int))
m.desc_ring_count = 1 << struct_val_u32(m.desc_ring,
prb_desc_ring_count_bits_offset);
kaddr = get_ulong(m.desc_ring + prb_desc_ring_descs_offset);
m.descs = calloc(1, prb_desc_sz * m.desc_ring_count);
size_t size;
if (__builtin_mul_overflow(m.desc_ring_count, prb_desc_sz, &size)) {
fprintf(stderr, "Failed to calculate size of descs: %s\n",
strerror(errno));
exit(66);
}
m.descs = calloc(1, size);
if (!m.descs) {
fprintf(stderr, "Failed to malloc %lu bytes for descs: %s\n",
prb_desc_sz * m.desc_ring_count, strerror(errno));
Expand All @@ -1154,7 +1160,12 @@ static void dump_dmesg_lockless(int fd, void (*handler)(char*, unsigned int))

/* setup info ring */
kaddr = get_ulong(m.prb + prb_desc_ring_infos_offset);
m.infos = calloc(1, printk_info_sz * m.desc_ring_count);
if (__builtin_mul_overflow(m.desc_ring_count, printk_info_sz, &size)) {
fprintf(stderr, "Failed to calculate size of descs: %s\n",
strerror(errno));
exit(66);
}
m.infos = calloc(1, size);
if (!m.infos) {
fprintf(stderr, "Failed to malloc %lu bytes for infos: %s\n",
printk_info_sz * m.desc_ring_count, strerror(errno));
Expand Down