Skip to content

Commit

Permalink
Move the heap overflow check before the allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
aled-ua authored Jan 4, 2025
1 parent 8d546b1 commit e347d4d
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions 3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,9 @@ static struct _light_option *__parse_options(uint32_t **memory, const int32_t ma
opt->option_length :
(opt->option_length / alignment + 1) * alignment;

if (actual_length > 0) {
if (actual_length > 0 && actual_length <= max_len - 2 * sizeof(*local_memory)) {
opt->data = calloc(1, actual_length);
if (actual_length <= max_len - 2 * sizeof(*local_memory)) {
memcpy(opt->data, local_memory, actual_length);
} else {
free(opt->data);
opt->data = NULL;
}
memcpy(opt->data, local_memory, actual_length);
local_memory += (sizeof(**memory) / sizeof(*local_memory)) * (actual_length / alignment);
}

Expand Down

0 comments on commit e347d4d

Please sign in to comment.