mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 04:21:51 +00:00
An error array was read at index 0 without checking its size, so a packet carrying "e":[] dereferenced a null element pointer and crashed the process on unauthenticated UDP input. When a message had an error array but no "a", "r" or "u" map, the same object was then walked through the map view of the msgpack union. A two-element array appeared to hold two key/value pairs, reading past its allocation. A request field that was not a map was never type-checked either. Validate the error array size, restrict request parsing to "a", "r" and "u", and require those to be maps. Add parser regressions for the empty error array, the error-only message and the non-map request; the first one segfaults without this change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
77 lines
2.8 KiB
C++
77 lines
2.8 KiB
C++
// Copyright (c) 2014-2026 Savoir-faire Linux Inc.
|
|
// SPDX-License-Identifier: MIT
|
|
#pragma once
|
|
|
|
// cppunit
|
|
#include <cppunit/TestFixture.h>
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
namespace test {
|
|
|
|
class ParsedMessageTester : public CppUnit::TestFixture
|
|
{
|
|
CPPUNIT_TEST_SUITE(ParsedMessageTester);
|
|
CPPUNIT_TEST(testAppendInOrder);
|
|
CPPUNIT_TEST(testAppendOutOfOrder);
|
|
CPPUNIT_TEST(testAppendReverseOrder);
|
|
CPPUNIT_TEST(testAppendDuplicateFragment);
|
|
CPPUNIT_TEST(testAppendOverlappingFragments);
|
|
CPPUNIT_TEST(testAppendFragmentBeyondTotal);
|
|
CPPUNIT_TEST(testAppendEmptyFragment);
|
|
CPPUNIT_TEST(testAppendUnknownIndex);
|
|
CPPUNIT_TEST(testAppendAlreadyComplete);
|
|
CPPUNIT_TEST(testAppendOverflowingOffset);
|
|
CPPUNIT_TEST(testParseRejectsNonMapPacket);
|
|
CPPUNIT_TEST(testParseRejectsInvalidValueDataPayload);
|
|
CPPUNIT_TEST(testParseRejectsInvalidValuesField);
|
|
CPPUNIT_TEST(testParseRejectsEmptyFieldSelection);
|
|
CPPUNIT_TEST(testParseRejectsEmptyErrorArray);
|
|
CPPUNIT_TEST(testParseRejectsNonMapRequest);
|
|
CPPUNIT_TEST(testParseErrorOnlyMessageKeepsRequestFieldsEmpty);
|
|
CPPUNIT_TEST(testParseIgnoresIncompleteValueDataEntry);
|
|
CPPUNIT_TEST(testCompleteEmpty);
|
|
CPPUNIT_TEST(testCompleteIncomplete);
|
|
CPPUNIT_TEST(testCompleteZeroSizedValue);
|
|
CPPUNIT_TEST(testCompleteSingleValue);
|
|
CPPUNIT_TEST(testCompleteMultipleValues);
|
|
CPPUNIT_TEST(testCompleteReassemblyOrder);
|
|
CPPUNIT_TEST(testAppendMultipleValuesOutOfOrder);
|
|
CPPUNIT_TEST(testReceiveLargeFragmentedValue);
|
|
CPPUNIT_TEST(testReceiveLargeFragmentedValueOutOfOrder);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
public:
|
|
void setUp();
|
|
void tearDown();
|
|
|
|
void testAppendInOrder();
|
|
void testAppendOutOfOrder();
|
|
void testAppendReverseOrder();
|
|
void testAppendDuplicateFragment();
|
|
void testAppendOverlappingFragments();
|
|
void testAppendFragmentBeyondTotal();
|
|
void testAppendEmptyFragment();
|
|
void testAppendUnknownIndex();
|
|
void testAppendAlreadyComplete();
|
|
void testAppendOverflowingOffset();
|
|
void testParseRejectsNonMapPacket();
|
|
void testParseRejectsInvalidValueDataPayload();
|
|
void testParseRejectsInvalidValuesField();
|
|
void testParseRejectsEmptyFieldSelection();
|
|
void testParseRejectsEmptyErrorArray();
|
|
void testParseRejectsNonMapRequest();
|
|
void testParseErrorOnlyMessageKeepsRequestFieldsEmpty();
|
|
void testParseIgnoresIncompleteValueDataEntry();
|
|
void testCompleteEmpty();
|
|
void testCompleteIncomplete();
|
|
void testCompleteZeroSizedValue();
|
|
void testCompleteSingleValue();
|
|
void testCompleteMultipleValues();
|
|
void testCompleteReassemblyOrder();
|
|
void testAppendMultipleValuesOutOfOrder();
|
|
void testReceiveLargeFragmentedValue();
|
|
void testReceiveLargeFragmentedValueOutOfOrder();
|
|
};
|
|
|
|
} // namespace test
|