From 765487ee9489470474ec40ae8c31a3e4a34dab6b Mon Sep 17 00:00:00 2001 From: seladb Date: Mon, 17 Jun 2024 01:55:47 -0700 Subject: [PATCH 01/12] Reproduce the issue --- .github/workflows/package.yml | 1 + 3rdParty/LightPcapNg/CMakeLists.txt | 7 ------- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index c97d658999..814fc94051 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -8,6 +8,7 @@ on: paths: # Also run this workflow when this package.yml is update by a PR - '.github/workflows/package.yml' + - '3rdParty/LightPcapNg' schedule: - cron: '0 0 * * 0' # Run every Sunday at midnight diff --git a/3rdParty/LightPcapNg/CMakeLists.txt b/3rdParty/LightPcapNg/CMakeLists.txt index cc79a42b33..2f10732f09 100644 --- a/3rdParty/LightPcapNg/CMakeLists.txt +++ b/3rdParty/LightPcapNg/CMakeLists.txt @@ -24,13 +24,6 @@ add_library( target_compile_definitions(light_pcapng PUBLIC -DUNIVERSAL) -# FIXME: https://github.com/seladb/PcapPlusPlus/issues/1347 -include(CheckCCompilerFlag) -check_c_compiler_flag(-Wincompatible-pointer-types HAVE_W_INCOMPATIBLE_POINTER_TYPES) -if(HAVE_W_INCOMPATIBLE_POINTER_TYPES) - target_compile_options(light_pcapng PRIVATE -Wno-incompatible-pointer-types) -endif() - if(BUILD_SHARED_LIBS) set_property(TARGET light_pcapng PROPERTY POSITION_INDEPENDENT_CODE ON) endif() From 7a47706fc9e55cea0333ff6af66da7aa4277964d Mon Sep 17 00:00:00 2001 From: seladb Date: Tue, 18 Jun 2024 01:37:28 -0700 Subject: [PATCH 02/12] Try to fix the issue --- 3rdParty/LightPcapNg/LightPcapNg/src/light_io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/3rdParty/LightPcapNg/LightPcapNg/src/light_io.c b/3rdParty/LightPcapNg/LightPcapNg/src/light_io.c index 49d177ef7b..a3fc4d87a6 100644 --- a/3rdParty/LightPcapNg/LightPcapNg/src/light_io.c +++ b/3rdParty/LightPcapNg/LightPcapNg/src/light_io.c @@ -88,7 +88,8 @@ int light_pcapng_to_compressed_file(const char *file_name, const light_pcapng pc light_pcapng_stream light_open_stream(const char *file_name) { light_pcapng_stream pcapng = calloc(1, sizeof(struct _light_pcapng_stream)); - pcapng->stream.fd = light_open(file_name, LIGHT_OREAD); + light_file light_f = light_open(file_name, LIGHT_OREAD); + pcapng->stream.fd = light_f->file; if (pcapng->stream.fd == NULL) { free(pcapng); From 8e197753a4efa31a6e2364d7b423161b837f7707 Mon Sep 17 00:00:00 2001 From: seladb Date: Tue, 18 Jun 2024 02:14:07 -0700 Subject: [PATCH 03/12] Try to fix the issue --- .../LightPcapNg/include/light_internal.h | 5 +---- 3rdParty/LightPcapNg/LightPcapNg/src/light_io.c | 13 ++++++------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/3rdParty/LightPcapNg/LightPcapNg/include/light_internal.h b/3rdParty/LightPcapNg/LightPcapNg/include/light_internal.h index ada7bed5a6..0b18d7448d 100644 --- a/3rdParty/LightPcapNg/LightPcapNg/include/light_internal.h +++ b/3rdParty/LightPcapNg/LightPcapNg/include/light_internal.h @@ -33,10 +33,7 @@ #include struct _light_pcapng_stream { - union { - FILE* fd; - void *reserved; - } stream; + struct light_file_t *file; struct _light_pcapng *current_block; int valid; }; diff --git a/3rdParty/LightPcapNg/LightPcapNg/src/light_io.c b/3rdParty/LightPcapNg/LightPcapNg/src/light_io.c index a3fc4d87a6..1647e46232 100644 --- a/3rdParty/LightPcapNg/LightPcapNg/src/light_io.c +++ b/3rdParty/LightPcapNg/LightPcapNg/src/light_io.c @@ -88,10 +88,9 @@ int light_pcapng_to_compressed_file(const char *file_name, const light_pcapng pc light_pcapng_stream light_open_stream(const char *file_name) { light_pcapng_stream pcapng = calloc(1, sizeof(struct _light_pcapng_stream)); - light_file light_f = light_open(file_name, LIGHT_OREAD); - pcapng->stream.fd = light_f->file; + pcapng->file = light_open(file_name, LIGHT_OREAD); - if (pcapng->stream.fd == NULL) { + if (pcapng->file == NULL) { free(pcapng); return NULL; } @@ -115,8 +114,8 @@ light_pcapng light_read_stream(light_pcapng_stream pcapng) pcapng->current_block = NULL; } - if (light_read(pcapng->stream.fd, &block_type, sizeof(block_type)) == -1 || - light_read(pcapng->stream.fd, &block_total_length, sizeof(block_total_length)) == -1) { + if (light_read(pcapng->file, &block_type, sizeof(block_type)) == -1 || + light_read(pcapng->file, &block_total_length, sizeof(block_total_length)) == -1) { pcapng->valid = 0; return NULL; } @@ -130,7 +129,7 @@ light_pcapng light_read_stream(light_pcapng_stream pcapng) block_data[0] = block_type; block_data[1] = block_total_length; - if (light_read(pcapng->stream.fd, &block_data[2], block_total_length - 2 * sizeof(uint32_t)) == -1) { + if (light_read(pcapng->file, &block_data[2], block_total_length - 2 * sizeof(uint32_t)) == -1) { free(block_data); pcapng->valid = 0; return NULL; @@ -153,7 +152,7 @@ int light_close_stream(light_pcapng_stream pcapng) pcapng->current_block = NULL; } - light_close(pcapng->stream.fd); + light_close(pcapng->file); pcapng->valid = 0; free(pcapng); From 0ce92f91e2ef0d4359ebb3bd6464b5052d0cd10b Mon Sep 17 00:00:00 2001 From: seladb Date: Tue, 18 Jun 2024 23:40:36 -0700 Subject: [PATCH 04/12] Try to cancle reserve --- Packet++/src/Asn1Codec.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packet++/src/Asn1Codec.cpp b/Packet++/src/Asn1Codec.cpp index e1c07d61b3..9f441578bd 100644 --- a/Packet++/src/Asn1Codec.cpp +++ b/Packet++/src/Asn1Codec.cpp @@ -621,7 +621,7 @@ namespace pcpp std::vector Asn1IntegerRecord::encodeValue() const { std::vector result; - result.reserve(m_ValueLength); +// result.reserve(m_ValueLength); switch (m_ValueLength) { From 48662082854077f0a3a94427b6536da539a63a6c Mon Sep 17 00:00:00 2001 From: seladb Date: Wed, 19 Jun 2024 00:13:42 -0700 Subject: [PATCH 05/12] Remove reserve --- Packet++/src/Asn1Codec.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Packet++/src/Asn1Codec.cpp b/Packet++/src/Asn1Codec.cpp index 9f441578bd..bef0b1810e 100644 --- a/Packet++/src/Asn1Codec.cpp +++ b/Packet++/src/Asn1Codec.cpp @@ -621,7 +621,6 @@ namespace pcpp std::vector Asn1IntegerRecord::encodeValue() const { std::vector result; -// result.reserve(m_ValueLength); switch (m_ValueLength) { From e85052fe897b20ebf3ccf40103cbe1034717ab10 Mon Sep 17 00:00:00 2001 From: seladb Date: Wed, 19 Jun 2024 00:42:21 -0700 Subject: [PATCH 06/12] Revert the changes in `package.yml` --- .github/workflows/package.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index 814fc94051..c97d658999 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -8,7 +8,6 @@ on: paths: # Also run this workflow when this package.yml is update by a PR - '.github/workflows/package.yml' - - '3rdParty/LightPcapNg' schedule: - cron: '0 0 * * 0' # Run every Sunday at midnight From 7cc748920a07def4d2506a1bce0c022deac2079b Mon Sep 17 00:00:00 2001 From: seladb Date: Wed, 19 Jun 2024 23:47:36 -0700 Subject: [PATCH 07/12] Detect MinGW using a macro --- .github/workflows/package.yml | 1 + Packet++/src/Asn1Codec.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index c97d658999..8d3b3ad69f 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -8,6 +8,7 @@ on: paths: # Also run this workflow when this package.yml is update by a PR - '.github/workflows/package.yml' + - 'Packet++/src/Asn1Codec.cpp' schedule: - cron: '0 0 * * 0' # Run every Sunday at midnight diff --git a/Packet++/src/Asn1Codec.cpp b/Packet++/src/Asn1Codec.cpp index bef0b1810e..e87c222dc7 100644 --- a/Packet++/src/Asn1Codec.cpp +++ b/Packet++/src/Asn1Codec.cpp @@ -622,6 +622,10 @@ namespace pcpp { std::vector result; + #if !(defined(__MIGW32__) || defined(__MIGW64__)) + result.reserve(m_ValueLength); + #endif + switch (m_ValueLength) { case 1: From c4bab92c3d30290776bc3cba99e51699242231ea Mon Sep 17 00:00:00 2001 From: seladb Date: Wed, 19 Jun 2024 23:59:16 -0700 Subject: [PATCH 08/12] Try again --- .github/workflows/package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index 8d3b3ad69f..98ecad220e 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -8,7 +8,7 @@ on: paths: # Also run this workflow when this package.yml is update by a PR - '.github/workflows/package.yml' - - 'Packet++/src/Asn1Codec.cpp' + - 'Packet++/src' schedule: - cron: '0 0 * * 0' # Run every Sunday at midnight From 3bc00b500433ef97a8afea51a11e0b8840619d68 Mon Sep 17 00:00:00 2001 From: seladb Date: Thu, 20 Jun 2024 00:00:29 -0700 Subject: [PATCH 09/12] Try again --- .github/workflows/package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index 98ecad220e..814fc94051 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -8,7 +8,7 @@ on: paths: # Also run this workflow when this package.yml is update by a PR - '.github/workflows/package.yml' - - 'Packet++/src' + - '3rdParty/LightPcapNg' schedule: - cron: '0 0 * * 0' # Run every Sunday at midnight From d911d1bd7675d4d919a396b8eca73b881787cf48 Mon Sep 17 00:00:00 2001 From: seladb Date: Thu, 20 Jun 2024 00:18:59 -0700 Subject: [PATCH 10/12] Try with `__MINGW64_VERSION_MAJOR` and `__MINGW32_MAJOR_VERSION` --- Packet++/src/Asn1Codec.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packet++/src/Asn1Codec.cpp b/Packet++/src/Asn1Codec.cpp index e87c222dc7..555b829861 100644 --- a/Packet++/src/Asn1Codec.cpp +++ b/Packet++/src/Asn1Codec.cpp @@ -622,7 +622,7 @@ namespace pcpp { std::vector result; - #if !(defined(__MIGW32__) || defined(__MIGW64__)) + #if !(defined(__MINGW64_VERSION_MAJOR) || defined(__MINGW32_MAJOR_VERSION)) result.reserve(m_ValueLength); #endif From 1e5f6a491585588eb7ce32a874a85f69e7377691 Mon Sep 17 00:00:00 2001 From: seladb Date: Thu, 20 Jun 2024 00:51:16 -0700 Subject: [PATCH 11/12] Revert changes in `package.yml` --- .github/workflows/package.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index 814fc94051..c97d658999 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -8,7 +8,6 @@ on: paths: # Also run this workflow when this package.yml is update by a PR - '.github/workflows/package.yml' - - '3rdParty/LightPcapNg' schedule: - cron: '0 0 * * 0' # Run every Sunday at midnight From dbfee2a4f86fd443366e4773e86ebff719c82a26 Mon Sep 17 00:00:00 2001 From: seladb Date: Thu, 20 Jun 2024 23:40:35 -0700 Subject: [PATCH 12/12] Add `// PCPP patch` in all changes made in LightPcapNg --- 3rdParty/LightPcapNg/LightPcapNg/include/light_internal.h | 2 +- 3rdParty/LightPcapNg/LightPcapNg/src/light_io.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/3rdParty/LightPcapNg/LightPcapNg/include/light_internal.h b/3rdParty/LightPcapNg/LightPcapNg/include/light_internal.h index 0b18d7448d..6ccd434eed 100644 --- a/3rdParty/LightPcapNg/LightPcapNg/include/light_internal.h +++ b/3rdParty/LightPcapNg/LightPcapNg/include/light_internal.h @@ -33,7 +33,7 @@ #include struct _light_pcapng_stream { - struct light_file_t *file; + struct light_file_t *file; // PCPP patch struct _light_pcapng *current_block; int valid; }; diff --git a/3rdParty/LightPcapNg/LightPcapNg/src/light_io.c b/3rdParty/LightPcapNg/LightPcapNg/src/light_io.c index 1647e46232..fef527785a 100644 --- a/3rdParty/LightPcapNg/LightPcapNg/src/light_io.c +++ b/3rdParty/LightPcapNg/LightPcapNg/src/light_io.c @@ -88,9 +88,9 @@ int light_pcapng_to_compressed_file(const char *file_name, const light_pcapng pc light_pcapng_stream light_open_stream(const char *file_name) { light_pcapng_stream pcapng = calloc(1, sizeof(struct _light_pcapng_stream)); - pcapng->file = light_open(file_name, LIGHT_OREAD); + pcapng->file = light_open(file_name, LIGHT_OREAD); // PCPP patch - if (pcapng->file == NULL) { + if (pcapng->file == NULL) { // PCPP patch free(pcapng); return NULL; } @@ -114,6 +114,7 @@ light_pcapng light_read_stream(light_pcapng_stream pcapng) pcapng->current_block = NULL; } + // PCPP patch if (light_read(pcapng->file, &block_type, sizeof(block_type)) == -1 || light_read(pcapng->file, &block_total_length, sizeof(block_total_length)) == -1) { pcapng->valid = 0; @@ -129,6 +130,7 @@ light_pcapng light_read_stream(light_pcapng_stream pcapng) block_data[0] = block_type; block_data[1] = block_total_length; + // PCPP patch if (light_read(pcapng->file, &block_data[2], block_total_length - 2 * sizeof(uint32_t)) == -1) { free(block_data); pcapng->valid = 0; @@ -152,7 +154,7 @@ int light_close_stream(light_pcapng_stream pcapng) pcapng->current_block = NULL; } - light_close(pcapng->file); + light_close(pcapng->file); // PCPP patch pcapng->valid = 0; free(pcapng);