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

fixes a use-of-uninitialized-value in light_pcapng.c #1669

Merged
merged 9 commits into from
Jan 3, 2025
28 changes: 18 additions & 10 deletions 3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng.c
Shivam7-1 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ void parse_by_block_type(struct _light_pcapng *current, const uint32_t *local_da
switch (current->block_type)
{
case LIGHT_SECTION_HEADER_BLOCK:
{
{ // PCPP patch
DPRINT_HERE(LIGHT_SECTION_HEADER_BLOCK);
struct _light_section_header *shb = calloc(1, sizeof(struct _light_section_header));
struct _light_option *opt = NULL;
uint32_t version;
int32_t local_offset;
struct _light_option *opt = calloc(1, sizeof(struct _light_option));
uint32_t version = 0;
int32_t local_offset = 0;

shb->byteorder_magic = *local_data++;
// TODO check byte order.
Expand All @@ -107,34 +107,38 @@ void parse_by_block_type(struct _light_pcapng *current, const uint32_t *local_da

current->block_body = (uint32_t*)shb;
local_offset = (size_t)local_data - (size_t)block_start;
if (opt != NULL)
free(opt); // Free memory before reassignment
opt = __parse_options((uint32_t **)&local_data, current->block_total_length - local_offset - sizeof(current->block_total_length));
current->options = opt;
}
break;

case LIGHT_INTERFACE_BLOCK:
{
{ // PCPP patch
DPRINT_HERE(LIGHT_INTERFACE_BLOCK);
struct _light_interface_description_block *idb = calloc(1, sizeof(struct _light_interface_description_block));
struct _light_option *opt = NULL;
struct _light_option *opt = calloc(1, sizeof(struct _light_option));
uint32_t link_reserved = *local_data++;
int32_t local_offset;
int32_t local_offset = 0;

idb->link_type = link_reserved & 0xFFFF;
idb->reserved = (link_reserved >> 16) & 0xFFFF;
idb->snapshot_length = *local_data++;
current->block_body = (uint32_t*)idb;
local_offset = (size_t)local_data - (size_t)block_start;
if (opt != NULL)
free(opt); // Free memory before reassignment
opt = __parse_options((uint32_t **)&local_data, current->block_total_length - local_offset - sizeof(current->block_total_length));
current->options = opt;
}
break;

case LIGHT_ENHANCED_PACKET_BLOCK:
{
{ //PCPP Patch
DPRINT_HERE(LIGHT_ENHANCED_PACKET_BLOCK);
struct _light_enhanced_packet_block *epb = NULL;
struct _light_option *opt = NULL;
struct _light_option *opt = calloc(1, sizeof(struct _light_option));
Shivam7-1 marked this conversation as resolved.
Show resolved Hide resolved
uint32_t interface_id = *local_data++;
uint32_t timestamp_high = *local_data++;
uint32_t timestamp_low = *local_data++;
Expand All @@ -156,6 +160,8 @@ void parse_by_block_type(struct _light_pcapng *current, const uint32_t *local_da
local_data += actual_len / sizeof(uint32_t);
current->block_body = (uint32_t*)epb;
local_offset = (size_t)local_data - (size_t)block_start;
if (opt != NULL)
free(opt); // Free memory before reassignment
opt = __parse_options((uint32_t **)&local_data, current->block_total_length - local_offset - sizeof(current->block_total_length));
current->options = opt;
}
Expand All @@ -182,7 +188,7 @@ void parse_by_block_type(struct _light_pcapng *current, const uint32_t *local_da
{
DPRINT_HERE(LIGHT_CUSTOM_DATA_BLOCK);
struct _light_custom_nonstandard_block *cnb = NULL;
struct _light_option *opt = NULL;
struct _light_option *opt = calloc(1, sizeof(struct _light_option));
Shivam7-1 marked this conversation as resolved.
Show resolved Hide resolved
uint32_t len = *local_data++;
uint32_t reserved0 = *local_data++;
uint32_t reserved1 = *local_data++;
Expand All @@ -199,6 +205,8 @@ void parse_by_block_type(struct _light_pcapng *current, const uint32_t *local_da
local_data += actual_len / sizeof(uint32_t);
current->block_body = (uint32_t*)cnb;
local_offset = (size_t)local_data - (size_t)block_start;
if (opt != NULL)
free(opt); // Free memory before reassignment
opt = __parse_options((uint32_t **)&local_data, current->block_total_length - local_offset - sizeof(current->block_total_length));
current->options = opt;
}
Expand Down
Loading