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 Heap-buffer-overflow in __parse_options #1678

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion 3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,24 @@ static struct _light_option *__parse_options(uint32_t **memory, const int32_t ma
opt->custom_option_code = *local_memory++;
opt->option_length = *local_memory++;

// Validate option_length
if (opt->option_length > max_len - 2 * sizeof(*local_memory)) {
free(opt);
return NULL;
}

actual_length = (opt->option_length % alignment) == 0 ?
opt->option_length :
(opt->option_length / alignment + 1) * alignment;

if (actual_length > 0) {
opt->data = calloc(1, actual_length);
memcpy(opt->data, local_memory, 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;
}
Dimi1010 marked this conversation as resolved.
Show resolved Hide resolved
local_memory += (sizeof(**memory) / sizeof(*local_memory)) * (actual_length / alignment);
}

Expand Down
Loading