From 301e792ea77b2071e24c4df51b73cc094c44e905 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 8 May 2026 12:36:20 +0000 Subject: [PATCH 1/2] Fix use-of-uninitialized-value in PcapNgFileReaderDevice::getNextPacketInternal - Zero-initialize light_packet_header pktHeader in getNextPacketInternal to prevent MSAN use-of-uninitialized-value on any path where light_get_next_packet does not fill every field. - Fix light_get_next_packet's LIGHT_SIMPLE_PACKET_BLOCK branch: add an else clause so packet_header->data_link is always set (to 0xFFFF) when there are no interface blocks, eliminating the root cause of the uninitialized read. Agent-Logs-Url: https://github.com/Shivam7-1/PcapPlusPlus/sessions/40af4014-b148-45f0-8e4f-9f159064c5d1 Co-authored-by: Shivam7-1 <55046031+Shivam7-1@users.noreply.github.com> --- 3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng_ext.c | 2 ++ Pcap++/src/PcapFileDevice.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng_ext.c b/3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng_ext.c index f31b6ced2a..384344dc6d 100644 --- a/3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng_ext.c +++ b/3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng_ext.c @@ -461,6 +461,8 @@ int light_get_next_packet(light_pcapng_t *pcapng, light_packet_header *packet_he packet_header->timestamp.tv_nsec = 0; if (pcapng->file_info->interface_block_count > 0) packet_header->data_link = pcapng->file_info->link_types[0]; + else + packet_header->data_link = 0xFFFF; *packet_data = (uint8_t*)spb->packet_data; } diff --git a/Pcap++/src/PcapFileDevice.cpp b/Pcap++/src/PcapFileDevice.cpp index 6d4ab40878..e8cc810672 100644 --- a/Pcap++/src/PcapFileDevice.cpp +++ b/Pcap++/src/PcapFileDevice.cpp @@ -874,7 +874,7 @@ namespace pcpp return false; } - light_packet_header pktHeader; + light_packet_header pktHeader{}; const uint8_t* pktData = nullptr; if (!light_get_next_packet(toLightPcapNgT(m_LightPcapNg), &pktHeader, &pktData)) From ee300a892fdd7f678c9145ce779510f8122f766e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 8 May 2026 12:39:46 +0000 Subject: [PATCH 2/2] Add comment explaining 0xFFFF sentinel value for data_link Agent-Logs-Url: https://github.com/Shivam7-1/PcapPlusPlus/sessions/40af4014-b148-45f0-8e4f-9f159064c5d1 Co-authored-by: Shivam7-1 <55046031+Shivam7-1@users.noreply.github.com> --- 3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng_ext.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng_ext.c b/3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng_ext.c index 384344dc6d..427cdf000f 100644 --- a/3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng_ext.c +++ b/3rdParty/LightPcapNg/LightPcapNg/src/light_pcapng_ext.c @@ -462,7 +462,7 @@ int light_get_next_packet(light_pcapng_t *pcapng, light_packet_header *packet_he if (pcapng->file_info->interface_block_count > 0) packet_header->data_link = pcapng->file_info->link_types[0]; else - packet_header->data_link = 0xFFFF; + packet_header->data_link = 0xFFFF; /* unknown/invalid link type sentinel (no interface block present) */ *packet_data = (uint8_t*)spb->packet_data; }