Skip to content

Commit

Permalink
avoid integer underflow when calling memset with 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 committed Jun 14, 2023
1 parent a7a0a67 commit ca4a665
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/nix-ld.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ static int elf_map(struct ld_ctx *ctx, int fd, const Phdr *prog_headers,
size_t brk = ctx->load_addr + ph->p_vaddr + ph->p_filesz;
size_t pgbrk = page_align(ctx, brk);
size_t this_max = page_align(ctx, ph->p_vaddr + ph->p_memsz);
memset((void *)brk, 0, page_offset(ctx, pgbrk - brk));
if (page_offset(ctx, pgbrk - brk)) {
memset((void *)brk, 0, page_offset(ctx, pgbrk - brk));
}

if (pgbrk - ctx->load_addr < this_max) {
void *res = mmap((void *)pgbrk, ctx->load_addr + this_max - pgbrk, prot,
Expand Down

0 comments on commit ca4a665

Please sign in to comment.