From 45cbee0c25e3220203ee7e2e1a328f30e58021e3 Mon Sep 17 00:00:00 2001 From: jert4803-droid Date: Mon, 24 Aug 2026 15:06:29 +0000 Subject: [PATCH] WCCP: Fix offset calculation when parsing incoming packets (#2480) Since 2021 commit 464223c1, WCCPv2 packet parsing code was using wrong offsets due to a `CheckFieldDataLength()` bug: * `wccp2_item_header_t` and `wccp2_capability_info_header_t`: The function returned a wrong offset on any 64-bit build, shifting dataStart and the returned field size by 4 bytes and desynchronizing the parse of subsequent WCCPv2 packet items; * `wccp2_capability_element_t`: The function happened to return a correct offset only on platforms with 8-byte pointers. This change is a reference point for automated CONTRIBUTORS updates. --- CONTRIBUTORS | 1 + src/wccp2.cc | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 45986f3f527..2f87d4fd9d6 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -54,6 +54,7 @@ Thank you! Andrew Novikov Andrew Tridgell Andrey + Andrey Kolesnik Andrey Shorin Ankor Anonymous diff --git a/src/wccp2.cc b/src/wccp2.cc index 4a95e7d0eaf..b8ef701bb31 100644 --- a/src/wccp2.cc +++ b/src/wccp2.cc @@ -1142,9 +1142,9 @@ static size_t CheckFieldDataLength(const FieldHeader *header, const size_t dataLength, const void *areaStart, const size_t areaSize, const char *error) { assert(header); - const auto dataStart = reinterpret_cast(header) + sizeof(header); + const auto dataStart = reinterpret_cast(header) + sizeof(*header); CheckSectionLength(dataStart, dataLength, areaStart, areaSize, error); - return sizeof(header) + dataLength; // no overflow after CheckSectionLength() + return sizeof(*header) + dataLength; // no overflow after CheckSectionLength() } /// Positions the given field at a given start within a given packet area.