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 4 commits into
base: dev
Choose a base branch
from
Open
Changes from 2 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
8 changes: 7 additions & 1 deletion 3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ 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) {
if (actual_length > 0 && actual_length <= max_len - 2 * sizeof(*local_memory)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is enough to terminate the parsing operation.

If the actual length is out of bounds, the recursion continues.
Also remaining_size on L69 will underflow from the subtraction.

Copy link
Contributor Author

@aled-ua aled-ua Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is enough to terminate the parsing operation.

If the actual length is out of bounds, the recursion continues. Also remaining_size on L69 will underflow from the subtraction.

Should we terminate immediately when overflow is found? patch similar to L52.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think terminating immediately is better...

Also @aled-ua please use the // PCPP patch comment when making changes in LightPcapNg (you can find it in various places in LightPcapNg code), since it's a 3rd-party library and we'd like to contribute it back at some point

opt->data = calloc(1, actual_length);
memcpy(opt->data, local_memory, actual_length);
local_memory += (sizeof(**memory) / sizeof(*local_memory)) * (actual_length / alignment);
Expand Down
Loading