Skip to content

Commit 7898a5d

Browse files
authored
fixes a use-of-uninitialized-value in light_pcapng.c (#1669)
1 parent 4a38f9a commit 7898a5d

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ void parse_by_block_type(struct _light_pcapng *current, const uint32_t *local_da
9090
switch (current->block_type)
9191
{
9292
case LIGHT_SECTION_HEADER_BLOCK:
93-
{
93+
{ // PCPP patch
9494
DPRINT_HERE(LIGHT_SECTION_HEADER_BLOCK);
9595
struct _light_section_header *shb = calloc(1, sizeof(struct _light_section_header));
9696
struct _light_option *opt = NULL;
97-
uint32_t version;
98-
int32_t local_offset;
97+
uint32_t version = 0;
98+
int32_t local_offset = 0;
9999

100100
shb->byteorder_magic = *local_data++;
101101
// TODO check byte order.
@@ -108,30 +108,34 @@ void parse_by_block_type(struct _light_pcapng *current, const uint32_t *local_da
108108
current->block_body = (uint32_t*)shb;
109109
local_offset = (size_t)local_data - (size_t)block_start;
110110
opt = __parse_options((uint32_t **)&local_data, current->block_total_length - local_offset - sizeof(current->block_total_length));
111+
if (opt == NULL)
112+
opt = calloc(1, sizeof(struct _light_option));
111113
current->options = opt;
112114
}
113115
break;
114116

115117
case LIGHT_INTERFACE_BLOCK:
116-
{
118+
{ // PCPP patch
117119
DPRINT_HERE(LIGHT_INTERFACE_BLOCK);
118120
struct _light_interface_description_block *idb = calloc(1, sizeof(struct _light_interface_description_block));
119121
struct _light_option *opt = NULL;
120122
uint32_t link_reserved = *local_data++;
121-
int32_t local_offset;
123+
int32_t local_offset = 0;
122124

123125
idb->link_type = link_reserved & 0xFFFF;
124126
idb->reserved = (link_reserved >> 16) & 0xFFFF;
125127
idb->snapshot_length = *local_data++;
126128
current->block_body = (uint32_t*)idb;
127129
local_offset = (size_t)local_data - (size_t)block_start;
128130
opt = __parse_options((uint32_t **)&local_data, current->block_total_length - local_offset - sizeof(current->block_total_length));
131+
if (opt == NULL)
132+
opt = calloc(1, sizeof(struct _light_option));
129133
current->options = opt;
130134
}
131135
break;
132136

133137
case LIGHT_ENHANCED_PACKET_BLOCK:
134-
{
138+
{ // PCPP Patch
135139
DPRINT_HERE(LIGHT_ENHANCED_PACKET_BLOCK);
136140
struct _light_enhanced_packet_block *epb = NULL;
137141
struct _light_option *opt = NULL;
@@ -157,6 +161,8 @@ void parse_by_block_type(struct _light_pcapng *current, const uint32_t *local_da
157161
current->block_body = (uint32_t*)epb;
158162
local_offset = (size_t)local_data - (size_t)block_start;
159163
opt = __parse_options((uint32_t **)&local_data, current->block_total_length - local_offset - sizeof(current->block_total_length));
164+
if (opt == NULL)
165+
opt = calloc(1, sizeof(struct _light_option));
160166
current->options = opt;
161167
}
162168
break;
@@ -200,6 +206,8 @@ void parse_by_block_type(struct _light_pcapng *current, const uint32_t *local_da
200206
current->block_body = (uint32_t*)cnb;
201207
local_offset = (size_t)local_data - (size_t)block_start;
202208
opt = __parse_options((uint32_t **)&local_data, current->block_total_length - local_offset - sizeof(current->block_total_length));
209+
if (opt == NULL)
210+
opt = calloc(1, sizeof(struct _light_option));
203211
current->options = opt;
204212
}
205213
break;

0 commit comments

Comments
 (0)