Skip to content

Commit ae88e11

Browse files
committed
Fix vuln OSV-2024-352
1 parent 0c95dfb commit ae88e11

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,24 @@ static struct _light_option *__parse_options(uint32_t **memory, const int32_t ma
4646
uint16_t *local_memory = (uint16_t*)*memory;
4747
uint16_t remaining_size;
4848

49+
// Read custom option code and length from local_memory
50+
if (remaining_size < 2 * sizeof(uint16_t)) {
51+
return NULL; // Not enough data for option code and length
52+
}
4953
opt->custom_option_code = *local_memory++;
5054
opt->option_length = *local_memory++;
5155

56+
// Check if the option length is valid
57+
if (opt->option_length > remaining_size - sizeof(opt->custom_option_code)) {
58+
return NULL; // Invalid length, buffer too small
59+
}
5260
actual_length = (opt->option_length % alignment) == 0 ?
5361
opt->option_length :
5462
(opt->option_length / alignment + 1) * alignment;
5563

56-
if (actual_length > 0) {
64+
if (actual_length > 0 && remaining_size >= actual_length) {
5765
opt->data = calloc(1, actual_length);
58-
memcpy(opt->data, local_memory, actual_length);
66+
memcpy(opt->data, local_memory, actual_length); // Safe copy now
5967
local_memory += (sizeof(**memory) / sizeof(*local_memory)) * (actual_length / alignment);
6068
}
6169

0 commit comments

Comments
 (0)