Skip to content

Commit 0c95dfb

Browse files
authored
Fix LightPcapNg null derefs found by oss-fuzz (seladb#1232)
1 parent 6a67cab commit 0c95dfb

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng_ext.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,8 @@ void light_pcapng_close(light_pcapng_t *pcapng)
558558
light_flush(pcapng->file);
559559
light_close(pcapng->file);
560560
}
561-
light_free_file_info(pcapng->file_info);
561+
if (pcapng->file_info != NULL)
562+
light_free_file_info(pcapng->file_info);
562563
free(pcapng);
563564
}
564565

Pcap++/src/PcapFileDevice.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,8 @@ std::string PcapNgFileReaderDevice::getOS() const
439439
}
440440

441441
light_pcapng_file_info* fileInfo = light_pcang_get_file_info((light_pcapng_t*)m_LightPcapNg);
442+
if (fileInfo == nullptr)
443+
return "";
442444
char* res = fileInfo->os_desc;
443445
size_t len = fileInfo->os_desc_size;
444446
if (len == 0 || res == nullptr)
@@ -456,6 +458,8 @@ std::string PcapNgFileReaderDevice::getHardware() const
456458
}
457459

458460
light_pcapng_file_info* fileInfo = light_pcang_get_file_info((light_pcapng_t*)m_LightPcapNg);
461+
if (fileInfo == nullptr)
462+
return "";
459463
char* res = fileInfo->hardware_desc;
460464
size_t len = fileInfo->hardware_desc_size;
461465
if (len == 0 || res == nullptr)
@@ -473,6 +477,8 @@ std::string PcapNgFileReaderDevice::getCaptureApplication() const
473477
}
474478

475479
light_pcapng_file_info* fileInfo = light_pcang_get_file_info((light_pcapng_t*)m_LightPcapNg);
480+
if (fileInfo == nullptr)
481+
return "";
476482
char* res = fileInfo->user_app_desc;
477483
size_t len = fileInfo->user_app_desc_size;
478484
if (len == 0 || res == nullptr)
@@ -490,6 +496,8 @@ std::string PcapNgFileReaderDevice::getCaptureFileComment() const
490496
}
491497

492498
light_pcapng_file_info* fileInfo = light_pcang_get_file_info((light_pcapng_t*)m_LightPcapNg);
499+
if (fileInfo == nullptr)
500+
return "";
493501
char* res = fileInfo->file_comment;
494502
size_t len = fileInfo->file_comment_size;
495503
if (len == 0 || res == nullptr)

0 commit comments

Comments
 (0)