From f5cbeb5238190dc2438098cdc5ef11f122dd359c Mon Sep 17 00:00:00 2001 From: Andreas Nordal <4992374+anordal@users.noreply.github.com> Date: Fri, 14 Jun 2024 12:41:40 +0200 Subject: [PATCH 01/15] Let's fix the tests enough to run with AddressSanitizer and UB Sanitizer and enable those in CI (#1151) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * unit-test CMake: Add option to build with sanitizers These build options affect both the tests and the code under test when built from the unit-test CMake file. Example: cmake -DSANITIZE=address,undefined To reset all options: cmake --fresh Meson users will find this familiar: meson -Db_sanitize=… (When in doubt in CMake, implement what Meson provides out of the box.) Motivation: ASan and UBSan currently finds a lot of crashy problems with the unit-tests, and makes them visible in plain sight. * unit-test CMake: Remove compile_options(-O0 -Wno-div-by-zero) Let's not override optimization options: This is surprising when the cmake user tries to set CMAKE_BUILD_TYPE=(Debug|Release)'. The -Wno-div-by-zero warning disabling seems obsolete: Replacing it with -Werror did not fail, at least with Gcc 13. * unit-test: Fix missing symbol in a few tests (linker error) I don't know why I get to resolve these, but in all cases, it is FreeRTOS_Sockets.c that is dragging in a dependency on xTCPWindowLoggingLevel, causing a few tests to fail to link: FreeRTOS_Sockets.c:5118:(.text+0x18fa2): undefined reference to `xTCPWindowLoggingLevel' Since it's one external variable, let's add it to the necessary unittests. Also under the headline of extern variables: The IPv6 address, which was not there for linkage, could be made const. * unit-test: Fix segfault due to discrepancy between the real and mocked recvfrom Symptom: test_vDHCPProcess_eWaitingOffer_CorrectState_ValidBytesInMessage_MatchingEndPoint() segfaults. What AddressSanitizer says about that: test/unit-test/build/Annexed_TCP_Sources/FreeRTOS_DHCP.c:1139:28: runtime error: member access within null pointer of type 'const struct DHCPMessage_IPv4_t' AddressSanitizer:DEADLYSIGNAL ================================================================= ==14403==ERROR: AddressSanitizer: SEGV on unknown address 0x0000000000ec ==14403==The signal is caused by a READ memory access. ==14403==Hint: address points to the zero page. #0 0x456eb7 in prvIsValidDHCPResponse test/unit-test/build/Annexed_TCP_Sources/FreeRTOS_DHCP.c:1139 #1 0x4584c3 in prvProcessDHCPReplies test/unit-test/build/Annexed_TCP_Sources/FreeRTOS_DHCP.c:1280 #2 0x45038c in xHandleWaitingOffer test/unit-test/build/Annexed_TCP_Sources/FreeRTOS_DHCP.c:334 #3 0x45366a in vDHCPProcessEndPoint test/unit-test/build/Annexed_TCP_Sources/FreeRTOS_DHCP.c:735 #4 0x44fe57 in vDHCPProcess test/unit-test/build/Annexed_TCP_Sources/FreeRTOS_DHCP.c:263 #5 0x418d2c in test_vDHCPProcess_eWaitingOffer_CorrectState_ValidBytesInMessage_MatchingEndPoint test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_utest.c:147 Diagnosis: pxDHCPMessage in prvProcessDHCPReplies() is the unlucky null pointer. As commented, it is expected to be set as an out-arg of FreeRTOS_recvfrom() due to calling it with FREERTOS_ZERO_COPY, but the condition for it in the mocked FreeRTOS_recvfrom() is that the sum of all flags is FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK. Finding the right fix: Should we add a null check? Nope. Set the FREERTOS_MSG_PEEK flag? Nope. The mocked function did not check the FREERTOS_ZERO_COPY flag properly. Observe that in the real FreeRTOS_recvfrom(), specifically inside prvRecvFrom_CopyPacket(), the condition for setting the zero-copy pointer into the buffer with the data depends only on one flag - FREERTOS_ZERO_COPY - and ignores the rest. It is obviously important that the mocked condition is exactly the same. * FreeRTOS_ND_utest: Fix segfaults caused by no ethernet buffer * test_prvProcessEthernetPacket_*(): Fix memset(NULL, …) segfaults The pointer was used before initialized. If it happened to be NULL, the test would segfault. * unit-test: Fix pxEthernetBuffer[-ipIP_TYPE_OFFSET] buffer underflows The tested functions intentionally expect there to be bytes before the ethernet buffer: * test_FreeRTOS_GetUDPPayloadBuffer_*(): The code under test, FreeRTOS_GetUDPPayloadBuffer_Multi, writes 6 bytes before the ethernet buffer. This looks intentional, as the write is commented as doing that. * FreeRTOS_IP_utest: The code under test, prvProcessIPPacket() intentionally writes a byte at offset -ipIP_TYPE_OFFSET into its ethernet buffer. I am thankful for the generous comment about the ipIP_TYPE_OFFSET. * test_vTCPWindowDestroy_list_length_not_zero(): Fix buffer overflow due to struct interposing The test was crashing due to what AddressSanitizer calls a buffer overflow, or really, interposing a TCPSegment_t on top of a TCPWindow_t::xRxSegments member and accessing an interposed struct member that fell outside the underlying TCPWindow_t struct. The naive fix - not doing that - works: void test_vTCPWindowDestroy_list_length_not_zero( void ) { TCPWindow_t xWindow = { 0 }; - List_t * pxSegments = &( xWindow.xRxSegments ); + TCPSegment_t xSegment = { 0 }; listLIST_IS_INITIALISED_ExpectAnyArgsAndReturn( pdFALSE ); listLIST_IS_INITIALISED_ExpectAnyArgsAndReturn( pdTRUE ); listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 1 ); - listGET_OWNER_OF_HEAD_ENTRY_ExpectAnyArgsAndReturn( pxSegments ); + listGET_OWNER_OF_HEAD_ENTRY_ExpectAnyArgsAndReturn( &xSegment ); /* ->vTCPWindowFree */ - uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); - uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 0 ); vTCPWindowDestroy( &xWindow ); } However, this became a different test, as evidenced by the less than 100% line coverage, that two function call expectations had to go, and that it functionally became an exact copy of the next test. To reach the holes in the test coverage opened by the naive fix, the two list items' container pointers also needed and sufficed to be set. * test_eARPGetCacheEntryByMac_OneMatchingEntry(): Arrest dangling pointer This test was using the stack of a previously returned function (probably a previous test). Highlights from AddressSanitizer output: ==15832==ERROR: AddressSanitizer: stack-use-after-return READ of size 8 at 0x7fdefb013670 thread T0 #0 0x4325bf in eARPGetCacheEntryByMac source/FreeRTOS_ARP.c:930 #1 0x421a71 in test_eARPGetCacheEntryByMac_OneMatchingEntry (test/unit-test/build/bin/tests/FreeRTOS_ARP_utest+0x421a71) Address 0x7fdefb013670 is located in stack of thread T0 at offset 624 in frame #0 0x41f941 in test_vARPRefreshCacheEntry_IPAndMACInDifferentLocations1 (test/unit-test/build/bin/tests/FreeRTOS_ARP_utest+0x41f941) This frame has 2 object(s): [48, 54) 'xMACAddress' (line 1937) [80, 640) 'xEndPoint' (line 1941) <== Memory access at offset 624 is inside this variable Nulling the dangling pointer is enough to fix the test, but in order to keep the 100% line coverage, it must point at somewhere valid. Therefore doing that. * FreeRTOS_TCP_Transmission_utest: Fix stack use after return: Point at own endpoint * FreeRTOS_TCP_IP_utest.c: Fix buffer overflow * prvTCPNextTimeout(): Fix leftshift by ~0 encountered in unittest This expression is obviously undefined when ucRepCount is 0 (leftshift by ~0): 3000U << ( ucRepCount - 1U ) Which is fine if that is impossible. But is it? This case is handled later by clamping the result from 0 to 1 (which hints at how this accidentally works), and this is being tested for (in FreeRTOS_TCP_IP_utest.c:: test_prvTCPNextTimeout_ConnSyn_State_Active_Rep0). I'm also surprised that neither Gcc or Clang optimizes the UB away (which would make the code behave differently with optimization): 1500U << ucRepCount It is very tempting to apply this fix, but 1ms is very different from 1500ms. That may well speak more for lowering the scale factor than making exceptions, though. But not now: For the purpose of fixing sanitizer failures, let's preserve the behaviour for now. * FreeRTOS_DNS_Callback_utest: Fix buffer overflow caused by mocked malloc * test_vReceiveRA_vRAProcess(): Fix buffer overflow in test: Don't cast The struct used as ethernet buffer did not contain the supposed data. The supposed data, however, seems to be correct based on this resource: https://support.huawei.com/enterprise/en/doc/ EDOC1100174721/8ebcb3c3/icmpv6-router-advertisement-ra-message AddressSanitizer called it a buffer overflow just because the buffer happened to be shorter than the supposed data. To make this evident and let type safety prevent this from compiling the wrong way, let's define a struct that contains the right data, and take pointers from the addresses of members instead of casting and doing manual offset calculations as far as possible. Also remove unused variables. I also wonder if the first test is not a subset of the second. It causes a subset of things to happen in the code under test, and their names only differ by a typo. * test_DNS_ParseDNSReply_answer_lmmnr_reply3(): Fix test failure due to use before initialization * DNS: test_SendRequest_fail(): Fix testing the failure scenario * FreeRTOS_DNS_utest.c: Fix size to copy when copying pointers instead of target * unit-test of DHCP option parser: Delete the buffer overflow Symptom: AddressSanitizer: dynamic-stack-buffer-overflow on address 0x7ffc9dfa5c07 READ of size 1 at 0x7ffc9dfa5c07 thread T0 #0 0x459a49 in prvProcessDHCPReplies test/unit-test/build/Annexed_TCP_Sources/FreeRTOS_DHCP.c:1310 #1 0x4526d2 in vHandleWaitingAcknowledge test/unit-test/build/Annexed_TCP_Sources/FreeRTOS_DHCP.c:495 #2 0x4544ef in vDHCPProcessEndPoint test/unit-test/build/Annexed_TCP_Sources/FreeRTOS_DHCP.c:739 #3 0x43dbd9 in test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2 (test/unit-test/build/bin/tests/FreeRTOS_DHCP_utest+0x43dbd9) Address 0x7ffc9dfa5c07 is located in stack of thread T0 SUMMARY: AddressSanitizer: dynamic-stack-buffer-overflow test/unit-test/build/Annexed_TCP_Sources/FreeRTOS_DHCP.c:1310 in prvProcessDHCPReplies Shadow bytes around the buggy address: 0x7ffc9dfa5980: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x7ffc9dfa5a00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x7ffc9dfa5a80: 00 00 00 00 00 00 00 00 ca ca ca ca 00 00 00 00 0x7ffc9dfa5b00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x7ffc9dfa5b80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =>0x7ffc9dfa5c00:[05]cb cb cb cb cb cb cb 00 00 00 00 00 00 00 00 0x7ffc9dfa5c80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x7ffc9dfa5d00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x7ffc9dfa5d80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x7ffc9dfa5e00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x7ffc9dfa5e80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Left alloca redzone: ca Right alloca redzone: cb There were two problems that conspired to create this segfault. The first was allowing the option parser to run off the end of the buffer at all: /* ulGenericLength is incremented by 100 to have uxDNSCount > ipconfigENDPOINT_DNS_ADDRESS_COUNT scenario */ ulGenericLength = sizeof( DHCPMsg ) + 100; The second problem was letting it overshoot the stop byte (0xFF). Which is a problem with having manually updated indexes and length fields. The stop byte was at the end of the buffer, but was of no help, because the buffer length was off by -3 (missing 2 bytes for the opcode and length field of the 6 server addresses and 1 byte to account for an unexplained hole in the serialized stream). The real fix for this kind of fragility is using some helper funcitons for serializing the data while keeping indexes and lenghts consistent (not to mention collapsing repeated lines 8-fold). Anyway, it is trivial to add a check that the serialized stream ends at the end of the buffer (done). Whether to add a functioning stop byte does not matter and should not be needed anymore with such a check. I initially fixed it the wrong way, by keeping it within the same buffer, which hurt line coverage. But what the test wants to test is as commented: At least 6 server addresses, because that's the value of ipconfigENDPOINT_DNS_ADDRESS_COUNT + 1. No "invalid" length required, just an overabundance of DNS servers. As such, let's rename the test. Btw, the test was using a VLA (fixed), and most of the uint32_t writes are still unaligned (I replaced one of them with memcpy). * test_eHandleIPv6ExtensionHeaders_TCPHappyPath: Fix buffer overflow * FreeRTOS_DNS.c: Fix NULL deref encountered in test_FreeRTOS_gethostbyname_SuccessAddressInCache * FreeRTOS_DNS_Parser_utest: Don't return dangling pointers UBSan happens to catch this as a misaligned pointer deref within the null page one moment before segfault: source/FreeRTOS_DNS_Parser.c:761:49: runtime error: member access within misaligned address 0x00000000012c for type 'struct freertos_addrinfo', which requires 8 byte alignment This was traced back to the test test_parseDNSAnswer_dns_nocallback_false(), which creates an uninitialized pointer and passes it on. Other tests were also found doing the same, though did not lead to segfault on GCC 12 and 13, except did on GCC 11 in CI with AddressSanitizer. This is a class of error that a higher warning level could easily forbid (reading an uninitialized variable, pointer or not): -Werror=maybe-uninitialized * FreeRTOS_DHCP_utest: Fix a read out of bounds xProcessCheckOption() reads the length from the second byte. So for the purpose of testing reading the second byte, but no more, the buffer length was correctly given as 2, except that the buffer length must then be at least 2. * FreeRTOS_{DNS,Routing}_utest.c: Fix off-by-one buffer overflows FreeRTOS_DNS_utest.c::test_FreeRTOS_gethostbyname_FailLongAddress: Array length vs index of last element: I was about to add one more byte to the buffer, but it looked like that had been attempted before without remembering to initialize them. Therefore, remove those bytes instead. FreeRTOS_Routing_utest.c::test_pcEndpointName_IPv{4,6}_HappyPath: Can be summed up as sizeof() != strlen(). These tests were copying one byte too many from their test input strings. Non-functional cleanups: * Let input strings have static storage duration (avoid copy to stack). * I found it confusing to take the address of the string constants, as it performs the same pointer decay as doing nothing. * unit-test FreeRTOS_DHCP_stubs.c: Fix NetworkBufferDescriptor_t alignment * FreeRTOS_{DHCPv6,DNS}_utest: Fix memory leaks Consider undoing this and see if the code under test needs fixing. LeakSanitizer finds these. * FreeRTOS_DNS_Parser_utest: Fix misaligned writes in the test * FreeRTOS_TCP_WIN_utest.c: Fix memory leaks of type free(NULL) The pointer to the allocated memory was reset. ⏚ * FreeRTOS_DHCP_utest: Fix misaligned writing of DHCP option fields Symptom (UB Sanitizer): Store to misaligned address 0x7ffe* for type 'uint32_t', which requires 4 byte alignment When repeated, these 4-byte fields are 2 bytes apart (because of the option and length bytes). The padding byte added to each test does not solve this problem (consider removing). Should have used memcpy (done). Actually, one thing that makes memcpy tedious is that it takes an address, not a value. I got tired of memcpy halfway through; this is what I mean by helper functions (see the commit about deleting a buffer overflow): The ultimate solution is not memcpy, but helpers that remove those manual indexes and length fields, and with that, the possibility for inconsistencies that can lead to such a buffer overflow. * FreeRTOS_ND_utest.c: Remove failing but redundant test test_prvProcessICMPMessage_IPv6_NeighborSolicitationCorrectLen() required these fixes when compiled with -fsanitize=address,memory +usGenerateProtocolChecksum_IgnoreAndReturn( ipCORRECT_CRC ); +vReturnEthernetFrame_ExpectAnyArgs(); … but only this fix when compiled regularly: +usGenerateProtocolChecksum_IgnoreAndReturn( ipCORRECT_CRC ); Thankfully, the intention is clear from the comment. It fails extra with sanitization because the two compared IP addresses actually do compare equal. Which is fixable. But removing the test did not impact coverage. * unit-test: Fix differences between with and without sanitization due to lack of initialization * unit-test: Add FIXME for behavioural difference with sanitizers * FreeRTOS_DNS_Parser_utest.c: Fix buffer alignment * CI: Add SANITIZE=address,undefined build As commented, it had to be a separate build because branch coverage (currently) doesn't ignore artificial branches added by sanitizers. On reusing the same build directory: It's totally possible to use separate build directories in build/, but there is no correctness benefit (CMake rebuilds the object files whose recipe has changed anyway). Rather, CMake saves (130) jobs that don't need to run again when reusing the same build directory. On which builds to build and run first (aubsan before coverage): When it matters, which is when a test is crashing, that's generally when you want to see the AddressSanitizer output. * FreeRTOS_ND_utest: Don't use an uninitialized ip address … it's not fun when it only fails in CI. The lookup happened to fail to fail with AddressSanitizer, but only on GCC 11 (not 12 of 13). * FreeRTOS_DHCP_utest: Fix attempt at making recvfrom return a NULL buffer With Gcc 11 + AddressSanitizer, the mocked recvfrom would not return a NULL buffer (unlike Gcc 12 and 13 with and without sanitization). A custom stub function gave enough control to do that. The existing FreeRTOS_recvfrom_Generic_NullBuffer() stub did almost the same, but was unused and meaningless (failed to set its out-argument), so it could be replaced. * FreeRTOS_ND_utest: Fix test failures due to missing initialization test_SendPingRequestIPv6_SendToIP_Pass(): This test segfaulted without AddressSanitizer: 'build/normal/bin/tests/FreeRTOS…' terminated by signal SIGSEGV test_SendPingRequestIPv6_Assert(): ==7143==AddressSanitizer CHECK failed: ../../../../src/libsanitizer/asan/asan_descriptions.cpp:80 "((0 && "Address is not in memory and not in shadow?")) != (0)" (0x0, 0x0) #0 0x7ff6c812f9a8 in AsanCheckFailed ../../../../src/libsanitizer/asan/asan_rtl.cpp:74 #1 0x7ff6c815032e in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) ../../../../src/libsanitizer/sanitizer_common/sanitizer_termination.cpp:78 #2 0x7ff6c809fa77 in GetShadowKind ../../../../src/libsanitizer/asan/asan_descriptions.cpp:80 #3 0x7ff6c809fa77 in __asan::GetShadowAddressInformation(unsigned long, __asan::ShadowAddressDescription*) ../../../../src/libsanitizer/asan/asan_descriptions.cpp:96 #4 0x7ff6c809fa77 in __asan::GetShadowAddressInformation(unsigned long, __asan::ShadowAddressDescription*) ../../../../src/libsanitizer/asan/asan_descriptions.cpp:93 #5 0x7ff6c80a1296 in __asan::AddressDescription::AddressDescription(unsigned long, unsigned long, bool) ../../../../src/libsanitizer/asan/asan_descriptions.cpp:441 #6 0x7ff6c80a3a84 in __asan::ErrorGeneric::ErrorGeneric(unsigned int, unsigned long, unsigned long, unsigned long, unsigned long, bool, unsigned long) ../../../../src/libsanitizer/asan/asan_errors.cpp:389 #7 0x7ff6c812efc5 in __asan::ReportGenericError(unsigned long, unsigned long, unsigned long, unsigned long, bool, unsigned long, unsigned int, bool) ../../../../src/libsanitizer/asan/asan_report.cpp:476 #8 0x7ff6c80abc44 in __interceptor_memset ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:799 #9 0x55f2e38a3620 in FreeRTOS_SendPingRequestIPv6 build/u22/Annexed_TCP_Sources/FreeRTOS_ND.c:768 #10 0x55f2e3893053 in test_SendPingRequestIPv6_Assert test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c:1065 #11 0x55f2e389c5dd in run_test build/u22/FreeRTOS_ND_utest_runner.c:201 #12 0x55f2e389ca84 in main build/u22/FreeRTOS_ND_utest_runner.c:252 #13 0x7ff6c6bcbd8f (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) #14 0x7ff6c6bcbe3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) #15 0x55f2e38873d4 in _start (build/u22/bin/tests/FreeRTOS_ND_utest+0x233d4 test_prvProcessICMPMessage_IPv6_NeighborSolicitationNullEP() behaved different with and without ASan on Gcc 11. Without AddressSanitizer on Gcc 11: FreeRTOS_ND_utest.c:1427:test_prvProcessICMPMessage_IPv6_NeighborSolicitationNullEP: FAIL:Function usGenerateProtocolChecksum. Called more times than expected. * test_lTCPWindowTxAdd_nothing_to_do(): Fix TCP window initialization Under Gcc 11, this expression in the tested function lTCPWindowTxAdd() was always true, leading to imperfect coverage: pxSegment->lDataLength < pxSegment->lMaxLength With Gcc 13, they were both 0. Let's add zero-initialization to make this what's tested for. --------- Co-authored-by: Tony Josi --- .github/.cSpellWords.txt | 1 + .github/workflows/ci.yml | 37 +- source/FreeRTOS_DNS.c | 2 +- source/FreeRTOS_TCP_IP.c | 9 +- test/unit-test/CMakeLists.txt | 6 + .../FreeRTOS_ARP/FreeRTOS_ARP_utest.c | 12 +- .../FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c | 35 +- .../FreeRTOS_DHCP/FreeRTOS_DHCP_utest.c | 441 ++++++------------ .../FreeRTOS_DHCPv6/FreeRTOS_DHCPv6_utest.c | 1 + .../FreeRTOS_DNS/FreeRTOS_DNS_utest.c | 19 +- test/unit-test/FreeRTOS_DNS/ut.cmake | 2 +- .../FreeRTOS_DNS_Cache_utest.c | 36 +- test/unit-test/FreeRTOS_DNS_Cache/ut.cmake | 2 +- .../FreeRTOS_DNS_Callback_utest.c | 88 ++-- test/unit-test/FreeRTOS_DNS_Callback/ut.cmake | 2 +- .../FreeRTOS_DNS_ConfigNoCallback_utest.c | 5 +- .../FreeRTOS_DNS_ConfigNoCallback/ut.cmake | 2 +- .../FreeRTOS_DNS_Networking_utest.c | 3 +- .../FreeRTOS_DNS_Networking/ut.cmake | 2 +- .../FreeRTOS_DNS_Parser_utest.c | 57 +-- test/unit-test/FreeRTOS_DNS_Parser/ut.cmake | 2 +- .../unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c | 163 +++---- .../FreeRTOS_IP_DiffConfig1_utest.c | 2 +- .../FreeRTOS_IPv6/FreeRTOS_IPv6_stubs.c | 6 +- .../FreeRTOS_IPv6/FreeRTOS_IPv6_utest.c | 6 +- .../unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c | 58 +-- .../unit-test/FreeRTOS_RA/FreeRTOS_RA_utest.c | 39 +- .../FreeRTOS_Routing/FreeRTOS_Routing_utest.c | 12 +- .../FreeRTOS_Sockets/FreeRTOS_Sockets_stubs.c | 2 + ...eeRTOS_Sockets_DiffConfig_privates_utest.c | 6 +- ...TOS_Sockets_DiffConfig1_GenericAPI_utest.c | 8 +- ...eeRTOS_Sockets_DiffConfig1_TCP_API_utest.c | 4 +- ...eeRTOS_Sockets_DiffConfig1_UDP_API_utest.c | 2 + ...eRTOS_Sockets_DiffConfig1_privates_utest.c | 2 + .../FreeRTOS_TCP_IP/FreeRTOS_TCP_IP_utest.c | 22 +- .../FreeRTOS_TCP_Transmission_utest.c | 14 +- .../FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_utest.c | 22 +- test/unit-test/FreeRTOS_TCP_WIN/ut.cmake | 2 +- test/unit-test/FreeRTOS_Tiny_TCP/ut.cmake | 2 +- test/unit-test/cmock/create_test.cmake | 2 +- 40 files changed, 520 insertions(+), 618 deletions(-) diff --git a/.github/.cSpellWords.txt b/.github/.cSpellWords.txt index d192c57c51..ed12e1e9c1 100644 --- a/.github/.cSpellWords.txt +++ b/.github/.cSpellWords.txt @@ -454,6 +454,7 @@ FPSP FRAMERX FRMFILTER frms +fsanitize FSDMA FTSR FUDUP diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ff3e72a48..4a1de02ec8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,27 +38,56 @@ jobs: echo "::endgroup::" echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" + # Separate builds for sanitizers and coverage: + # These can currently not be combined without branch coverage dilution. - env: - stepName: Build Unit Tests + stepName: Build Unit Tests (aubsan build) name: ${{ env.stepName }} run: | # ${{ env.stepName }} echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" - cmake -S test/unit-test -B test/unit-test/build/ -G Ninja - cmake --build test/unit-test/build/ --target all + cmake --fresh -G Ninja -S test/unit-test -B test/unit-test/build/ -DSANITIZE=address,undefined + ninja -C test/unit-test/build/ echo "::endgroup::" echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" - env: - stepName: Run Unit Tests + stepName: Run Unit Tests (aubsan build) name: ${{ env.stepName }} shell: bash run: | # ${{ env.stepName }} echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" + env ASAN_OPTIONS=detect_odr_violation=0 ctest --test-dir test/unit-test/build/ -E system --output-on-failure + + echo "::endgroup::" + echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" + + - env: + stepName: Build Unit Tests (coverage build) + name: ${{ env.stepName }} + run: | + # ${{ env.stepName }} + echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" + + cmake --fresh -G Ninja -S test/unit-test -B test/unit-test/build/ -DSANITIZE= + ninja -C test/unit-test/build/ + + echo "::endgroup::" + echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}" + + - env: + stepName: Run Unit Tests (coverage build) + name: ${{ env.stepName }} + shell: bash + run: | + # ${{ env.stepName }} + echo -e "::group::${{ env.bashInfo }} ${{ env.stepName }} ${{ env.bashEnd }}" + + find test/unit-test/build/ -name '*.gcda' -delete ctest --test-dir test/unit-test/build/ -E system --output-on-failure echo "::endgroup::" diff --git a/source/FreeRTOS_DNS.c b/source/FreeRTOS_DNS.c index 0bc2029543..b29eb0cfe5 100644 --- a/source/FreeRTOS_DNS.c +++ b/source/FreeRTOS_DNS.c @@ -656,7 +656,7 @@ if( ulIPAddress != 0UL ) { #if ( ipconfigUSE_IPv6 != 0 ) - if( ( ppxAddressInfo != NULL ) && ( ( *ppxAddressInfo )->ai_family == FREERTOS_AF_INET6 ) ) + if( ( ppxAddressInfo != NULL ) && ( *ppxAddressInfo != NULL ) && ( ( *ppxAddressInfo )->ai_family == FREERTOS_AF_INET6 ) ) { FreeRTOS_printf( ( "prvPrepareLookup: found '%s' in cache: %pip\n", pcHostName, ( void * ) ( *ppxAddressInfo )->xPrivateStorage.sockaddr.sin_address.xIP_IPv6.ucBytes ) ); diff --git a/source/FreeRTOS_TCP_IP.c b/source/FreeRTOS_TCP_IP.c index de9e14dff2..528224b407 100644 --- a/source/FreeRTOS_TCP_IP.c +++ b/source/FreeRTOS_TCP_IP.c @@ -627,7 +627,14 @@ * active connect(). */ if( pxSocket->u.xTCP.ucRepCount < 3U ) { - ulDelayMs = ( ( ( uint32_t ) 3000U ) << ( pxSocket->u.xTCP.ucRepCount - 1U ) ); + if( pxSocket->u.xTCP.ucRepCount == 0U ) + { + ulDelayMs = 0U; + } + else + { + ulDelayMs = ( ( uint32_t ) 3000U ) << ( pxSocket->u.xTCP.ucRepCount - 1U ); + } } else { diff --git a/test/unit-test/CMakeLists.txt b/test/unit-test/CMakeLists.txt index 253cf45b2b..cac757688e 100644 --- a/test/unit-test/CMakeLists.txt +++ b/test/unit-test/CMakeLists.txt @@ -18,6 +18,12 @@ if( ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR} ) message( FATAL_ERROR "In-source build is not allowed. Please build in a separate directory, such as ${PROJECT_SOURCE_DIR}/build." ) endif() +set(SANITIZE "" CACHE STRING "Comma-separated list of compiler sanitizers to enable; empty string disables.") +if(NOT ${SANITIZE} STREQUAL "") + add_compile_options(-fsanitize=${SANITIZE} -fno-sanitize-recover) + add_link_options(-fsanitize=${SANITIZE} -fno-sanitize-recover) +endif() + # Set global path variables. get_filename_component( __MODULE_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE ) set( MODULE_ROOT_DIR ${__MODULE_ROOT_DIR} CACHE INTERNAL "FreeRTOS-Plus-TCP repository root." ) diff --git a/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c b/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c index 3d733142e9..dcb4e13dd3 100644 --- a/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c +++ b/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_utest.c @@ -2034,29 +2034,34 @@ void test_eARPGetCacheEntryByMac_OneMatchingEntry( void ) eARPLookupResult_t eResult; MACAddress_t xMACAddress = { 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 }; int i; - struct xNetworkInterface * xInterface; + NetworkEndPoint_t xNetworkEndPoint = { 0 }; + NetworkInterface_t xInterface, * pxInterface = NULL; + + xNetworkEndPoint.pxNetworkInterface = &xInterface; /* =================================================== */ /* Make sure one entry matches. */ for( i = 0; i < ipconfigARP_CACHE_ENTRIES; i++ ) { xARPCache[ i ].ulIPAddress = 0xAABBCCDD; + xARPCache[ i ].pxEndPoint = &xNetworkEndPoint; memset( xARPCache[ i ].xMACAddress.ucBytes, 0x11, sizeof( xMACAddress.ucBytes ) ); } ulEntryToTest = 1; memset( xARPCache[ ulEntryToTest ].xMACAddress.ucBytes, 0x22, sizeof( xMACAddress.ucBytes ) ); xARPCache[ ulEntryToTest ].ulIPAddress = 0xAABBCCEE; - eResult = eARPGetCacheEntryByMac( &xMACAddress, &ulIPAddress, &xInterface ); + eResult = eARPGetCacheEntryByMac( &xMACAddress, &ulIPAddress, &pxInterface ); TEST_ASSERT_EQUAL( eARPCacheHit, eResult ); TEST_ASSERT_EQUAL( xARPCache[ ulEntryToTest ].ulIPAddress, ulIPAddress ); + TEST_ASSERT_EQUAL( &xInterface, pxInterface ); /* =================================================== */ eResult = eARPGetCacheEntryByMac( &xMACAddress, &ulIPAddress, NULL ); TEST_ASSERT_EQUAL( eARPCacheHit, eResult ); TEST_ASSERT_EQUAL( xARPCache[ ulEntryToTest ].ulIPAddress, ulIPAddress ); /* =================================================== */ xARPCache[ ulEntryToTest ].pxEndPoint = NULL; - eResult = eARPGetCacheEntryByMac( &xMACAddress, &ulIPAddress, &xInterface ); + eResult = eARPGetCacheEntryByMac( &xMACAddress, &ulIPAddress, &pxInterface ); TEST_ASSERT_EQUAL( eARPCacheHit, eResult ); TEST_ASSERT_EQUAL( xARPCache[ ulEntryToTest ].ulIPAddress, ulIPAddress ); /* =================================================== */ @@ -2305,6 +2310,7 @@ void test_eARPGetCacheEntry_NoCacheHit( void ) { xARPCache[ i ].ulIPAddress = 0; xARPCache[ i ].ucValid = ( uint8_t ) pdTRUE; + xARPCache[ i ].pxEndPoint = NULL; } ulSavedGatewayAddress = xNetworkAddressing.ulGatewayAddress; diff --git a/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c b/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c index 0556507109..350372d895 100644 --- a/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c +++ b/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c @@ -12,6 +12,11 @@ #include "FreeRTOS_IP.h" #include "FreeRTOS_IP_Private.h" +#define prvROUND_UP_TO( SIZE, ALIGNMENT ) ( ( ( SIZE ) + ( ALIGNMENT ) -1 ) / ( ALIGNMENT ) *( ALIGNMENT ) ) + +/* FIXME: Consider instead fixing ipBUFFER_PADDING if it's supposed to be pointer aligned. */ +#define prvALIGNED_BUFFER_PADDING prvROUND_UP_TO( ipBUFFER_PADDING, sizeof( void * ) ) + struct xNetworkEndPoint * pxNetworkEndPoints = NULL; NetworkInterface_t xInterfaces[ 1 ]; @@ -212,9 +217,9 @@ static NetworkBufferDescriptor_t * GetNetworkBuffer( size_t SizeOfEthBuf, long unsigned int xTimeToBlock, int callbacks ) { - NetworkBufferDescriptor_t * pxNetworkBuffer = malloc( sizeof( NetworkBufferDescriptor_t ) + ipBUFFER_PADDING ) + ipBUFFER_PADDING; + NetworkBufferDescriptor_t * pxNetworkBuffer = malloc( sizeof( NetworkBufferDescriptor_t ) + prvALIGNED_BUFFER_PADDING ) + prvALIGNED_BUFFER_PADDING; - pxNetworkBuffer->pucEthernetBuffer = malloc( SizeOfEthBuf + ipBUFFER_PADDING ) + ipBUFFER_PADDING; + pxNetworkBuffer->pucEthernetBuffer = malloc( SizeOfEthBuf + prvALIGNED_BUFFER_PADDING ) + prvALIGNED_BUFFER_PADDING; /* Ignore the callback count. */ ( void ) callbacks; @@ -230,9 +235,9 @@ static NetworkBufferDescriptor_t * GetNetworkBuffer( size_t SizeOfEthBuf, static void ReleaseNetworkBuffer( void ) { /* Free the ethernet buffer. */ - free( ( ( uint8_t * ) pxGlobalNetworkBuffer[ --GlobalBufferCounter ]->pucEthernetBuffer ) - ipBUFFER_PADDING ); + free( ( ( uint8_t * ) pxGlobalNetworkBuffer[ --GlobalBufferCounter ]->pucEthernetBuffer ) - prvALIGNED_BUFFER_PADDING ); /* Free the network buffer. */ - free( ( ( uint8_t * ) pxGlobalNetworkBuffer[ GlobalBufferCounter ] ) - ipBUFFER_PADDING ); + free( ( ( uint8_t * ) pxGlobalNetworkBuffer[ GlobalBufferCounter ] ) - prvALIGNED_BUFFER_PADDING ); } static void ReleaseUDPBuffer( const void * temp, @@ -289,19 +294,19 @@ static int32_t FreeRTOS_recvfrom_Generic( const ConstSocket_t xSocket, return ulGenericLength; } -static int32_t FreeRTOS_recvfrom_Generic_NullBuffer( const ConstSocket_t xSocket, - void * pvBuffer, - size_t uxBufferLength, - BaseType_t xFlags, - struct freertos_sockaddr * pxSourceAddress, - socklen_t * pxSourceAddressLength, - int callbacks ) +static int32_t FreeRTOS_recvfrom_Small_NullBuffer( const ConstSocket_t xSocket, + void * pvBuffer, + size_t uxBufferLength, + BaseType_t xFlags, + struct freertos_sockaddr * pxSourceAddress, + socklen_t * pxSourceAddressLength, + int callbacks ) { - pvBuffer = NULL; - return xSizeofUDPBuffer; + /* Admittedly, returning a (NULL, 1) slice is contrived, but coverage speaks. */ + *( ( uint8_t ** ) pvBuffer ) = NULL; + return 1; } - static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromLessBytesNoTimeout( const ConstSocket_t xSocket, void * pvBuffer, size_t uxBufferLength, @@ -336,7 +341,7 @@ static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_ pxIterator = pxIterator->pxNext; } - if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK ) + if( ( xFlags & FREERTOS_ZERO_COPY ) != 0 ) { *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer; } diff --git a/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_utest.c b/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_utest.c index 7da21e3584..dfe97e4038 100644 --- a/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_utest.c +++ b/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_utest.c @@ -53,6 +53,38 @@ extern uint8_t pucUDPBuffer[]; extern uint8_t DHCP_header[]; +/*-------------------------------------Helpers--------------------------------*/ + +static void prvWriteDHCPOption( uint8_t ** ppucBuf, + uint8_t ucOp, + const void * pvPayload, + uint8_t ucLen ) +{ + uint8_t * pucBuf = *ppucBuf; + + *pucBuf++ = ucOp; + *pucBuf++ = ucLen; + memcpy( pucBuf, pvPayload, ucLen ); + pucBuf += ucLen; + + *ppucBuf = pucBuf; +} + +static void prvWriteDHCPOptionU8( uint8_t ** ppucBuf, + uint8_t ucOp, + uint8_t ucPayload ) +{ + prvWriteDHCPOption( ppucBuf, ucOp, &ucPayload, sizeof( ucPayload ) ); +} + +static void prvWriteDHCPOptionU32( uint8_t ** ppucBuf, + uint8_t ucOp, + uint32_t ulPayload ) +{ + /* TBD: htonl(ulPayload)? */ + prvWriteDHCPOption( ppucBuf, ucOp, &ulPayload, sizeof( ulPayload ) ); +} + /*---------------------------------------Test Cases--------------------------*/ void test_xIsDHCPSocket( void ) { @@ -1554,9 +1586,7 @@ void test_vDHCPProcessEndPoint_eWaitingOfferNullUDPBuffer( void ) pxNetworkEndPoints = pxEndPoint; - FreeRTOS_recvfrom_ExpectAndReturn( xDHCPv4Socket, NULL, 0UL, FREERTOS_ZERO_COPY, NULL, NULL, 1 ); - /* Ignore the buffer argument though. */ - FreeRTOS_recvfrom_IgnoreArg_pvBuffer(); + FreeRTOS_recvfrom_Stub( FreeRTOS_recvfrom_Small_NullBuffer ); vDHCPProcessEndPoint( pdFALSE, pdTRUE, pxEndPoint ); } @@ -2654,7 +2684,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsSendFails( void /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -2751,7 +2781,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsSendSucceeds( vo /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -2853,7 +2883,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsDHCPHookReturnDe /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -2952,7 +2982,7 @@ void test_vDHCPProcess_eWaitingOfferCorrectDHCPMessageTwoOptionsDHCPHookReturnEr /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3052,7 +3082,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerNoTimeout( vo /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -3137,7 +3167,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutGNBfai /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -3227,7 +3257,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutGNBSuc /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3322,7 +3352,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutPeriod /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3407,7 +3437,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsIncorrectServerTimeoutPeriod /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3493,7 +3523,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsCorrectServerLeaseTimeZero( /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3594,7 +3624,7 @@ void test_vDHCPProcess_eWaitingAcknowledgeTwoOptionsCorrectServerLeaseTimeLessTh /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3693,7 +3723,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_TwoOptions_CorrectServer_AptLeaseTime /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3791,7 +3821,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_TwoOptions_NACK( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3878,7 +3908,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_TwoOptions_OFFER( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by @@ -3980,7 +4010,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); DHCPOption += 6; /* Add Message type code. */ @@ -3988,7 +4018,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; + memcpy( &DHCPOption[ 2 ], &ulSubnetMask, sizeof( ulSubnetMask ) ); DHCPOption += 6; /* Add Message type code. */ @@ -3996,7 +4026,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; + memcpy( &DHCPOption[ 2 ], &ulGateway, sizeof( ulGateway ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4004,7 +4034,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; + memcpy( &DHCPOption[ 2 ], &ulLeaseTime, sizeof( ulLeaseTime ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4012,7 +4042,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulDNSServer; + memcpy( &DHCPOption[ 2 ], &ulDNSServer, sizeof( ulDNSServer ) ); /* Put the information in global variables to be returned by @@ -4126,7 +4156,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4134,7 +4164,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; + memcpy( &DHCPOption[ 2 ], &ulSubnetMask, sizeof( ulSubnetMask ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4142,7 +4172,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; + memcpy( &DHCPOption[ 2 ], &ulGateway, sizeof( ulGateway ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4150,7 +4180,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; + memcpy( &DHCPOption[ 2 ], &ulLeaseTime, sizeof( ulLeaseTime ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4158,7 +4188,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_AllOptionsCorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulDNSServer; + memcpy( &DHCPOption[ 2 ], &ulDNSServer, sizeof( ulDNSServer ) ); /* Put the information in global variables to be returned by @@ -4273,7 +4303,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4281,7 +4311,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; + memcpy( &DHCPOption[ 2 ], &ulSubnetMask, sizeof( ulSubnetMask ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4289,7 +4319,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; + memcpy( &DHCPOption[ 2 ], &ulGateway, sizeof( ulGateway ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4297,7 +4327,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; + memcpy( &DHCPOption[ 2 ], &ulLeaseTime, sizeof( ulLeaseTime ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4305,7 +4335,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 3; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulDNSServer; + memcpy( &DHCPOption[ 2 ], &ulDNSServer, sizeof( ulDNSServer ) ); /* Put the information in global variables to be returned by @@ -4363,33 +4393,29 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength( void ) TEST_ASSERT_EQUAL( xIPv4Addressing->ulNetMask, ulSubnetMask ); } -void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) +void test_vDHCPProcess_eWaitingAcknowledge_DNSServerOverabundance( void ) { struct xSOCKET xTestSocket; - TickType_t xTimeValue = 1234; - /* Create a bit longer DHCP message but keep it empty. */ - const BaseType_t xTotalLength = sizeof( struct xDHCPMessage_IPv4 ) + 1U /* Padding */ - + 3U /* DHCP offer */ - + 6U /* Server IP address */ - + 6U /* Subnet Mask */ - + 6U /* Gateway */ - + 6U /* Lease time */ - + 24U /* DNS server */ - + 1U /* End */; - uint8_t DHCPMsg[ xTotalLength ]; uint32_t DHCPServerAddress = 0xC0A80001; /* 192.168.0.1 */ uint32_t ulClientIPAddress = 0xC0A8000A; /* 192.168.0.10 */ uint32_t ulSubnetMask = 0xFFFFF100; /* 255.255.241.0 */ uint32_t ulGateway = 0xC0A80001; /* 192.168.0.1 */ uint32_t ulLeaseTime = 0x00000096; /* 150 seconds */ uint32_t ulDNSServer = 0xC0010101; /* 192.1.1.1 */ + uint8_t DHCPMsg[ + sizeof( DHCPMessage_IPv4_t ) + + 2U + sizeof( ( uint8_t ) dhcpMESSAGE_TYPE_ACK ) + + 2U + sizeof( DHCPServerAddress ) + + 2U + sizeof( ulSubnetMask ) + + 2U + sizeof( ulGateway ) + + 2U + sizeof( ulLeaseTime ) + + 2U + sizeof( ulDNSServer ) * ( ipconfigENDPOINT_DNS_ADDRESS_COUNT + 1 ) + ]; DHCPMessage_IPv4_t * pxDHCPMessage = ( DHCPMessage_IPv4_t * ) DHCPMsg; NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; IPV4Parameters_t * xIPv4Addressing = &( pxEndPoint->ipv4_settings ); - - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - + size_t xDNSServersToAdd = ipconfigENDPOINT_DNS_ADDRESS_COUNT + 1; /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); @@ -4404,8 +4430,8 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) /* Set the client IP address. */ pxDHCPMessage->ulYourIPAddress_yiaddr = ulClientIPAddress; - /* Leave one byte for the padding. */ - uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; + uint8_t * DHCPOption = &DHCPMsg[ sizeof( DHCPMessage_IPv4_t ) ]; + /* Add Message type code. */ DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; /* Add length. */ @@ -4413,13 +4439,13 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) /* Add the offer byte. */ DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - DHCPOption += 4; + DHCPOption += 3; /* Add Message type code. */ DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4427,7 +4453,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; + memcpy( &DHCPOption[ 2 ], &ulSubnetMask, sizeof( ulSubnetMask ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4435,7 +4461,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; + memcpy( &DHCPOption[ 2 ], &ulGateway, sizeof( ulGateway ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4443,21 +4469,29 @@ void test_vDHCPProcess_eWaitingAcknowledge_DNSIncorrectLength2( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; + memcpy( &DHCPOption[ 2 ], &ulLeaseTime, sizeof( ulLeaseTime ) ); DHCPOption += 6; /* Add Message type code. */ DHCPOption[ 0 ] = dhcpIPv4_DNS_SERVER_OPTIONS_CODE; /* Add length. */ - DHCPOption[ 1 ] = 24; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulDNSServer; + DHCPOption[ 1 ] = xDNSServersToAdd * sizeof( ulDNSServer ); + DHCPOption += 2; + while( xDNSServersToAdd-- > 0U ) + { + memcpy( DHCPOption, &ulDNSServer, sizeof( ulDNSServer ) ); + DHCPOption += sizeof( ulDNSServer ); + } + + /* A stop byte shall not be necessary to prevent the DHCP option parser from running off the end of the buffer. */ + /* *DHCPOption++ = 0xFF; */ + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, sizeof( DHCPMsg ) ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ ucGenericPtr = DHCPMsg; - ulGenericLength = sizeof( DHCPMsg ) + 100; /* ulGenericLength is incremented by 100 to have uxDNSCount > ipconfigENDPOINT_DNS_ADDRESS_COUNT scenario */ + ulGenericLength = sizeof( DHCPMsg ); /* This should remain unchanged. */ xDHCPv4Socket = &xTestSocket; @@ -4534,9 +4568,6 @@ void test_vDHCPProcess_eWaitingAcknowledge_IncorrectDNSServerAddress( void ) NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; IPV4Parameters_t * xIPv4Addressing = &( pxEndPoint->ipv4_settings ); - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - - /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); /* Copy the header here. */ @@ -4552,53 +4583,16 @@ void test_vDHCPProcess_eWaitingAcknowledge_IncorrectDNSServerAddress( void ) /* Leave one byte for the padding. */ uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 1; - /* Add the offer byte. */ - DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - - DHCPOption += 4; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SUBNET_MASK_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_GATEWAY_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_LEASE_TIME_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_DNS_SERVER_OPTIONS_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = FREERTOS_INADDR_ANY; + prvWriteDHCPOptionU8( &DHCPOption, dhcpIPv4_MESSAGE_TYPE_OPTION_CODE, dhcpMESSAGE_TYPE_ACK ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE, DHCPServerAddress ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SUBNET_MASK_OPTION_CODE, ulSubnetMask ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_GATEWAY_OPTION_CODE, ulGateway ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_LEASE_TIME_OPTION_CODE, ulLeaseTime ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_DNS_SERVER_OPTIONS_CODE, FREERTOS_INADDR_ANY ); + *DHCPOption++ = 0xFF; + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, xTotalLength ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -4680,9 +4674,6 @@ void test_vDHCPProcess_eWaitingAcknowledge_IncorrectDNSServerAddress2( void ) NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; IPV4Parameters_t * xIPv4Addressing = &( pxEndPoint->ipv4_settings ); - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - - /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); /* Copy the header here. */ @@ -4698,53 +4689,16 @@ void test_vDHCPProcess_eWaitingAcknowledge_IncorrectDNSServerAddress2( void ) /* Leave one byte for the padding. */ uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 1; - /* Add the offer byte. */ - DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - DHCPOption += 4; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SUBNET_MASK_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_GATEWAY_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_LEASE_TIME_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_DNS_SERVER_OPTIONS_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ipBROADCAST_IP_ADDRESS; + prvWriteDHCPOptionU8( &DHCPOption, dhcpIPv4_MESSAGE_TYPE_OPTION_CODE, dhcpMESSAGE_TYPE_ACK ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE, DHCPServerAddress ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SUBNET_MASK_OPTION_CODE, ulSubnetMask ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_GATEWAY_OPTION_CODE, ulGateway ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_LEASE_TIME_OPTION_CODE, ulLeaseTime ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_DNS_SERVER_OPTIONS_CODE, ipBROADCAST_IP_ADDRESS ); + *DHCPOption++ = 0xFF; + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, xTotalLength ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -4817,9 +4771,6 @@ void test_vDHCPProcess_eWaitingAcknowledge_IPv4ServerIncorrectLength( void ) uint8_t DHCPMsg[ xTotalLength ]; uint32_t DHCPServerAddress = 0xC0A80001; /* 192.168.0.1 */ uint32_t ulClientIPAddress = 0xC0A8000A; /* 192.168.0.10 */ - uint32_t ulSubnetMask = 0xFFFFF100; /* 255.255.241.0 */ - uint32_t ulGateway = 0xC0A80001; /* 192.168.0.1 */ - uint32_t ulLeaseTime = 0x00000096; /* 150 seconds */ DHCPMessage_IPv4_t * pxDHCPMessage = ( DHCPMessage_IPv4_t * ) DHCPMsg; NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; @@ -4854,7 +4805,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_IPv4ServerIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 4; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); DHCPOption += 6; /* Add Message type code. */ @@ -4862,7 +4813,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_IPv4ServerIncorrectLength( void ) /* Add length. */ DHCPOption[ 1 ] = 3; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + memcpy( &DHCPOption[ 2 ], &DHCPServerAddress, sizeof( DHCPServerAddress ) ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -4927,22 +4878,15 @@ void test_vDHCPProcess_eWaitingAcknowledge_SubnetMaskIncorrectLength( void ) const BaseType_t xTotalLength = sizeof( struct xDHCPMessage_IPv4 ) + 1U /* Padding */ + 3U /* DHCP offer */ + 6U /* Server IP address */ - + 6U /* Subnet Mask */ - + 6U /* Gateway */ - + 6U /* Lease time */ + + 5U /* Subnet Mask, truncated */ + 1U /* End */; uint8_t DHCPMsg[ xTotalLength ]; uint32_t DHCPServerAddress = 0xC0A80001; /* 192.168.0.1 */ uint32_t ulClientIPAddress = 0xC0A8000A; /* 192.168.0.10 */ uint32_t ulSubnetMask = 0xFFFFF100; /* 255.255.241.0 */ - uint32_t ulGateway = 0xC0A80001; /* 192.168.0.1 */ - uint32_t ulLeaseTime = 0x00000096; /* 150 seconds */ DHCPMessage_IPv4_t * pxDHCPMessage = ( DHCPMessage_IPv4_t * ) DHCPMsg; NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - - /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); /* Copy the header here. */ @@ -4958,28 +4902,13 @@ void test_vDHCPProcess_eWaitingAcknowledge_SubnetMaskIncorrectLength( void ) /* Leave one byte for the padding. */ uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 1; - /* Add the offer byte. */ - DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - DHCPOption += 4; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + prvWriteDHCPOptionU8( &DHCPOption, dhcpIPv4_MESSAGE_TYPE_OPTION_CODE, dhcpMESSAGE_TYPE_ACK ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE, DHCPServerAddress ); + prvWriteDHCPOption( &DHCPOption, dhcpIPv4_SUBNET_MASK_OPTION_CODE, &ulSubnetMask, 3 ); - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SUBNET_MASK_OPTION_CODE; - /* Add incorrect length. */ - DHCPOption[ 1 ] = 3; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; + *DHCPOption++ = 0xFF; + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, xTotalLength ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -5045,20 +4974,15 @@ void test_vDHCPProcess_eWaitingAcknowledge_GatewayIncorrectLength( void ) + 6U /* Server IP address */ + 6U /* Subnet Mask */ + 6U /* Gateway */ - + 6U /* Lease time */ + 1U /* End */; uint8_t DHCPMsg[ xTotalLength ]; uint32_t DHCPServerAddress = 0xC0A80001; /* 192.168.0.1 */ uint32_t ulClientIPAddress = 0xC0A8000A; /* 192.168.0.10 */ uint32_t ulSubnetMask = 0xFFFFF100; /* 255.255.241.0 */ uint32_t ulGateway = 0xC0A80001; /* 192.168.0.1 */ - uint32_t ulLeaseTime = 0x00000096; /* 150 seconds */ DHCPMessage_IPv4_t * pxDHCPMessage = ( DHCPMessage_IPv4_t * ) DHCPMsg; NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - - /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); /* Copy the header here. */ @@ -5074,36 +4998,21 @@ void test_vDHCPProcess_eWaitingAcknowledge_GatewayIncorrectLength( void ) /* Leave one byte for the padding. */ uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 1; - /* Add the offer byte. */ - DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - DHCPOption += 4; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; + prvWriteDHCPOptionU8( &DHCPOption, dhcpIPv4_MESSAGE_TYPE_OPTION_CODE, dhcpMESSAGE_TYPE_ACK ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE, DHCPServerAddress ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SUBNET_MASK_OPTION_CODE, ulSubnetMask ); - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SUBNET_MASK_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; - - DHCPOption += 6; /* Add Message type code. */ DHCPOption[ 0 ] = dhcpIPv4_GATEWAY_OPTION_CODE; /* Add incorrect length. */ DHCPOption[ 1 ] = 2; /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; + memcpy( &DHCPOption[ 2 ], &ulGateway, sizeof( ulGateway ) ); + DHCPOption += 6; + + *DHCPOption++ = 0xFF; + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, xTotalLength ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -5170,7 +5079,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength( void ) + 6U /* Server IP address */ + 6U /* Subnet Mask */ + 6U /* Gateway */ - + 6U /* Lease time */ + + 5U /* Lease time, truncated */ + 1U /* End */; uint8_t DHCPMsg[ xTotalLength ]; uint32_t DHCPServerAddress = 0xC0A80001; /* 192.168.0.1 */ @@ -5181,9 +5090,6 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength( void ) DHCPMessage_IPv4_t * pxDHCPMessage = ( DHCPMessage_IPv4_t * ) DHCPMsg; NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - - /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); /* Copy the header here. */ @@ -5199,45 +5105,15 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength( void ) /* Leave one byte for the padding. */ uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 1; - /* Add the offer byte. */ - DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - - DHCPOption += 4; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SUBNET_MASK_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_GATEWAY_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_LEASE_TIME_OPTION_CODE; - /* Add incorrect length. */ - DHCPOption[ 1 ] = 3; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; + prvWriteDHCPOptionU8( &DHCPOption, dhcpIPv4_MESSAGE_TYPE_OPTION_CODE, dhcpMESSAGE_TYPE_ACK ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE, DHCPServerAddress ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SUBNET_MASK_OPTION_CODE, ulSubnetMask ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_GATEWAY_OPTION_CODE, ulGateway ); + prvWriteDHCPOption( &DHCPOption, dhcpIPv4_LEASE_TIME_OPTION_CODE, &ulLeaseTime, 3 ); + *DHCPOption++ = 0xFF; + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, xTotalLength ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -5303,7 +5179,7 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength2( void ) + 6U /* Server IP address */ + 6U /* Subnet Mask */ + 6U /* Gateway */ - + 6U /* Lease time */ + + 5U /* Lease time */ + 1U /* End */; uint8_t DHCPMsg[ xTotalLength ]; uint32_t DHCPServerAddress = 0xC0A80001; /* 192.168.0.1 */ @@ -5314,9 +5190,6 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength2( void ) DHCPMessage_IPv4_t * pxDHCPMessage = ( DHCPMessage_IPv4_t * ) DHCPMsg; NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; - DHCPMsg[ xTotalLength - 1U ] = 0xFF; - - /* Set the header - or at least the start of DHCP message. */ memset( DHCPMsg, 0, sizeof( DHCPMsg ) ); /* Copy the header here. */ @@ -5332,45 +5205,15 @@ void test_vDHCPProcess_eWaitingAcknowledge_LeaseTimeIncorrectLength2( void ) /* Leave one byte for the padding. */ uint8_t * DHCPOption = &DHCPMsg[ sizeof( struct xDHCPMessage_IPv4 ) + 1 ]; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 1; - /* Add the offer byte. */ - DHCPOption[ 2 ] = dhcpMESSAGE_TYPE_ACK; - - DHCPOption += 4; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = DHCPServerAddress + 0x1234; - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_SUBNET_MASK_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulSubnetMask; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_GATEWAY_OPTION_CODE; - /* Add length. */ - DHCPOption[ 1 ] = 4; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulGateway; - - DHCPOption += 6; - /* Add Message type code. */ - DHCPOption[ 0 ] = dhcpIPv4_LEASE_TIME_OPTION_CODE; - /* Add incorrect length. */ - DHCPOption[ 1 ] = 3; - /* Add the offer byte. */ - *( ( uint32_t * ) &DHCPOption[ 2 ] ) = ulLeaseTime; + prvWriteDHCPOptionU8( &DHCPOption, dhcpIPv4_MESSAGE_TYPE_OPTION_CODE, dhcpMESSAGE_TYPE_ACK ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SERVER_IP_ADDRESS_OPTION_CODE, DHCPServerAddress + 0x1234 ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_SUBNET_MASK_OPTION_CODE, ulSubnetMask ); + prvWriteDHCPOptionU32( &DHCPOption, dhcpIPv4_GATEWAY_OPTION_CODE, ulGateway ); + prvWriteDHCPOption( &DHCPOption, dhcpIPv4_LEASE_TIME_OPTION_CODE, &ulLeaseTime, 3 ); + *DHCPOption++ = 0xFF; + TEST_ASSERT_EQUAL( DHCPOption - DHCPMsg, xTotalLength ); /* Put the information in global variables to be returned by * the FreeRTOS_recvrom. */ @@ -5903,7 +5746,7 @@ void test_xProcessCheckOption_LengthByteZero( void ) BaseType_t xResult; ProcessSet_t xSet; - uint8_t ucUDPPayload[ 1 ]; + uint8_t ucUDPPayload[ 2 ]; memset( &( ucUDPPayload ), 0, sizeof( ucUDPPayload ) ); @@ -5912,7 +5755,7 @@ void test_xProcessCheckOption_LengthByteZero( void ) xSet.ucOptionCode = dhcpIPv4_MESSAGE_TYPE_OPTION_CODE; xSet.pucByte = ucUDPPayload; xSet.uxIndex = 0; - xSet.uxPayloadDataLength = 2; + xSet.uxPayloadDataLength = sizeof( ucUDPPayload ); xResult = xProcessCheckOption( &xSet ); diff --git a/test/unit-test/FreeRTOS_DHCPv6/FreeRTOS_DHCPv6_utest.c b/test/unit-test/FreeRTOS_DHCPv6/FreeRTOS_DHCPv6_utest.c index 86e6a7f007..29a0492331 100644 --- a/test/unit-test/FreeRTOS_DHCPv6/FreeRTOS_DHCPv6_utest.c +++ b/test/unit-test/FreeRTOS_DHCPv6/FreeRTOS_DHCPv6_utest.c @@ -1388,6 +1388,7 @@ void test_vDHCPv6Process_ResetFromInit() vDHCP_RATimerReload_Expect( &xEndPoint, dhcpINITIAL_TIMER_PERIOD ); vDHCPv6Process( pdTRUE, &xEndPoint ); + vPortFree( xEndPoint.pxDHCPMessage ); /* Make LeakSanitizer happy. */ /* The endpoint sends the DHCPv6 Solicitation message to find the DHCPv6 server. * Then change the state to eWaitingSendFirstDiscover. */ diff --git a/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c b/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c index 73d656af1e..6daae41e46 100644 --- a/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c +++ b/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c @@ -149,10 +149,10 @@ void test_FreeRTOS_gethostbyname_FailNullAddress( void ) void test_FreeRTOS_gethostbyname_FailLongAddress( void ) { uint32_t ret; - char address[ ipconfigDNS_CACHE_NAME_LENGTH + 3 ]; + char address[ ipconfigDNS_CACHE_NAME_LENGTH + 1 ]; memset( address, 'a', ipconfigDNS_CACHE_NAME_LENGTH ); - address[ ipconfigDNS_CACHE_NAME_LENGTH + 3 ] = '\0'; + address[ ipconfigDNS_CACHE_NAME_LENGTH ] = '\0'; ret = FreeRTOS_gethostbyname( address ); @@ -776,10 +776,9 @@ void test_FreeRTOS_getaddrinfo_a_UnknownHintFamily( void ) void test_FreeRTOS_getaddrinfo_a_IPv4AddressFound( void ) { BaseType_t xReturn; - struct freertos_addrinfo xAddress, * pxAddress = &xAddress; + struct freertos_addrinfo * pxAddress; struct freertos_addrinfo xHint, * pxHint = &xHint; - memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); xHint.ai_family = FREERTOS_AF_INET4; @@ -794,6 +793,8 @@ void test_FreeRTOS_getaddrinfo_a_IPv4AddressFound( void ) TEST_ASSERT_EQUAL( FREERTOS_AF_INET4, pxAddress->ai_family ); TEST_ASSERT_EQUAL( DOTTED_IPV4_ADDRESS_UINT32, FreeRTOS_htonl( pxAddress->ai_addr->sin_address.ulIP_IPv4 ) ); TEST_ASSERT_EQUAL( ipSIZE_OF_IPv4_ADDRESS, pxAddress->ai_addrlen ); + + vPortFree( pxAddress ); /* Make LeakSanitizer happy. */ } /** @@ -802,10 +803,9 @@ void test_FreeRTOS_getaddrinfo_a_IPv4AddressFound( void ) void test_FreeRTOS_getaddrinfo_a_IPv6AddressFound( void ) { BaseType_t xReturn; - struct freertos_addrinfo xAddress, * pxAddress = &xAddress; + struct freertos_addrinfo * pxAddress; struct freertos_addrinfo xHint, * pxHint = &xHint; - memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); xHint.ai_family = FREERTOS_AF_INET6; @@ -821,6 +821,8 @@ void test_FreeRTOS_getaddrinfo_a_IPv6AddressFound( void ) TEST_ASSERT_EQUAL( FREERTOS_AF_INET6, pxAddress->ai_family ); TEST_ASSERT_EQUAL_MEMORY( xIPv6Address.ucBytes, pxAddress->ai_addr->sin_address.xIP_IPv6.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); TEST_ASSERT_EQUAL( ipSIZE_OF_IPv6_ADDRESS, pxAddress->ai_addrlen ); + + vPortFree( pxAddress ); /* Make LeakSanitizer happy. */ } /** @@ -829,17 +831,16 @@ void test_FreeRTOS_getaddrinfo_a_IPv6AddressFound( void ) void test_FreeRTOS_getaddrinfo_a_IPv4DomainCacheFound( void ) { BaseType_t xReturn; - struct freertos_addrinfo xAddress, * pxAddress = &xAddress; + struct freertos_addrinfo * pxAddress; struct freertos_addrinfo xExpectedAddress, * pxExpectedAddress = &xExpectedAddress; - memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xExpectedAddress, 0, sizeof( struct freertos_addrinfo ) ); xExpectedAddress.ai_family = FREERTOS_AF_INET4; FreeRTOS_inet_addr_ExpectAndReturn( GOOD_ADDRESS, 0 ); Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET4, &pxAddress, DOTTED_IPV4_ADDRESS_UINT32 ); - Prepare_CacheLookup_ReturnMemThruPtr_ppxAddressInfo( &pxExpectedAddress, sizeof( struct freertos_addrinfo ) ); + Prepare_CacheLookup_ReturnMemThruPtr_ppxAddressInfo( &pxExpectedAddress, sizeof( struct freertos_addrinfo * ) ); xReturn = FreeRTOS_getaddrinfo_a( GOOD_ADDRESS, "Service", NULL, &pxAddress, dns_callback, NULL, 0U ); diff --git a/test/unit-test/FreeRTOS_DNS/ut.cmake b/test/unit-test/FreeRTOS_DNS/ut.cmake index f9d25a146d..4e0db6bffd 100644 --- a/test/unit-test/FreeRTOS_DNS/ut.cmake +++ b/test/unit-test/FreeRTOS_DNS/ut.cmake @@ -42,7 +42,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "") list(APPEND real_source_files diff --git a/test/unit-test/FreeRTOS_DNS_Cache/FreeRTOS_DNS_Cache_utest.c b/test/unit-test/FreeRTOS_DNS_Cache/FreeRTOS_DNS_Cache_utest.c index 1994b128d9..89c9aeb4f4 100644 --- a/test/unit-test/FreeRTOS_DNS_Cache/FreeRTOS_DNS_Cache_utest.c +++ b/test/unit-test/FreeRTOS_DNS_Cache/FreeRTOS_DNS_Cache_utest.c @@ -495,15 +495,12 @@ void test_prepare_DNSLookup( void ) void test_prepare_DNSLookup2( void ) { - BaseType_t x = 0U; - BaseType_t xFamily; + BaseType_t x; struct freertos_addrinfo * pxAddressInfo = NULL; - struct freertos_addrinfo ** ppxAddressInfo; IPv46_Address_t xAddress; - xFamily = FREERTOS_AF_INET; xAddress.xIs_IPv6 = pdFALSE; - ppxAddressInfo = &pxAddressInfo; + xAddress.xIPAddress.ulIP_IPv4 = ~0U; xTaskGetTickCount_ExpectAndReturn( 3000 ); /* 3 seconds */ FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); @@ -516,7 +513,7 @@ void test_prepare_DNSLookup2( void ) pxNew_AddrInfo_ExpectAnyArgsAndReturn( NULL ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); - x = Prepare_CacheLookup( "helloman", xFamily, ppxAddressInfo ); + x = Prepare_CacheLookup( "helloman", FREERTOS_AF_INET, &pxAddressInfo ); TEST_ASSERT_EQUAL( 0, x ); } @@ -525,13 +522,11 @@ void test_prepare_DNSLookup2( void ) */ void test_prepare_DNSLookup3( void ) { - BaseType_t x = 0U; - BaseType_t xFamily; - struct freertos_addrinfo ** ppxAddressInfo = NULL; + BaseType_t x; IPv46_Address_t xAddress; - xFamily = FREERTOS_AF_INET; xAddress.xIs_IPv6 = pdFALSE; + xAddress.xIPAddress.ulIP_IPv4 = ~0U; xTaskGetTickCount_ExpectAndReturn( 3000 ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); @@ -543,7 +538,7 @@ void test_prepare_DNSLookup3( void ) xTaskGetTickCount_ExpectAndReturn( 5000 ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); - x = Prepare_CacheLookup( "helloman", xFamily, ppxAddressInfo ); + x = Prepare_CacheLookup( "helloman", FREERTOS_AF_INET, NULL ); TEST_ASSERT_EQUAL( 0, x ); } @@ -552,13 +547,11 @@ void test_prepare_DNSLookup3( void ) */ void test_prepare_DNSLookup4( void ) { - BaseType_t x = 0U; - BaseType_t xFamily; - struct freertos_addrinfo ** ppxAddressInfo = NULL; + BaseType_t x; IPv46_Address_t xAddress; - xFamily = FREERTOS_AF_INET; xAddress.xIs_IPv6 = pdFALSE; + xAddress.xIPAddress.ulIP_IPv4 = ~0U; xTaskGetTickCount_ExpectAndReturn( 3000 ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); @@ -570,7 +563,7 @@ void test_prepare_DNSLookup4( void ) xTaskGetTickCount_ExpectAndReturn( 5000 ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); - x = Prepare_CacheLookup( "hello", xFamily, ppxAddressInfo ); + x = Prepare_CacheLookup( "hello", FREERTOS_AF_INET, NULL ); TEST_ASSERT_EQUAL( 0, x ); } @@ -629,14 +622,14 @@ void test_prepare_DNSLookup6( void ) */ void test_prepare_DNSLookup_IPv6( void ) { - BaseType_t x = 0U; - BaseType_t xFamily; + BaseType_t x; + BaseType_t xFamily = FREERTOS_AF_INET6; struct freertos_addrinfo * pxAddressInfo = &pucAddrBuffer[ 0 ]; - struct freertos_addrinfo ** ppxAddressInfo = ( struct freertos_addrinfo ** ) &pucAddrBuffer; + struct freertos_addrinfo ** ppxAddressInfo = ( struct freertos_addrinfo ** ) &pxAddressInfo; IPv46_Address_t xAddress; - xFamily = FREERTOS_AF_INET6; xAddress.xIs_IPv6 = pdTRUE; + memcpy( xAddress.xIPAddress.xIP_IPv6.ucBytes, "great ip address", 16 ); *ppxAddressInfo = pxAddressInfo; @@ -680,6 +673,7 @@ void test_prepare_DNSLookup2_IPv6( void ) xFamily = FREERTOS_AF_INET6; xAddress.xIs_IPv6 = pdTRUE; + memcpy( xAddress.xIPAddress.xIP_IPv6.ucBytes, "great ip address", 16 ); ppxAddressInfo = &pxAddressInfo; xTaskGetTickCount_ExpectAndReturn( 3000 ); /* 3 seconds */ @@ -709,6 +703,7 @@ void test_prepare_DNSLookup3_IPv6( void ) xFamily = FREERTOS_AF_INET6; xAddress.xIs_IPv6 = pdTRUE; + memcpy( xAddress.xIPAddress.xIP_IPv6.ucBytes, "great ip address", 16 ); xTaskGetTickCount_ExpectAndReturn( 3000 ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); @@ -737,6 +732,7 @@ void test_prepare_DNSLookup4_IPv6( void ) xFamily = FREERTOS_AF_INET6; xAddress.xIs_IPv6 = pdTRUE; + memcpy( xAddress.xIPAddress.xIP_IPv6.ucBytes, "great ip address", 16 ); xTaskGetTickCount_ExpectAndReturn( 3000 ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( NULL ); diff --git a/test/unit-test/FreeRTOS_DNS_Cache/ut.cmake b/test/unit-test/FreeRTOS_DNS_Cache/ut.cmake index 6c20e12103..b9c5e9e619 100755 --- a/test/unit-test/FreeRTOS_DNS_Cache/ut.cmake +++ b/test/unit-test/FreeRTOS_DNS_Cache/ut.cmake @@ -39,7 +39,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "" ) diff --git a/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c b/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c index 816a19944b..3a03807845 100644 --- a/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c +++ b/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c @@ -65,6 +65,10 @@ typedef void (* FOnDNSEvent ) ( const char * /* pcName */, /* =========================== GLOBAL VARIABLES =========================== */ static int callback_called = 0; +/* The second element is for the flexible array member + * /* when pvPortMalloc is mocked to return this object. + */ +static DNSCallback_t dnsCallback[ 2 ]; /* =========================== STATIC FUNCTIONS =========================== */ static void dns_callback( const char * pcName, @@ -74,8 +78,6 @@ static void dns_callback( const char * pcName, callback_called = 1; } - -static DNSCallback_t dnsCallback; /* ============================ TEST FIXTURES ============================= */ /** @@ -86,7 +88,7 @@ void setUp( void ) vListInitialise_ExpectAnyArgs(); vDNSCallbackInitialise(); callback_called = 0; - memset( &dnsCallback, 0x00, sizeof( DNSCallback_t ) ); + memset( dnsCallback, 0x00, sizeof( dnsCallback ) ); } /** @@ -142,14 +144,14 @@ void test_xDNSDoCallback_success_equal_identifier( void ) char pc_name[] = "test"; strcpy( pxSet.pcName, pc_name ); - dnsCallback.pCallbackFunction = dns_callback; + dnsCallback->pCallbackFunction = dns_callback; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 4 ); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_LIST_ITEM_VALUE_ExpectAnyArgsAndReturn( 123 ); uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); vPortFree_ExpectAnyArgs(); @@ -176,14 +178,14 @@ void test_xDNSDoCallback_success_equal_identifier_set_timer( void ) pxSet.pxDNSMessageHeader->usIdentifier = 123; char pc_name[] = "test"; strcpy( pxSet.pcName, pc_name ); - dnsCallback.pCallbackFunction = dns_callback; + dnsCallback->pCallbackFunction = dns_callback; /* Expectations */ listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 4 ); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_LIST_ITEM_VALUE_ExpectAnyArgsAndReturn( 123 ); uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); vPortFree_ExpectAnyArgs(); @@ -208,7 +210,7 @@ void test_vDNSSetCallback_success( void ) void * pvSearchID = NULL; /* Expectations */ - pvPortMalloc_ExpectAnyArgsAndReturn( &dnsCallback ); + pvPortMalloc_ExpectAnyArgsAndReturn( dnsCallback ); listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdFALSE ); vTaskSetTimeOutState_ExpectAnyArgs(); listSET_LIST_ITEM_OWNER_ExpectAnyArgs(); @@ -221,10 +223,10 @@ void test_vDNSSetCallback_success( void ) vDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE ); /* Validations */ - TEST_ASSERT_EQUAL( 0, strcmp( dnsCallback.pcName, "hostname" ) ); - TEST_ASSERT_EQUAL( dns_callback, dnsCallback.pCallbackFunction ); - TEST_ASSERT_EQUAL( pvSearchID, dnsCallback.pvSearchID ); - TEST_ASSERT_EQUAL( 56, dnsCallback.uxRemainingTime ); + TEST_ASSERT_EQUAL( 0, strcmp( dnsCallback->pcName, "hostname" ) ); + TEST_ASSERT_EQUAL( dns_callback, dnsCallback->pCallbackFunction ); + TEST_ASSERT_EQUAL( pvSearchID, dnsCallback->pvSearchID ); + TEST_ASSERT_EQUAL( 56, dnsCallback->uxRemainingTime ); } /** @@ -235,7 +237,7 @@ void test_vDNSSetCallback_success_empty_list( void ) void * pvSearchID = NULL; /* Expectations */ - pvPortMalloc_ExpectAnyArgsAndReturn( &dnsCallback ); + pvPortMalloc_ExpectAnyArgsAndReturn( dnsCallback ); listLIST_IS_EMPTY_ExpectAnyArgsAndReturn( pdTRUE ); FreeRTOS_min_uint32_ExpectAnyArgsAndReturn( 0 ); vDNSTimerReload_ExpectAnyArgs(); @@ -250,10 +252,10 @@ void test_vDNSSetCallback_success_empty_list( void ) vDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE ); /* Validations */ - TEST_ASSERT_EQUAL( 0, strcmp( dnsCallback.pcName, "hostname" ) ); - TEST_ASSERT_EQUAL( dns_callback, dnsCallback.pCallbackFunction ); - TEST_ASSERT_EQUAL( pvSearchID, dnsCallback.pvSearchID ); - TEST_ASSERT_EQUAL( 56, dnsCallback.uxRemainingTime ); + TEST_ASSERT_EQUAL( 0, strcmp( dnsCallback->pcName, "hostname" ) ); + TEST_ASSERT_EQUAL( dns_callback, dnsCallback->pCallbackFunction ); + TEST_ASSERT_EQUAL( pvSearchID, dnsCallback->pvSearchID ); + TEST_ASSERT_EQUAL( 56, dnsCallback->uxRemainingTime ); } /** @@ -278,13 +280,13 @@ void test_vDNSCheckCallback_success_search_id_not_null( void ) { void * pvSearchID = ( void * ) 456; - dnsCallback.pvSearchID = pvSearchID; + dnsCallback->pvSearchID = pvSearchID; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ uxListRemove_ExpectAnyArgsAndReturn( pdFALSE ); vPortFree_ExpectAnyArgs(); @@ -306,13 +308,13 @@ void test_vDNSCheckCallback_success_search_id_not_null_list_empty( void ) { void * pvSearchID = ( void * ) 456; - dnsCallback.pvSearchID = pvSearchID; + dnsCallback->pvSearchID = pvSearchID; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ uxListRemove_ExpectAnyArgsAndReturn( pdFALSE ); vPortFree_ExpectAnyArgs(); @@ -333,13 +335,13 @@ void test_vDNSCheckCallback_success_search_id_null( void ) { void * pvSearchID = ( void * ) 456; - dnsCallback.pvSearchID = pvSearchID; + dnsCallback->pvSearchID = pvSearchID; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdFALSE ); @@ -363,15 +365,15 @@ void test_vDNSCheckCallback_success_search_id_null_timeout( void ) List_t xTempList; void * pvSearchID = ( void * ) 456; - dnsCallback.pvSearchID = pvSearchID; - dnsCallback.xIsIPv6 = 0; - dnsCallback.pCallbackFunction = dns_callback; + dnsCallback->pvSearchID = pvSearchID; + dnsCallback->xIsIPv6 = 0; + dnsCallback->pCallbackFunction = dns_callback; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdTRUE ); @@ -383,7 +385,7 @@ void test_vDNSCheckCallback_success_search_id_null_timeout( void ) listGET_END_MARKER_ExpectAnyArgsAndReturn( NULL ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( NULL ); /* end marker */ uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); vPortFree_ExpectAnyArgs(); @@ -407,15 +409,15 @@ void test_vDNSCheckCallback_success_search_id_null_timeout_IPv6( void ) List_t xTempList; void * pvSearchID = ( void * ) 456; - dnsCallback.pvSearchID = pvSearchID; - dnsCallback.xIsIPv6 = 1; - dnsCallback.pCallbackFunction = dns_callback; + dnsCallback->pvSearchID = pvSearchID; + dnsCallback->xIsIPv6 = 1; + dnsCallback->pCallbackFunction = dns_callback; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdTRUE ); @@ -427,7 +429,7 @@ void test_vDNSCheckCallback_success_search_id_null_timeout_IPv6( void ) listGET_END_MARKER_ExpectAnyArgsAndReturn( NULL ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( NULL ); /* end marker */ uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); vPortFree_ExpectAnyArgs(); @@ -451,15 +453,15 @@ void test_vDNSCheckCallback_success_search_id_null_timeout2( void ) void * pvSearchID = ( void * ) 456; void * pvSearchID2 = ( void * ) 457; - dnsCallback.pvSearchID = pvSearchID2; - dnsCallback.xIsIPv6 = 0; - dnsCallback.pCallbackFunction = dns_callback; + dnsCallback->pvSearchID = pvSearchID2; + dnsCallback->xIsIPv6 = 0; + dnsCallback->pCallbackFunction = dns_callback; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdTRUE ); @@ -471,7 +473,7 @@ void test_vDNSCheckCallback_success_search_id_null_timeout2( void ) listGET_END_MARKER_ExpectAnyArgsAndReturn( NULL ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( NULL ); /* end marker */ uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); vPortFree_ExpectAnyArgs(); @@ -495,15 +497,15 @@ void test_vDNSCheckCallback_success_search_id_null_timeout2_IPv6( void ) void * pvSearchID = ( void * ) 456; void * pvSearchID2 = ( void * ) 457; - dnsCallback.pvSearchID = pvSearchID2; - dnsCallback.xIsIPv6 = 1; - dnsCallback.pCallbackFunction = dns_callback; + dnsCallback->pvSearchID = pvSearchID2; + dnsCallback->xIsIPv6 = 1; + dnsCallback->pCallbackFunction = dns_callback; listGET_END_MARKER_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); vListInitialise_ExpectAnyArgs(); vTaskSuspendAll_Expect(); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 8 ); /* end marker */ xTaskCheckForTimeOut_ExpectAnyArgsAndReturn( pdTRUE ); @@ -515,7 +517,7 @@ void test_vDNSCheckCallback_success_search_id_null_timeout2_IPv6( void ) listGET_END_MARKER_ExpectAnyArgsAndReturn( NULL ); listGET_NEXT_ExpectAnyArgsAndReturn( ( ListItem_t * ) 16 ); - listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( &dnsCallback ); + listGET_LIST_ITEM_OWNER_ExpectAnyArgsAndReturn( dnsCallback ); listGET_NEXT_ExpectAnyArgsAndReturn( NULL ); /* end marker */ uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); vPortFree_ExpectAnyArgs(); diff --git a/test/unit-test/FreeRTOS_DNS_Callback/ut.cmake b/test/unit-test/FreeRTOS_DNS_Callback/ut.cmake index e1962eaaa3..6d0688f6e7 100644 --- a/test/unit-test/FreeRTOS_DNS_Callback/ut.cmake +++ b/test/unit-test/FreeRTOS_DNS_Callback/ut.cmake @@ -41,7 +41,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "") list(APPEND real_source_files diff --git a/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/FreeRTOS_DNS_ConfigNoCallback_utest.c b/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/FreeRTOS_DNS_ConfigNoCallback_utest.c index 74ed71c802..b00f4970ec 100644 --- a/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/FreeRTOS_DNS_ConfigNoCallback_utest.c +++ b/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/FreeRTOS_DNS_ConfigNoCallback_utest.c @@ -90,10 +90,9 @@ void setUp( void ) void test_FreeRTOS_getaddrinfo_IPv4AddressFound( void ) { BaseType_t xReturn; - struct freertos_addrinfo xAddress, * pxAddress = &xAddress; + struct freertos_addrinfo * pxAddress; struct freertos_addrinfo xHint, * pxHint = &xHint; - memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); xHint.ai_family = FREERTOS_AF_INET4; @@ -107,6 +106,8 @@ void test_FreeRTOS_getaddrinfo_IPv4AddressFound( void ) TEST_ASSERT_EQUAL( FREERTOS_AF_INET4, pxAddress->ai_family ); TEST_ASSERT_EQUAL( DOTTED_IPV4_ADDRESS_UINT32, FreeRTOS_htonl( pxAddress->ai_addr->sin_address.ulIP_IPv4 ) ); TEST_ASSERT_EQUAL( ipSIZE_OF_IPv4_ADDRESS, pxAddress->ai_addrlen ); + + vPortFree( pxAddress ); /* Make LeakSanitizer happy. */ } /** diff --git a/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/ut.cmake b/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/ut.cmake index 9e63fd66e7..6146679ff6 100644 --- a/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/ut.cmake +++ b/test/unit-test/FreeRTOS_DNS_ConfigNoCallback/ut.cmake @@ -41,7 +41,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "") list(APPEND real_source_files diff --git a/test/unit-test/FreeRTOS_DNS_Networking/FreeRTOS_DNS_Networking_utest.c b/test/unit-test/FreeRTOS_DNS_Networking/FreeRTOS_DNS_Networking_utest.c index 8419e537fe..f109cd6629 100644 --- a/test/unit-test/FreeRTOS_DNS_Networking/FreeRTOS_DNS_Networking_utest.c +++ b/test/unit-test/FreeRTOS_DNS_Networking/FreeRTOS_DNS_Networking_utest.c @@ -195,7 +195,8 @@ void test_SendRequest_fail( void ) struct freertos_sockaddr xAddress; struct xDNSBuffer pxDNSBuf; - FreeRTOS_sendto_ExpectAnyArgsAndReturn( pdFALSE ); + pxDNSBuf.uxPayloadLength = 1024; + FreeRTOS_sendto_ExpectAnyArgsAndReturn( 1023 ); ret = DNS_SendRequest( s, &xAddress, &pxDNSBuf ); diff --git a/test/unit-test/FreeRTOS_DNS_Networking/ut.cmake b/test/unit-test/FreeRTOS_DNS_Networking/ut.cmake index 36328c3386..083ffaf027 100644 --- a/test/unit-test/FreeRTOS_DNS_Networking/ut.cmake +++ b/test/unit-test/FreeRTOS_DNS_Networking/ut.cmake @@ -35,7 +35,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "" ) diff --git a/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c b/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c index e31fb23fb6..61d2babcae 100644 --- a/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c +++ b/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c @@ -57,6 +57,10 @@ #define BAD_ADDRESS "this is a bad address" #define DOTTED_ADDRESS "192.268.0.1" +#define prvROUND_UP_TO( SIZE, ALIGNMENT ) ( ( ( SIZE ) + ( ALIGNMENT ) -1 ) / ( ALIGNMENT ) *( ALIGNMENT ) ) + +#define prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 prvROUND_UP_TO( ipUDP_PAYLOAD_OFFSET_IPv4, sizeof( void * ) ) + typedef void (* FOnDNSEvent ) ( const char * /* pcName */, void * /* pvSearchID */, struct freertos_addrinfo * /* pxAddressInfo */ ); @@ -1629,8 +1633,8 @@ void test_DNS_ParseDNSReply_InvalidEndpointIP( void ) void test_DNS_ParseDNSReply_InvalidEndpointType( void ) { uint32_t ret; - uint8_t udp_buffer[ 250 + ipUDP_PAYLOAD_OFFSET_IPv4 ] = { 0 }; - uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4; + uint8_t udp_buffer[ prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 + 250 ] = { 0 }; + uint8_t * pucUDPPayloadBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4; size_t uxBufferLength = 250; struct freertos_addrinfo * pxAddressInfo; uint16_t usPort; @@ -1642,11 +1646,11 @@ void test_DNS_ParseDNSReply_InvalidEndpointType( void ) memset( pucUDPPayloadBuffer, 0x00, uxBufferLength ); NetworkBufferDescriptor_t pxNetworkBuffer = { 0 }; - pxNetworkBuffer.pucEthernetBuffer = udp_buffer; + pxNetworkBuffer.pucEthernetBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 - ipUDP_PAYLOAD_OFFSET_IPv4; pxNetworkBuffer.xDataLength = uxBufferLength; NetworkBufferDescriptor_t pxNewBuffer; - pxNewBuffer.pucEthernetBuffer = udp_buffer; + pxNewBuffer.pucEthernetBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 - ipUDP_PAYLOAD_OFFSET_IPv4; pxNewBuffer.xDataLength = uxBufferLength; pxNetworkBuffer.pxEndPoint = &xEndPoint; xEndPoint.bits.bIPv6 = pdTRUE; @@ -1768,8 +1772,8 @@ void test_DNS_ParseDNSReply_answer_record_too_many_answers( void ) void test_DNS_ParseDNSReply_answer_lmmnr_reply_xBufferAllocFixedsize( void ) { uint32_t ret; - uint8_t udp_buffer[ 250 + ipUDP_PAYLOAD_OFFSET_IPv4 ] = { 0 }; - uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4; + uint8_t udp_buffer[ prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 + 250 ] = { 0 }; + uint8_t * pucUDPPayloadBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4; size_t uxBufferLength = 250; struct freertos_addrinfo * pxAddressInfo; uint16_t usPort; @@ -1781,11 +1785,11 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply_xBufferAllocFixedsize( void ) memset( pucUDPPayloadBuffer, 0x00, uxBufferLength ); NetworkBufferDescriptor_t pxNetworkBuffer = { 0 }; - pxNetworkBuffer.pucEthernetBuffer = udp_buffer; + pxNetworkBuffer.pucEthernetBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 - ipUDP_PAYLOAD_OFFSET_IPv4; pxNetworkBuffer.xDataLength = uxBufferLength; NetworkBufferDescriptor_t pxNewBuffer; - pxNewBuffer.pucEthernetBuffer = udp_buffer; + pxNewBuffer.pucEthernetBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 - ipUDP_PAYLOAD_OFFSET_IPv4; pxNewBuffer.xDataLength = uxBufferLength; char dns[ 64 ]; @@ -1846,8 +1850,8 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply_xBufferAllocFixedsize( void ) void test_DNS_ParseDNSReply_answer_lmmnr_reply( void ) { uint32_t ret; - uint8_t udp_buffer[ 250 + ipUDP_PAYLOAD_OFFSET_IPv4 ] = { 0 }; - uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4; + uint8_t udp_buffer[ prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 + 250 ] = { 0 }; + uint8_t * pucUDPPayloadBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4; size_t uxBufferLength = 250; struct freertos_addrinfo * pxAddressInfo; uint16_t usPort; @@ -1856,7 +1860,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply( void ) memset( pucUDPPayloadBuffer, 0x00, uxBufferLength ); NetworkBufferDescriptor_t pxNetworkBuffer = { 0 }; - pxNetworkBuffer.pucEthernetBuffer = udp_buffer; + pxNetworkBuffer.pucEthernetBuffer = udp_buffer + prvALIGNED_UDP_PAYLOAD_OFFSET_IPv4 - ipUDP_PAYLOAD_OFFSET_IPv4; pxNetworkBuffer.xDataLength = uxBufferLength; char dns[ 64 ]; @@ -1991,7 +1995,7 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply2( void ) */ void test_DNS_ParseDNSReply_answer_lmmnr_reply3( void ) { - uint32_t ret; + uint32_t ret = 0xDEADC0DE; uint8_t udp_buffer[ 250 + ipUDP_PAYLOAD_OFFSET_IPv4 ] = { 0 }; uint8_t * pucUDPPayloadBuffer = ( ( uint8_t * ) udp_buffer ) + ipUDP_PAYLOAD_OFFSET_IPv4 - 1; size_t uxBufferLength = 250; @@ -2054,7 +2058,8 @@ void test_DNS_ParseDNSReply_answer_lmmnr_reply3( void ) xExpected, usPort ) ); - TEST_ASSERT_EQUAL( pdFALSE, ret ); + /* ret is not reassigned, because the function asserts. */ + TEST_ASSERT_EQUAL( 0xDEADC0DE, ret ); ASSERT_DNS_QUERY_HOOK_NOT_CALLED(); } @@ -2938,6 +2943,7 @@ void test_parseDNSAnswer_recordstored_gt_count( void ) char pcName[ 300 ]; DNSAnswerRecord_t * pxDNSAnswerRecord; IPv46_Address_t ip_address; + const uint32_t ulTestAddress = 0xABCD1234; ip_address.xIPAddress.ulIP_IPv4 = 1234; ip_address.xIs_IPv6 = pdFALSE; @@ -2962,8 +2968,7 @@ void test_parseDNSAnswer_recordstored_gt_count( void ) pxDNSAnswerRecord->usDataLength = FreeRTOS_htons( ipSIZE_OF_IPv4_ADDRESS ); pxDNSAnswerRecord->usType = ( dnsTYPE_A_HOST ); - uint32_t * pulTestAddress = ( uint32_t * ) ( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ) ); - *pulTestAddress = 0xABCD1234; + memcpy( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ), &ulTestAddress, sizeof( ulTestAddress ) ); usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_A_HOST ); /* usType */ pxNew_AddrInfo_ExpectAnyArgsAndReturn( pxAddressInfo ); @@ -3178,7 +3183,7 @@ void test_parseDNSAnswer_recordstored_gt_count_IPv6_success( void ) memset( &( ip_address.xIPAddress.xIP_IPv6 ), 1, ipSIZE_OF_IPv6_ADDRESS ); ip_address.xIs_IPv6 = pdTRUE; ParseSet_t xSet = { 0 }; - struct freertos_addrinfo * pxAddressInfo, * pxAddressInfo_2; + struct freertos_addrinfo xAddressInfo = { 0 }, * pxAddressInfo, * pxAddressInfo_2; xSet.pxDNSMessageHeader = &pxDNSMessageHeader; xSet.pucByte = pucByte; @@ -3200,7 +3205,7 @@ void test_parseDNSAnswer_recordstored_gt_count_IPv6_success( void ) pxDNSAnswerRecord->usType = ( dnsTYPE_AAAA_HOST ); usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_AAAA_HOST ); /* usType */ - pxNew_AddrInfo_ExpectAnyArgsAndReturn( pxAddressInfo ); + pxNew_AddrInfo_ExpectAnyArgsAndReturn( &xAddressInfo ); xDNSDoCallback_ExpectAnyArgsAndReturn( pdTRUE ); FreeRTOS_dns_update_ExpectAnyArgsAndReturn( pdTRUE ); FreeRTOS_dns_update_ReturnThruPtr_pxIP( &ip_address ); @@ -3329,6 +3334,7 @@ void test_parseDNSAnswer_recordstored_gt_count_IPv6_fail_nullLinkedListForDNSAns char pcName[ 300 ]; DNSAnswerRecord_t * pxDNSAnswerRecord; IPv46_Address_t ip_address; + const uint32_t ulTestAddress = 0xABCD1234; memset( &( ip_address.xIPAddress.xIP_IPv6 ), 1, ipSIZE_OF_IPv6_ADDRESS ); ip_address.xIs_IPv6 = pdTRUE; @@ -3354,8 +3360,7 @@ void test_parseDNSAnswer_recordstored_gt_count_IPv6_fail_nullLinkedListForDNSAns pxDNSAnswerRecord->usDataLength = FreeRTOS_htons( ipSIZE_OF_IPv4_ADDRESS ); pxDNSAnswerRecord->usType = ( dnsTYPE_A_HOST ); - uint32_t * pulTestAddress = ( uint32_t * ) ( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ) ); - *pulTestAddress = 0xABCD1234; + memcpy( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ), &ulTestAddress, sizeof( ulTestAddress ) ); usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_A_HOST ); /* usType */ xDNSDoCallback_ExpectAnyArgsAndReturn( pdTRUE ); @@ -3466,11 +3471,12 @@ void test_parseDNSAnswer_dns_nocallback_false( void ) BaseType_t xDoStore = pdTRUE; DNSAnswerRecord_t * pxDNSAnswerRecord; IPv46_Address_t ip_address; + const uint32_t ulTestAddress = 0xABCD1234; ip_address.xIPAddress.ulIP_IPv4 = 5678; ip_address.xIs_IPv6 = pdFALSE; ParseSet_t xSet = { 0 }; - struct freertos_addrinfo * pxAddressInfo; + struct freertos_addrinfo xAddressInfo = { 0 }; struct freertos_addrinfo ** ppxAddressInfo = ( struct freertos_addrinfo ** ) &pucAddrBuffer; *ppxAddressInfo = NULL; @@ -3485,8 +3491,7 @@ void test_parseDNSAnswer_dns_nocallback_false( void ) pxDNSAnswerRecord->usDataLength = FreeRTOS_htons( ipSIZE_OF_IPv4_ADDRESS ); pxDNSAnswerRecord->usType = ( dnsTYPE_A_HOST ); - uint32_t * pulTestAddress = ( uint32_t * ) ( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ) ); - *pulTestAddress = 0xABCD1234; + memcpy( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ), &ulTestAddress, sizeof( ulTestAddress ) ); xSet.pucByte = pucByte; xSet.usNumARecordsStored = 0; @@ -3497,7 +3502,7 @@ void test_parseDNSAnswer_dns_nocallback_false( void ) xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY + 1; usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_A_HOST ); /* usType */ - pxNew_AddrInfo_ExpectAnyArgsAndReturn( pxAddressInfo ); + pxNew_AddrInfo_ExpectAnyArgsAndReturn( &xAddressInfo ); xDNSDoCallback_ExpectAnyArgsAndReturn( pdFALSE ); FreeRTOS_dns_update_ExpectAnyArgsAndReturn( pdTRUE ); FreeRTOS_dns_update_ReturnThruPtr_pxIP( &ip_address ); @@ -3526,6 +3531,7 @@ void test_parseDNSAnswer_do_store_false( void ) ParseSet_t xSet = { 0 }; struct freertos_addrinfo * pxAddressInfo; struct freertos_addrinfo ** ppxAddressInfo = ( struct freertos_addrinfo ** ) &pucAddrBuffer; + const uint32_t ulTestAddress = 0xABCD1234; memset( pucByte, 0x00, 300 ); memset( pcName, 0x00, 300 ); @@ -3544,7 +3550,7 @@ void test_parseDNSAnswer_do_store_false( void ) xSet.usAnswers = ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY + 1; usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_A_HOST ); /* usType */ - pxNew_AddrInfo_ExpectAnyArgsAndReturn( pxAddressInfo ); + pxNew_AddrInfo_ExpectAnyArgsAndReturn( NULL ); xDNSDoCallback_ExpectAnyArgsAndReturn( pdFALSE ); FreeRTOS_inet_ntop_ExpectAnyArgsAndReturn( "ignored" ); @@ -3552,8 +3558,7 @@ void test_parseDNSAnswer_do_store_false( void ) pxDNSAnswerRecord->usDataLength = FreeRTOS_htons( ipSIZE_OF_IPv4_ADDRESS ); pxDNSAnswerRecord->usType = ( dnsTYPE_A_HOST ); - uint32_t * pulTestAddress = ( uint32_t * ) ( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ) ); - *pulTestAddress = 0xABCD1234; + memcpy( ( ( uint8_t * ) pxDNSAnswerRecord ) + sizeof( DNSAnswerRecord_t ), &ulTestAddress, sizeof( ulTestAddress ) ); ret = parseDNSAnswer( &xSet, &pxAddressInfo, &uxBytesRead ); diff --git a/test/unit-test/FreeRTOS_DNS_Parser/ut.cmake b/test/unit-test/FreeRTOS_DNS_Parser/ut.cmake index d8520accda..5356fb1be4 100755 --- a/test/unit-test/FreeRTOS_DNS_Parser/ut.cmake +++ b/test/unit-test/FreeRTOS_DNS_Parser/ut.cmake @@ -36,7 +36,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "" ) diff --git a/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c b/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c index d7c5af405b..2bc281d810 100644 --- a/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c +++ b/test/unit-test/FreeRTOS_IP/FreeRTOS_IP_utest.c @@ -267,7 +267,7 @@ void test_FreeRTOS_GetUDPPayloadBuffer_BlockTimeEqualToConfig( void ) uint8_t pucEthernetBuffer[ 1500 ]; /* Put the ethernet buffer in place. */ - pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer; + pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = 0; pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( UDPPacket_t ) + uxRequestedSizeBytes, uxBlockTimeTicks, pxNetworkBuffer ); @@ -291,7 +291,7 @@ void test_FreeRTOS_GetUDPPayloadBuffer_BlockTimeLessThanConfig( void ) uint8_t pucEthernetBuffer[ 1500 ]; /* Put the ethernet buffer in place. */ - pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer; + pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = 0; pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( UDPPacket_t ) + uxRequestedSizeBytes, uxBlockTimeTicks, pxNetworkBuffer ); @@ -316,7 +316,7 @@ void test_FreeRTOS_GetUDPPayloadBuffer_BlockTimeMoreThanConfig( void ) uint8_t pucEthernetBuffer[ 1500 ]; /* Put the ethernet buffer in place. */ - pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer; + pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = 0; pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( UDPPacket_t ) + uxRequestedSizeBytes, ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS, pxNetworkBuffer ); @@ -1989,10 +1989,12 @@ void test_prvProcessEthernetPacket_ARPFrameType_eFrameConsumed( void ) uint8_t ucEtherBuffer[ ipconfigTCP_MSS ]; EthernetHeader_t * pxEthernetHeader; struct xNetworkInterface xInterface; + NetworkEndPoint_t xNetworkEndPoint = { 0 }; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pucEthernetBuffer = ucEtherBuffer; pxNetworkBuffer->pxInterface = &xInterface; + pxNetworkBuffer->pxEndPoint = &xNetworkEndPoint; pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer; @@ -2017,10 +2019,12 @@ void test_prvProcessEthernetPacket_ARPFrameType_SmallerDataLength( void ) uint8_t ucEtherBuffer[ ipconfigTCP_MSS ]; EthernetHeader_t * pxEthernetHeader; struct xNetworkInterface xInterface; + NetworkEndPoint_t xNetworkEndPoint = { 0 }; pxNetworkBuffer->xDataLength = sizeof( EthernetHeader_t ); pxNetworkBuffer->pucEthernetBuffer = ucEtherBuffer; pxNetworkBuffer->pxInterface = &xInterface; + pxNetworkBuffer->pxEndPoint = &xNetworkEndPoint; pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer; @@ -2045,10 +2049,12 @@ void test_prvProcessEthernetPacket_IPv4FrameType_LessData( void ) uint8_t ucEtherBuffer[ ipconfigTCP_MSS ]; EthernetHeader_t * pxEthernetHeader; struct xNetworkInterface xInterface; + NetworkEndPoint_t xNetworkEndPoint = { 0 }; pxNetworkBuffer->xDataLength = sizeof( EthernetHeader_t ); pxNetworkBuffer->pucEthernetBuffer = ucEtherBuffer; pxNetworkBuffer->pxInterface = &xInterface; + pxNetworkBuffer->pxEndPoint = &xNetworkEndPoint; pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer; @@ -2070,17 +2076,17 @@ void test_prvProcessEthernetPacket_IPv4FrameType_AptData( void ) { NetworkBufferDescriptor_t xNetworkBuffer; NetworkBufferDescriptor_t * pxNetworkBuffer = &xNetworkBuffer; - uint8_t ucEtherBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ] = { 0 }; EthernetHeader_t * pxEthernetHeader; IPPacket_t * pxIPPacket; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - - memset( pxNetworkBuffer->pucEthernetBuffer, 0, ipconfigTCP_MSS ); + NetworkEndPoint_t xNetworkEndPoint = { 0 }; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; - pxNetworkBuffer->pucEthernetBuffer = ucEtherBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; pxNetworkBuffer->pxInterface = &xInterface; + pxNetworkBuffer->pxEndPoint = &xNetworkEndPoint; pxEthernetHeader = ( EthernetHeader_t * ) pxNetworkBuffer->pucEthernetBuffer; pxEthernetHeader->usFrameType = ipIPv4_FRAME_TYPE; @@ -2103,16 +2109,14 @@ void test_prvProcessEthernetPacket_InterfaceNull( void ) { NetworkBufferDescriptor_t xNetworkBuffer; NetworkBufferDescriptor_t * pxNetworkBuffer = &xNetworkBuffer; - uint8_t ucEtherBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthernetBuffer[ ipconfigTCP_MSS ] = { 0 }; EthernetHeader_t * pxEthernetHeader; IPPacket_t * pxIPPacket; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( pxNetworkBuffer->pucEthernetBuffer, 0, ipconfigTCP_MSS ); - pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; - pxNetworkBuffer->pucEthernetBuffer = ucEtherBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; pxNetworkBuffer->pxInterface = NULL; vReleaseNetworkBufferAndDescriptor_Expect( pxNetworkBuffer ); @@ -2221,15 +2225,13 @@ void test_prvProcessIPPacket_ValidHeader_ARPResolutionReqd( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->pxInterface = &xInterface; /* Initialize ethernet layer. */ @@ -2258,15 +2260,13 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_InvalidProt( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; /* Initialize ethernet layer. */ @@ -2299,15 +2299,13 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_ICMPRelease( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2341,15 +2339,13 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_ICMPProcess( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2383,16 +2379,14 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_UDPZeroLength( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; UDPPacket_t * pxUDPPacket; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2428,16 +2422,14 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_UDPLengthGreaterThanIPHeader( eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; UDPPacket_t * pxUDPPacket; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2473,16 +2465,14 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_UDPHappyPath( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; UDPPacket_t * pxUDPPacket; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2518,16 +2508,14 @@ void test_prvProcessIPPacket_ARPResolutionNotReqd_UDPProcessFail( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; UDPPacket_t * pxUDPPacket; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2566,17 +2554,15 @@ void test_prvProcessIPPacket_ARPResolutionReqd_UDP( void ) IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; UBaseType_t uxHeaderLength = 0; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; UDPPacket_t * pxUDPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2619,17 +2605,15 @@ void test_prvProcessIPPacket_ARPResolutionReqd_UDP1( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; UDPPacket_t * pxUDPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = sizeof( UDPPacket_t ); pxNetworkBuffer->pxInterface = &xInterface; @@ -2670,16 +2654,15 @@ void test_prvProcessIPPacket_TCP( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = sizeof( UDPPacket_t ); pxNetworkBuffer->pxInterface = &xInterface; @@ -2714,17 +2697,15 @@ void test_prvProcessIPPacket_TCPProcessFail( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; BaseType_t xReturnValue = pdTRUE; NetworkEndPoint_t xEndPoint = { 0 }; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = sizeof( UDPPacket_t ); pxNetworkBuffer->pxInterface = &xInterface; @@ -2759,15 +2740,13 @@ void test_prvProcessIPPacket_UDP_ExternalLoopback( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2799,15 +2778,13 @@ void test_prvProcessIPPacket_UDP_GreaterLoopbackAddress( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = 0; pxNetworkBuffer->pxInterface = &xInterface; @@ -2839,15 +2816,13 @@ void test_prvProcessIPPacket_UDP_LessLoopbackAddress( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = 0; pxNetworkBuffer->pxInterface = &xInterface; @@ -2879,15 +2854,13 @@ void test_prvProcessIPPacket_UDP_IPHeaderLengthTooLarge( void ) eFrameProcessingResult_t eResult; IPPacket_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_t * pxIPHeader; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv4_HEADER; pxNetworkBuffer->pxInterface = &xInterface; @@ -2915,17 +2888,15 @@ void test_prvProcessIPPacket_UDP_IPv6_HappyPath( void ) eFrameProcessingResult_t eResult; IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; UDPPacket_IPv6_t * pxUDPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -2962,17 +2933,15 @@ void test_prvProcessIPPacket_UDP_IPv6_ExtensionHappyPath( void ) eFrameProcessingResult_t eResult; IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; UDPPacket_IPv6_t * pxUDPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - /* Initialize network buffer descriptor. */ pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -3017,16 +2986,14 @@ void test_prvProcessIPPacket_UDP_IPv6_ExtensionHandleFail( void ) IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; UBaseType_t uxHeaderLength = 0; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; UDPPacket_IPv6_t * pxUDPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -3068,16 +3035,14 @@ void test_prvProcessIPPacket_TCP_IPv6_HappyPath( void ) IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; UBaseType_t uxHeaderLength = 0; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; TCPPacket_IPv6_t * pxTCPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -3120,16 +3085,14 @@ void test_prvProcessIPPacket_TCP_IPv6_ARPResolution( void ) IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; UBaseType_t uxHeaderLength = 0; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; TCPPacket_IPv6_t * pxTCPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -3169,16 +3132,14 @@ void test_prvProcessIPPacket_ICMP_IPv6_HappyPath( void ) IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; UBaseType_t uxHeaderLength = 0; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; ICMPPacket_IPv6_t * pxICMPPacket; BaseType_t xReturnValue = pdTRUE; struct xNetworkInterface xInterface; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = ipconfigTCP_MSS; pxNetworkBuffer->pxInterface = &xInterface; @@ -3220,15 +3181,13 @@ void test_prvProcessIPPacket_IPv6_LessPacketSize( void ) IPPacket_IPv6_t * pxIPPacket; NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; UBaseType_t uxHeaderLength = 0; - uint8_t ucEthBuffer[ ipconfigTCP_MSS ]; + uint8_t ucEthBuffer[ ipIP_TYPE_OFFSET + ipconfigTCP_MSS ] = { 0 }; IPHeader_IPv6_t * pxIPHeader; struct xNetworkInterface xInterface; BaseType_t xReturnValue = pdTRUE; - memset( ucEthBuffer, 0, ipconfigTCP_MSS ); - pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = sizeof( IPPacket_IPv6_t ) - 1; pxNetworkBuffer->pxInterface = &xInterface; diff --git a/test/unit-test/FreeRTOS_IP_DiffConfig1/FreeRTOS_IP_DiffConfig1_utest.c b/test/unit-test/FreeRTOS_IP_DiffConfig1/FreeRTOS_IP_DiffConfig1_utest.c index f420447d65..c103cd2649 100644 --- a/test/unit-test/FreeRTOS_IP_DiffConfig1/FreeRTOS_IP_DiffConfig1_utest.c +++ b/test/unit-test/FreeRTOS_IP_DiffConfig1/FreeRTOS_IP_DiffConfig1_utest.c @@ -441,7 +441,7 @@ void test_FreeRTOS_GetUDPPayloadBuffer_BlockTimeEqualToConfigBackwardCompatible( uint8_t pucEthernetBuffer[ 1500 ]; /* Put the ethernet buffer in place. */ - pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer; + pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer + ipIP_TYPE_OFFSET; pxNetworkBuffer->xDataLength = 0; pxGetNetworkBufferWithDescriptor_ExpectAndReturn( sizeof( UDPPacket_t ) + uxRequestedSizeBytes, uxBlockTimeTicks, pxNetworkBuffer ); diff --git a/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_stubs.c b/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_stubs.c index 03ba1b2c32..5767d82acb 100644 --- a/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_stubs.c +++ b/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_stubs.c @@ -109,7 +109,11 @@ static NetworkBufferDescriptor_t * prvInitializeNetworkDescriptorWithExtensionHe { static NetworkBufferDescriptor_t xNetworkBuffer; /* Ethernet header + IPv6 header + Maximum protocol header + IPv6 Extension Headers + 1 payload */ - static uint8_t pcNetworkBuffer[ sizeof( EthernetHeader_t ) + sizeof( IPHeader_IPv6_t ) + TEST_IPv6_DEFAULT_EXTENSION_HEADERS_LENGTH + sizeof( ICMPHeader_IPv6_t ) + 1U ]; + static uint8_t pcNetworkBuffer[ + sizeof( EthernetHeader_t ) + sizeof( IPHeader_IPv6_t ) + TEST_IPv6_DEFAULT_EXTENSION_HEADERS_LENGTH + + configMAX( sizeof( ICMPHeader_IPv6_t ), sizeof( TCPHeader_t ) ) + + 1U + ]; EthernetHeader_t * pxEthHeader = ( EthernetHeader_t * ) pcNetworkBuffer; IPHeader_IPv6_t * pxIPv6Header = ( IPHeader_IPv6_t * ) &( pcNetworkBuffer[ sizeof( EthernetHeader_t ) ] ); uint8_t * pxIPv6ExtHeader = ( uint8_t * ) &( pcNetworkBuffer[ sizeof( EthernetHeader_t ) + sizeof( IPHeader_IPv6_t ) ] ); diff --git a/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_utest.c b/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_utest.c index b869cef098..edcfab7656 100644 --- a/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_utest.c +++ b/test/unit-test/FreeRTOS_IPv6/FreeRTOS_IPv6_utest.c @@ -310,10 +310,10 @@ void test_eHandleIPv6ExtensionHeaders_TCPHappyPath() uint8_t ucExtHeaderNum = 7U; uint8_t ucProtocol = ipPROTOCOL_TCP; NetworkBufferDescriptor_t * pxNetworkBuffer = prvInitializeNetworkDescriptorWithExtensionHeader( ucProtocol ); - TCPHeader_t * pxProtocolHeader = ( TCPHeader_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + TEST_IPv6_DEFAULT_EXTENSION_HEADERS_LENGTH ] ); - uint8_t * pxPayload; + uint8_t * pxPayload = &( pxNetworkBuffer->pucEthernetBuffer[ + ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + TEST_IPv6_DEFAULT_EXTENSION_HEADERS_LENGTH + sizeof( TCPHeader_t ) + ] ); - pxPayload = ( uint8_t * ) ( pxProtocolHeader + 1 ); *pxPayload = 'a'; usGetExtensionHeaderLength_ExpectAndReturn( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength, NULL, ucExtHeaderNum * 8U ); diff --git a/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c b/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c index 6cdb37dec7..2bd43461ba 100644 --- a/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c +++ b/test/unit-test/FreeRTOS_ND/FreeRTOS_ND_utest.c @@ -455,7 +455,6 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_Gateway( void ) void test_eNDGetCacheEntry_NDCacheLookupMiss_NoEP( void ) { MACAddress_t xMACAddress; - IPv6_Address_t xIPAddress; NetworkEndPoint_t * pxEndPoint, xEndPoint; eARPLookupResult_t eResult; BaseType_t xUseEntry = 0; @@ -472,7 +471,8 @@ void test_eNDGetCacheEntry_NDCacheLookupMiss_NoEP( void ) FreeRTOS_FindGateWay_ExpectAnyArgsAndReturn( NULL ); - eResult = eNDGetCacheEntry( &xIPAddress, &xMACAddress, &pxEndPoint ); + /* TODO: This function should take a const pointer; remove const cast when it does. */ + eResult = eNDGetCacheEntry( ( IPv6_Address_t * ) &xSiteLocalIPAddress, &xMACAddress, &pxEndPoint ); TEST_ASSERT_EQUAL( eARPCacheMiss, eResult ); } @@ -1039,13 +1039,16 @@ void test_SendPingRequestIPv6_NULL_Buffer( void ) */ void test_SendPingRequestIPv6_Assert( void ) { - NetworkEndPoint_t xEndPoint, * pxEndPoint = &xEndPoint; - NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer = &xNetworkBuffer; - IPv6_Address_t xIPAddress; + NetworkEndPoint_t xEndPoint = { 0 }, * pxEndPoint = &xEndPoint; + NetworkBufferDescriptor_t xNetworkBuffer = { 0 }; + uint8_t ucEthernetBuffer[ 1500 ] = { 0 }; + IPv6_Address_t xIPAddress = { 0 }; size_t uxNumberOfBytesToSend = 100; BaseType_t xReturn; uint16_t usSequenceNumber = 1; + xNetworkBuffer.pucEthernetBuffer = ucEthernetBuffer; + xNetworkBuffer.xDataLength = sizeof( ucEthernetBuffer ); ( void ) memcpy( xIPAddress.ucBytes, xDefaultIPAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); pxEndPoint->bits.bIPv6 = 1; @@ -1057,7 +1060,7 @@ void test_SendPingRequestIPv6_Assert( void ) uxGetNumberOfFreeNetworkBuffers_ExpectAndReturn( 4U ); - pxGetNetworkBufferWithDescriptor_ExpectAnyArgsAndReturn( pxNetworkBuffer ); + pxGetNetworkBufferWithDescriptor_ExpectAnyArgsAndReturn( &xNetworkBuffer ); xSendEventStructToIPTask_IgnoreAndReturn( pdPASS ); xReturn = FreeRTOS_SendPingRequestIPv6( &xIPAddress, uxNumberOfBytesToSend, 0 ); @@ -1073,12 +1076,15 @@ void test_SendPingRequestIPv6_Assert( void ) void test_SendPingRequestIPv6_SendToIP_Pass( void ) { NetworkEndPoint_t xEndPoint, * pxEndPoint = &xEndPoint; - NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer = &xNetworkBuffer; + NetworkBufferDescriptor_t xNetworkBuffer = { 0 }, * pxNetworkBuffer = &xNetworkBuffer; + uint8_t ucEthernetBuffer[ 1500 ] = { 0 }; IPv6_Address_t xIPAddress; size_t uxNumberOfBytesToSend = 100; BaseType_t xReturn; uint16_t usSequenceNumber = 1; + xNetworkBuffer.pucEthernetBuffer = ucEthernetBuffer; + xNetworkBuffer.xDataLength = sizeof( ucEthernetBuffer ); ( void ) memcpy( xIPAddress.ucBytes, xDefaultIPAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); pxEndPoint->bits.bIPv6 = 1; @@ -1107,11 +1113,13 @@ void test_SendPingRequestIPv6_SendToIP_Fail( void ) { NetworkEndPoint_t xEndPoint, * pxEndPoint = &xEndPoint; NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer = &xNetworkBuffer; + uint8_t ucEthernetBuffer[ 1500 ] = { 0 }; IPv6_Address_t xIPAddress; size_t uxNumberOfBytesToSend = 100; BaseType_t xReturn; uint16_t usSequenceNumber = 1; + xNetworkBuffer.pucEthernetBuffer = ucEthernetBuffer; ( void ) memcpy( xIPAddress.ucBytes, xDefaultIPAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); pxEndPoint->bits.bIPv6 = 1; @@ -1454,15 +1462,17 @@ void test_prvProcessICMPMessage_IPv6_ipICMP_PING_REPLY_IPv6_eSuccess( void ) */ void test_prvProcessICMPMessage_IPv6_NeighborSolicitationNullEP( void ) { - NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer = &xNetworkBuffer; - ICMPPacket_IPv6_t xICMPPacket; - NetworkEndPoint_t xEndPoint; + NetworkBufferDescriptor_t xNetworkBuffer = { 0 }, * pxNetworkBuffer = &xNetworkBuffer; + ICMPPacket_IPv6_t xICMPPacket = { 0 }; + NetworkEndPoint_t xEndPoint = { 0 }; eFrameProcessingResult_t eReturn; xEndPoint.bits.bIPv6 = pdTRUE_UNSIGNED; + ( void ) memcpy( xEndPoint.ipv6_settings.xIPAddress.ucBytes, xDefaultIPAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); xICMPPacket.xICMPHeaderIPv6.ucTypeOfMessage = ipICMP_NEIGHBOR_SOLICITATION_IPv6; pxNetworkBuffer->pxEndPoint = &xEndPoint; pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xICMPPacket; + pxNetworkBuffer->xDataLength = sizeof( xICMPPacket ); FreeRTOS_InterfaceEPInSameSubnet_IPv6_ExpectAnyArgsAndReturn( NULL ); @@ -1497,34 +1507,6 @@ void test_prvProcessICMPMessage_IPv6_NeighborSolicitationIncorrectLen( void ) TEST_ASSERT_EQUAL( eReturn, eReleaseBuffer ); } - -/** - * @brief This function process ICMP message when message type is - * ipICMP_NEIGHBOR_SOLICITATION_IPv6. - * It handles case where the ICMP header address does not - * match which means the message is not for us, - * ignore it. - */ -void test_prvProcessICMPMessage_IPv6_NeighborSolicitationCorrectLen( void ) -{ - NetworkBufferDescriptor_t xNetworkBuffer, * pxNetworkBuffer = &xNetworkBuffer; - ICMPPacket_IPv6_t xICMPPacket; - NetworkEndPoint_t xEndPoint; - eFrameProcessingResult_t eReturn; - - xEndPoint.bits.bIPv6 = pdTRUE_UNSIGNED; - xICMPPacket.xICMPHeaderIPv6.ucTypeOfMessage = ipICMP_NEIGHBOR_SOLICITATION_IPv6; - pxNetworkBuffer->pxEndPoint = &xEndPoint; - pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xICMPPacket; - pxNetworkBuffer->xDataLength = xHeaderSize + ipBUFFER_PADDING; - - FreeRTOS_InterfaceEPInSameSubnet_IPv6_ExpectAnyArgsAndReturn( &xEndPoint ); - - eReturn = prvProcessICMPMessage_IPv6( pxNetworkBuffer ); - - TEST_ASSERT_EQUAL( eReturn, eReleaseBuffer ); -} - /** * @brief This function process ICMP message when message type is * ipICMP_NEIGHBOR_SOLICITATION_IPv6. diff --git a/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_utest.c b/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_utest.c index a1dfca94e0..b82ae59832 100644 --- a/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_utest.c +++ b/test/unit-test/FreeRTOS_RA/FreeRTOS_RA_utest.c @@ -52,6 +52,19 @@ #include "FreeRTOS_ND.h" #include "FreeRTOS_RA_stubs.c" +/* ================================ TYPES ================================= */ + +#include "pack_struct_start.h" +struct xEthernetPacketICMPv6RouterAdvertisementPrefixOption +{ + EthernetHeader_t xEthernetHeader; /* 0 + 14 = 14 */ + IPHeader_IPv6_t xIPHeader; /* 14 + 40 = 54 */ + ICMPRouterAdvertisement_IPv6_t xAdvertisement; /* 54 + 16 = 70 */ + ICMPPrefixOption_IPv6_t xPrefixOption; /* 70 + 32 = 102 */ +} +#include "pack_struct_end.h" +typedef struct xEthernetPacketICMPv6RouterAdvertisementPrefixOption EthernetPacketICMPv6RouterAdvertisementPrefixOption_t; + /* =========================== EXTERN VARIABLES =========================== */ /** The default value for the IPv6-field 'ucVersionTrafficClass'. */ @@ -866,17 +879,15 @@ void test_vReceiveRA_ValidICMPPrefix_IncorrectOption( void ) */ void test_vReceiveRA_vRAProccess( void ) { - NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer, xNetworkBuffer2; - ICMPPacket_IPv6_t xICMPPacket; + NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; + EthernetPacketICMPv6RouterAdvertisementPrefixOption_t xICMPPacket; NetworkInterface_t xInterface; - size_t uxIndex = 0U, uxNeededSize, uxOptionsLength; - uint8_t * pucBytes; NetworkEndPoint_t xEndPoint, * pxEndPoint = &xEndPoint; ICMPPrefixOption_IPv6_t * pxPrefixOption; ICMPRouterAdvertisement_IPv6_t * pxAdvertisement; memset( &xNetworkBuffer, 0, sizeof( NetworkBufferDescriptor_t ) ); - memset( &xICMPPacket, 0, sizeof( ICMPPacket_IPv6_t ) ); + memset( &xICMPPacket, 0, sizeof( xICMPPacket ) ); memset( &xInterface, 0, sizeof( NetworkInterface_t ) ); memset( &xEndPoint, 0, sizeof( NetworkEndPoint_t ) ); @@ -884,11 +895,10 @@ void test_vReceiveRA_vRAProccess( void ) pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xICMPPacket; pxNetworkBuffer->pxInterface = &xInterface; pxNetworkBuffer->xDataLength = raHeaderBytesRA + raPrefixOptionlen; - uxNeededSize = raHeaderBytesRA; - pxAdvertisement = ( ( ICMPRouterAdvertisement_IPv6_t * ) &( xICMPPacket.xICMPHeaderIPv6 ) ); + pxAdvertisement = &xICMPPacket.xAdvertisement; pxAdvertisement->usLifetime = pdTRUE_UNSIGNED; - pxPrefixOption = ( ICMPPrefixOption_IPv6_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ uxNeededSize ] ); + pxPrefixOption = &xICMPPacket.xPrefixOption; pxPrefixOption->ucType = ndICMP_PREFIX_INFORMATION; /* Only 1 option */ pxPrefixOption->ucLength = 1; @@ -906,17 +916,15 @@ void test_vReceiveRA_vRAProccess( void ) */ void test_vReceiveRA_vRAProcess( void ) { - NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer, xNetworkBuffer2; - ICMPPacket_IPv6_t xICMPPacket; + NetworkBufferDescriptor_t * pxNetworkBuffer, xNetworkBuffer; + EthernetPacketICMPv6RouterAdvertisementPrefixOption_t xICMPPacket; NetworkInterface_t xInterface; - size_t uxIndex = 0U, uxNeededSize, uxOptionsLength; - uint8_t * pucBytes; NetworkEndPoint_t xEndPoint, * pxEndPoint = &xEndPoint; ICMPPrefixOption_IPv6_t * pxPrefixOption; ICMPRouterAdvertisement_IPv6_t * pxAdvertisement; memset( &xNetworkBuffer, 0, sizeof( NetworkBufferDescriptor_t ) ); - memset( &xICMPPacket, 0, sizeof( ICMPPacket_IPv6_t ) ); + memset( &xICMPPacket, 0, sizeof( xICMPPacket ) ); memset( &xInterface, 0, sizeof( NetworkInterface_t ) ); memset( &xEndPoint, 0, sizeof( NetworkEndPoint_t ) ); @@ -924,11 +932,10 @@ void test_vReceiveRA_vRAProcess( void ) pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xICMPPacket; pxNetworkBuffer->pxInterface = &xInterface; pxNetworkBuffer->xDataLength = raHeaderBytesRA + raPrefixOptionlen; - uxNeededSize = raHeaderBytesRA; - pxAdvertisement = ( ( ICMPRouterAdvertisement_IPv6_t * ) &( xICMPPacket.xICMPHeaderIPv6 ) ); + pxAdvertisement = &xICMPPacket.xAdvertisement; pxAdvertisement->usLifetime = pdTRUE_UNSIGNED; - pxPrefixOption = ( ICMPPrefixOption_IPv6_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ uxNeededSize ] ); + pxPrefixOption = &xICMPPacket.xPrefixOption; pxPrefixOption->ucType = ndICMP_PREFIX_INFORMATION; /* Only 1 option */ pxPrefixOption->ucLength = 1; diff --git a/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c b/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c index 13525f1357..4275506bf8 100644 --- a/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c +++ b/test/unit-test/FreeRTOS_Routing/FreeRTOS_Routing_utest.c @@ -2379,8 +2379,8 @@ void test_pcEndpointName_IPv4_HappyPath() { NetworkEndPoint_t xEndPoint; FreeRTOS_Socket_t xSocket; - char cIPString[] = "192.168.123.223"; - int lNameSize = sizeof( cIPString ) + 1; + static const char cIPString[] = "192.168.123.223"; + uint32_t lNameSize = sizeof( cIPString ); char cName[ lNameSize ]; const char * pcName = NULL; @@ -2388,7 +2388,7 @@ void test_pcEndpointName_IPv4_HappyPath() memset( &xEndPoint, 0, sizeof( NetworkEndPoint_t ) ); xEndPoint.ipv4_settings.ulIPAddress = IPV4_DEFAULT_ADDRESS; - memset( &cName, 0, sizeof( cName ) ); + memset( cName, 0, sizeof( cName ) ); xStubFreeRTOS_inet_ntop_TargetFamily = FREERTOS_AF_INET4; pvStubFreeRTOS_inet_ntop_TargetSource = &( xEndPoint.ipv4_settings.ulIPAddress ); @@ -2507,8 +2507,8 @@ void test_pcEndpointName_IPv6_HappyPath() { NetworkEndPoint_t xEndPoint; FreeRTOS_Socket_t xSocket; - const char cIPString[] = "2001::1"; - int lNameSize = sizeof( cIPString ) + 1; + static const char cIPString[] = "2001::1"; + uint32_t lNameSize = sizeof( cIPString ); char cName[ lNameSize ]; const char * pcName; @@ -2517,7 +2517,7 @@ void test_pcEndpointName_IPv6_HappyPath() xEndPoint.bits.bIPv6 = pdTRUE; memcpy( xEndPoint.ipv6_settings.xIPAddress.ucBytes, &xDefaultIPAddress_IPv6.ucBytes, sizeof( IPv6_Address_t ) ); - memset( &cName, 0, sizeof( cName ) ); + memset( cName, 0, sizeof( cName ) ); xStubFreeRTOS_inet_ntop_TargetFamily = FREERTOS_AF_INET6; pvStubFreeRTOS_inet_ntop_TargetSource = xEndPoint.ipv6_settings.xIPAddress.ucBytes; diff --git a/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_stubs.c b/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_stubs.c index 34fe7a2c2c..2ac4847522 100644 --- a/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_stubs.c +++ b/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_stubs.c @@ -54,6 +54,8 @@ BaseType_t xRNGStatus; BaseType_t xLocalReceiveCallback_Return; uint8_t xLocalReceiveCallback_Called = 0; +BaseType_t xTCPWindowLoggingLevel = 0; + /* ======================== Stub Callback Functions ========================= */ EventBits_t xStubForEventGroupWaitBits( EventGroupHandle_t xEventGroup, diff --git a/test/unit-test/FreeRTOS_Sockets_DiffConfig/FreeRTOS_Sockets_DiffConfig_privates_utest.c b/test/unit-test/FreeRTOS_Sockets_DiffConfig/FreeRTOS_Sockets_DiffConfig_privates_utest.c index 3b612ec210..0c61574b04 100644 --- a/test/unit-test/FreeRTOS_Sockets_DiffConfig/FreeRTOS_Sockets_DiffConfig_privates_utest.c +++ b/test/unit-test/FreeRTOS_Sockets_DiffConfig/FreeRTOS_Sockets_DiffConfig_privates_utest.c @@ -56,7 +56,11 @@ #include "catch_assert.h" -/* ============================== Test Cases ============================== */ +/* ============================ EXTERN VARIABLES ============================ */ + +BaseType_t xTCPWindowLoggingLevel = 0; + +/* =============================== Test Cases =============================== */ /** * @brief Binding successful. diff --git a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_GenericAPI_utest.c b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_GenericAPI_utest.c index c20dba9197..9b43c4c6e1 100644 --- a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_GenericAPI_utest.c +++ b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_GenericAPI_utest.c @@ -53,7 +53,9 @@ /* ============================ EXTERN VARIABLES ============================ */ /* 2001::1 */ -static IPv6_Address_t xIPv6Address = { { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }; +static const IPv6_Address_t xIPv6Address = { { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }; + +BaseType_t xTCPWindowLoggingLevel = 0; /* ============================== Test Cases ============================== */ @@ -231,7 +233,7 @@ void test_FreeRTOS_connect_SocketValuesNULL_NullDestinationAddress( void ) void test_prvSocketProps_UDPv6() { FreeRTOS_Socket_t xSocket; - IPv6_Address_t * pxIPv6SrcAddress = &xIPv6Address; /* 2001::1 */ + const IPv6_Address_t * pxIPv6SrcAddress = &xIPv6Address; /* 2001::1 */ uint16_t usSrcPort = 1024U; const char * pcReturn; @@ -251,7 +253,7 @@ void test_prvSocketProps_UDPv6() void test_prvSocketProps_TCPv6() { FreeRTOS_Socket_t xSocket; - IPv6_Address_t * pxIPv6SrcAddress = &xIPv6Address; /* 2001::1 */ + const IPv6_Address_t * pxIPv6SrcAddress = &xIPv6Address; /* 2001::1 */ IPv6_Address_t xIPv6RemoteAddress = { { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 } }; /* 2001::2 */ uint16_t usSrcPort = 1024U; uint16_t usRemotePort = 2048U; diff --git a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_TCP_API_utest.c b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_TCP_API_utest.c index 361b05fa1e..03b3687521 100644 --- a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_TCP_API_utest.c +++ b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_TCP_API_utest.c @@ -50,7 +50,9 @@ /* ============================ EXTERN VARIABLES ============================ */ /* 2001::1 */ -static IPv6_Address_t xIPv6Address = { { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }; +static const IPv6_Address_t xIPv6Address = { { 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } }; + +BaseType_t xTCPWindowLoggingLevel = 0; /* =============================== Test Cases =============================== */ diff --git a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_UDP_API_utest.c b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_UDP_API_utest.c index 7fe9363774..af3ee7d8fc 100644 --- a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_UDP_API_utest.c +++ b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_UDP_API_utest.c @@ -46,6 +46,8 @@ #define TEST_MAX_UDPV4_PAYLOAD_LENGTH ipconfigNETWORK_MTU - ( ipSIZE_OF_IPv4_HEADER + ipSIZE_OF_UDP_HEADER ) +BaseType_t xTCPWindowLoggingLevel = 0; + /* =============================== Test Cases =============================== */ /** diff --git a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_privates_utest.c b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_privates_utest.c index 45e1968897..752aef9c01 100644 --- a/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_privates_utest.c +++ b/test/unit-test/FreeRTOS_Sockets_DiffConfig1/FreeRTOS_Sockets_DiffConfig1_privates_utest.c @@ -54,6 +54,8 @@ BaseType_t prvDetermineSocketSize( BaseType_t xDomain, BaseType_t xProtocol, size_t * pxSocketSize ); +BaseType_t xTCPWindowLoggingLevel = 0; + /* ============================== Test Cases ============================== */ /** diff --git a/test/unit-test/FreeRTOS_TCP_IP/FreeRTOS_TCP_IP_utest.c b/test/unit-test/FreeRTOS_TCP_IP/FreeRTOS_TCP_IP_utest.c index 94a972213b..7eee3348c6 100644 --- a/test/unit-test/FreeRTOS_TCP_IP/FreeRTOS_TCP_IP_utest.c +++ b/test/unit-test/FreeRTOS_TCP_IP/FreeRTOS_TCP_IP_utest.c @@ -1076,7 +1076,12 @@ void test_vTCPStateChange_ClosedWaitState_CallingFromIPTask( void ) xIsCallingFromIPTask_ExpectAndReturn( pdTRUE ); - vSocketClose_ExpectAnyArgsAndReturn( NULL ); + /* FIXME: Different behaviour with -fsanitize=address,undefined. */ + if( xSocketToClose != &xSocket ) + { + vSocketClose_ExpectAnyArgsAndReturn( NULL ); + } + xTaskResumeAll_ExpectAndReturn( 0 ); xTaskGetTickCount_ExpectAndReturn( xTickCountAck ); @@ -1173,6 +1178,12 @@ void test_vTCPStateChange_ClosedWaitState_CallingFromIPTask1( void ) xIsCallingFromIPTask_ExpectAndReturn( pdTRUE ); + /* FIXME: Different behaviour with -fsanitize=address,undefined. */ + if( xSocketToClose != &xSocket ) + { + vSocketClose_ExpectAnyArgsAndReturn( NULL ); + } + xTaskResumeAll_ExpectAndReturn( 0 ); xTaskGetTickCount_ExpectAndReturn( xTickCountAck ); @@ -1809,17 +1820,18 @@ void test_xProcessReceivedTCPPacket_Null_Buffer( void ) void test_xProcessReceivedTCPPacket_IPv6_FrameType( void ) { BaseType_t Return = pdFALSE; - EthernetHeader_t xEthHeader; + uint8_t xEthBuffer[ 1500 ] = { 0 }; - pxNetworkBuffer = &xNetworkBuffer; - pxNetworkBuffer->pucEthernetBuffer = ( uint8_t * ) &xEthHeader; + ( ( EthernetHeader_t * ) xEthBuffer )->usFrameType = ipIPv6_FRAME_TYPE; - xEthHeader.usFrameType = ipIPv6_FRAME_TYPE; + pxNetworkBuffer = &xNetworkBuffer; + pxNetworkBuffer->pucEthernetBuffer = xEthBuffer; pxNetworkBuffer->xDataLength = 100; uxIPHeaderSizePacket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv6_HEADER ); pxTCPSocketLookup_ExpectAnyArgsAndReturn( NULL ); + prvTCPSendReset_ExpectAnyArgsAndReturn( pdTRUE ); Return = xProcessReceivedTCPPacket( pxNetworkBuffer ); diff --git a/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c b/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c index 745dc1a209..99b3bbc395 100644 --- a/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c +++ b/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c @@ -813,6 +813,7 @@ void test_prvTCPReturnPacket_No_KL( void ) pxTCPPacket->xTCPHeader.ulAckNr = 0; pxSocket->pxEndPoint = &xEndPoint; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -867,6 +868,7 @@ void test_prvTCPReturnPacket_No_KL_LocalIP( void ) pxTCPPacket->xTCPHeader.ulAckNr = 0; pxSocket->pxEndPoint = &xEndPoint; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -927,6 +929,7 @@ void test_prvTCPReturnPacket_No_KL_LocalIP_GT_Eth_Packet_Length( void ) pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -966,6 +969,7 @@ void test_prvTCPReturnPacket_No_KL_LocalIP_ARP_Not_Hit( void ) xEndPoint.pxNetworkInterface->pfOutput = &NetworkInterfaceOutputFunction_Stub; NetworkInterfaceOutputFunction_Stub_Called = 0; pxSocket->pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; pxSocket->u.xTCP.rxStream = ( StreamBuffer_t * ) 0x12345678; pxSocket->u.xTCP.uxRxStreamSize = 1500; @@ -1035,6 +1039,7 @@ void test_prvTCPReturnPacket_No_KL_Fin_Suppress_Rx_Stop( void ) pxTCPPacket->xTCPHeader.ulAckNr = 0; pxTCPPacket->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_FIN; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizeSocket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); @@ -1086,6 +1091,7 @@ void test_prvTCPReturnPacket_No_KL_Fin_Not_Suppress_Low_Water( void ) pxTCPPacket->xTCPHeader.ulAckNr = 0; pxTCPPacket->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_FIN; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizeSocket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); @@ -1137,6 +1143,7 @@ void test_prvTCPReturnPacket_No_KL_Fin_Not_Suppress_Big_Win( void ) pxTCPPacket->xTCPHeader.ulAckNr = 0; pxTCPPacket->xTCPHeader.ucTCPFlags = tcpTCP_FLAG_FIN; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizeSocket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); @@ -2151,6 +2158,7 @@ void test_prvSendData_AckMsg_Not_Null_Small_Length( void ) pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); vReleaseNetworkBufferAndDescriptor_ExpectAnyArgs(); @@ -2207,7 +2215,7 @@ void test_prvSendData_AckMsg_Not_Null_Same_NetBuffer_Syn_State( void ) pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; - + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -2263,6 +2271,7 @@ void test_prvSendData_AckMsg_Not_Null_Same_NetBuffer_Syn_State_Data_To_Send( voi pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -2318,6 +2327,7 @@ void test_prvSendData_AckMsg_Null_Syn_State_Data_To_Send( void ) pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -2374,6 +2384,7 @@ void test_prvSendData_AckMsg_Null_Syn_State_Data_To_Send_Log( void ) pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); @@ -2430,6 +2441,7 @@ void test_prvSendData_AckMsg_Null_Syn_State_Data_To_Send_Rcv_Zero( void ) pxTCPWindow->rx.ulCurrentSequenceNumber = 50; pxTCPPacket->xTCPHeader.ulAckNr = 0; pxEndPoint = &xEndPoint; + pxNetworkBuffer->pxEndPoint = &xEndPoint; uxIPHeaderSizePacket_IgnoreAndReturn( ipSIZE_OF_IPv4_HEADER ); uxStreamBufferFrontSpace_ExpectAnyArgsAndReturn( 1000 ); diff --git a/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_utest.c b/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_utest.c index dfabac3746..99e800e412 100644 --- a/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_utest.c +++ b/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_utest.c @@ -193,12 +193,15 @@ void test_vTCPWindowDestroy_list_length_zero( void ) void test_vTCPWindowDestroy_list_length_not_zero( void ) { TCPWindow_t xWindow = { 0 }; - List_t * pxSegments = &( xWindow.xRxSegments ); + TCPSegment_t xSegment = { 0 }; + + xSegment.xQueueItem.pvContainer = &xWindow.xPriorityQueue; + xSegment.xSegmentItem.pvContainer = &xWindow.xPriorityQueue; listLIST_IS_INITIALISED_ExpectAnyArgsAndReturn( pdFALSE ); listLIST_IS_INITIALISED_ExpectAnyArgsAndReturn( pdTRUE ); listCURRENT_LIST_LENGTH_ExpectAnyArgsAndReturn( 1 ); - listGET_OWNER_OF_HEAD_ENTRY_ExpectAnyArgsAndReturn( pxSegments ); + listGET_OWNER_OF_HEAD_ENTRY_ExpectAnyArgsAndReturn( &xSegment ); /* ->vTCPWindowFree */ uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); uxListRemove_ExpectAnyArgsAndReturn( pdTRUE ); @@ -389,11 +392,14 @@ void test_vTCPSegmentCleanup_segment_null( void ) void test_vTCPSegmentCleanup_segment_not_null( void ) { /* will be freed by the function under test */ - xTCPSegments = ( TCPSegment_t * ) malloc( 123 ); + TCPSegment_t * pxTCPSegment = malloc( sizeof( TCPSegment_t ) ); + + xTCPSegments = pxTCPSegment; vPortFree_Expect( xTCPSegments ); vTCPSegmentCleanup(); TEST_ASSERT_NULL( xTCPSegments ); + free( pxTCPSegment ); } void test_lTCPWindowRxCheck_sequence_nums_equal( void ) @@ -1044,13 +1050,14 @@ void test_lTCPWindowTxAdd_nothing_to_do( void ) { int32_t lDone; TCPWindow_t xWindow = { 0 }; + TCPSegment_t xSegment = { 0 }; uint32_t ulLength = 0; int32_t lPosition = 0; int32_t lMax = 0; BaseType_t xBackup = xTCPWindowLoggingLevel; /* in real code, this points to a list of segments */ - xWindow.pxHeadSegment = malloc( sizeof( TCPSegment_t ) ); + xWindow.pxHeadSegment = &xSegment; xTCPWindowLoggingLevel = 3; @@ -1062,7 +1069,6 @@ void test_lTCPWindowTxAdd_nothing_to_do( void ) TEST_ASSERT_EQUAL( 0, lDone ); xTCPWindowLoggingLevel = xBackup; - free( xWindow.pxHeadSegment ); } void test_lTCPWindowTxAdd_null_txSegment( void ) @@ -1230,7 +1236,9 @@ void test_lTCPWindowTxAdd_lBytesLeft_gt_zero_data_length_gt_maxlen( void ) int32_t lMax = 0; /* in real code, this points to a list of segments */ - xWindow.pxHeadSegment = malloc( sizeof( TCPSegment_t ) ); + TCPSegment_t * pxTCPSegment = malloc( sizeof( TCPSegment_t ) ); + + xWindow.pxHeadSegment = pxTCPSegment; xWindow.pxHeadSegment->lMaxLength = 300; xWindow.pxHeadSegment->lDataLength = 200; xWindow.pxHeadSegment->u.bits.bOutstanding = pdTRUE_UNSIGNED; @@ -1262,7 +1270,7 @@ void test_lTCPWindowTxAdd_lBytesLeft_gt_zero_data_length_gt_maxlen( void ) TEST_ASSERT_EQUAL( 25, lDone ); TEST_ASSERT_NULL( xWindow.pxHeadSegment ); - free( xWindow.pxHeadSegment ); + free( pxTCPSegment ); } void test_lTCPWindowTxAdd_lBytesLeft_gt_zero_data_length_lt_maxlen( void ) diff --git a/test/unit-test/FreeRTOS_TCP_WIN/ut.cmake b/test/unit-test/FreeRTOS_TCP_WIN/ut.cmake index b36711c84f..309104dc86 100644 --- a/test/unit-test/FreeRTOS_TCP_WIN/ut.cmake +++ b/test/unit-test/FreeRTOS_TCP_WIN/ut.cmake @@ -32,7 +32,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "") list(APPEND real_source_files diff --git a/test/unit-test/FreeRTOS_Tiny_TCP/ut.cmake b/test/unit-test/FreeRTOS_Tiny_TCP/ut.cmake index 656973395e..959ae9dd9f 100644 --- a/test/unit-test/FreeRTOS_Tiny_TCP/ut.cmake +++ b/test/unit-test/FreeRTOS_Tiny_TCP/ut.cmake @@ -29,7 +29,7 @@ list(APPEND mock_define_list # ================= Create the library under test here (edit) ================== -add_compile_options(-Wno-pedantic -Wno-div-by-zero -O0 -ggdb3) +add_compile_options(-Wno-pedantic -ggdb3) # list the files you would like to test here set(real_source_files "") list(APPEND real_source_files diff --git a/test/unit-test/cmock/create_test.cmake b/test/unit-test/cmock/create_test.cmake index e44be268c1..f8e46c1e6c 100644 --- a/test/unit-test/cmock/create_test.cmake +++ b/test/unit-test/cmock/create_test.cmake @@ -19,7 +19,7 @@ function(create_test test_name ) add_executable(${test_name} ${test_src} ${test_name}_runner.c) set_target_properties(${test_name} PROPERTIES - COMPILE_FLAG "-Wall -O0 -ggdb" + COMPILE_FLAG "-Wall -ggdb3" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/tests" INSTALL_RPATH_USE_LINK_PATH TRUE LINK_FLAGS " \ From 0a8ad98ffc14e96cb508dc70100f989bb54d42e0 Mon Sep 17 00:00:00 2001 From: Tony Josi Date: Mon, 17 Jun 2024 09:03:54 +0530 Subject: [PATCH 02/15] Handle buffer allocation failure in `prvCreateSectors` (#1152) * Catch allocation failure in prvCreateSectors * Fix unit tests * Fix UTs 2 * Fix formatting --- source/FreeRTOS_TCP_State_Handling_IPv4.c | 81 ++++++++++------- source/FreeRTOS_TCP_State_Handling_IPv6.c | 89 ++++++++++-------- source/FreeRTOS_TCP_Transmission.c | 7 +- source/FreeRTOS_TCP_Transmission_IPv4.c | 5 +- source/FreeRTOS_TCP_Transmission_IPv6.c | 5 +- source/FreeRTOS_TCP_WIN.c | 20 +++-- source/include/FreeRTOS_TCP_Transmission.h | 2 +- source/include/FreeRTOS_TCP_WIN.h | 12 +-- .../FreeRTOS_TCP_State_Handling_IPv4_utest.c | 75 +++++++++++++++- .../FreeRTOS_TCP_State_Handling_IPv6_utest.c | 90 ++++++++++++++++++- .../FreeRTOS_TCP_Transmission_utest.c | 24 ++++- .../FreeRTOS_TCP_Transmission_IPv6_stubs.c | 7 -- .../FreeRTOS_TCP_Transmission_IPv6_utest.c | 34 +++++++ .../TCP_Transmission_IPv6_list_macros.h | 37 ++++++++ .../FreeRTOS_TCP_Transmission_IPv6/ut.cmake | 1 + .../FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_utest.c | 79 +++++++++++----- 16 files changed, 447 insertions(+), 121 deletions(-) create mode 100644 test/unit-test/FreeRTOS_TCP_Transmission_IPv6/TCP_Transmission_IPv6_list_macros.h diff --git a/source/FreeRTOS_TCP_State_Handling_IPv4.c b/source/FreeRTOS_TCP_State_Handling_IPv4.c index 5bba5a7718..4badde1383 100644 --- a/source/FreeRTOS_TCP_State_Handling_IPv4.c +++ b/source/FreeRTOS_TCP_State_Handling_IPv4.c @@ -81,6 +81,7 @@ FreeRTOS_Socket_t * prvHandleListen_IPV4( FreeRTOS_Socket_t * pxSocket, FreeRTOS_Socket_t * pxReturn = NULL; uint32_t ulInitialSequenceNumber = 0U; const NetworkEndPoint_t * pxEndpoint = NULL; + BaseType_t xIsNewSocket = pdFALSE; if( ( pxSocket != NULL ) && ( pxNetworkBuffer != NULL ) ) { @@ -155,6 +156,7 @@ FreeRTOS_Socket_t * prvHandleListen_IPV4( FreeRTOS_Socket_t * pxSocket, * socket to the new socket. Only the binding might fail (due to * lack of resources). */ pxReturn = pxNewSocket; + xIsNewSocket = pdTRUE; } else { @@ -166,45 +168,62 @@ FreeRTOS_Socket_t * prvHandleListen_IPV4( FreeRTOS_Socket_t * pxSocket, if( ( ulInitialSequenceNumber != 0U ) && ( pxReturn != NULL ) ) { - size_t xCopyLength; + do + { + size_t xCopyLength; + BaseType_t xReturnCreateWindow; - /* Map the byte stream onto the ProtocolHeaders_t for easy access to the fields. */ + /* Map the byte stream onto the ProtocolHeaders_t for easy access to the fields. */ - /* MISRA Ref 11.3.1 [Misaligned access] */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ - /* coverity[misra_c_2012_rule_11_3_violation] */ - const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) - &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ) ] ) ); + /* MISRA Ref 11.3.1 [Misaligned access] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* coverity[misra_c_2012_rule_11_3_violation] */ + const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) + &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ) ] ) ); - /* The endpoint in network buffer must be valid in this condition. */ - pxReturn->pxEndPoint = pxNetworkBuffer->pxEndPoint; - pxReturn->bits.bIsIPv6 = pdFALSE_UNSIGNED; - pxReturn->u.xTCP.usRemotePort = FreeRTOS_htons( pxTCPPacket->xTCPHeader.usSourcePort ); - pxReturn->u.xTCP.xRemoteIP.ulIP_IPv4 = FreeRTOS_htonl( pxTCPPacket->xIPHeader.ulSourceIPAddress ); - pxReturn->u.xTCP.xTCPWindow.ulOurSequenceNumber = ulInitialSequenceNumber; + /* The endpoint in network buffer must be valid in this condition. */ + pxReturn->pxEndPoint = pxNetworkBuffer->pxEndPoint; + pxReturn->bits.bIsIPv6 = pdFALSE_UNSIGNED; + pxReturn->u.xTCP.usRemotePort = FreeRTOS_htons( pxTCPPacket->xTCPHeader.usSourcePort ); + pxReturn->u.xTCP.xRemoteIP.ulIP_IPv4 = FreeRTOS_htonl( pxTCPPacket->xIPHeader.ulSourceIPAddress ); + pxReturn->u.xTCP.xTCPWindow.ulOurSequenceNumber = ulInitialSequenceNumber; - /* Here is the SYN action. */ - pxReturn->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulSequenceNumber ); - prvSocketSetMSS( pxReturn ); + /* Here is the SYN action. */ + pxReturn->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulSequenceNumber ); + prvSocketSetMSS( pxReturn ); - prvTCPCreateWindow( pxReturn ); + xReturnCreateWindow = prvTCPCreateWindow( pxReturn ); - vTCPStateChange( pxReturn, eSYN_FIRST ); + /* Did allocating TCP sectors fail? */ + if( xReturnCreateWindow != pdPASS ) + { + /* Close the socket if it was newly created. */ + if( xIsNewSocket == pdTRUE ) + { + vSocketClose( pxReturn ); + } - /* Make a copy of the header up to the TCP header. It is needed later - * on, whenever data must be sent to the peer. */ - if( pxNetworkBuffer->xDataLength > sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ) ) - { - xCopyLength = sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ); - } - else - { - xCopyLength = pxNetworkBuffer->xDataLength; - } + pxReturn = NULL; + break; + } + + vTCPStateChange( pxReturn, eSYN_FIRST ); + + /* Make a copy of the header up to the TCP header. It is needed later + * on, whenever data must be sent to the peer. */ + if( pxNetworkBuffer->xDataLength > sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ) ) + { + xCopyLength = sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ); + } + else + { + xCopyLength = pxNetworkBuffer->xDataLength; + } - ( void ) memcpy( ( void * ) pxReturn->u.xTCP.xPacket.u.ucLastPacket, - ( const void * ) pxNetworkBuffer->pucEthernetBuffer, - xCopyLength ); + ( void ) memcpy( ( void * ) pxReturn->u.xTCP.xPacket.u.ucLastPacket, + ( const void * ) pxNetworkBuffer->pucEthernetBuffer, + xCopyLength ); + } while( ipFALSE_BOOL ); } return pxReturn; diff --git a/source/FreeRTOS_TCP_State_Handling_IPv6.c b/source/FreeRTOS_TCP_State_Handling_IPv6.c index 60a1682075..ab9020995b 100644 --- a/source/FreeRTOS_TCP_State_Handling_IPv6.c +++ b/source/FreeRTOS_TCP_State_Handling_IPv6.c @@ -79,6 +79,7 @@ FreeRTOS_Socket_t * prvHandleListen_IPV6( FreeRTOS_Socket_t * pxSocket, FreeRTOS_Socket_t * pxReturn = NULL; uint32_t ulInitialSequenceNumber = 0; BaseType_t xHasSequence = pdFALSE; + BaseType_t xIsNewSocket = pdFALSE; if( ( pxSocket != NULL ) && ( pxNetworkBuffer != NULL ) ) { @@ -150,6 +151,7 @@ FreeRTOS_Socket_t * prvHandleListen_IPV6( FreeRTOS_Socket_t * pxSocket, * socket to the new socket. Only the binding might fail (due to * lack of resources). */ pxReturn = pxNewSocket; + xIsNewSocket = pdTRUE; } else { @@ -161,50 +163,67 @@ FreeRTOS_Socket_t * prvHandleListen_IPV6( FreeRTOS_Socket_t * pxSocket, if( ( xHasSequence != pdFALSE ) && ( pxReturn != NULL ) ) { - size_t xCopyLength; - const IPHeader_IPv6_t * pxIPHeader_IPv6; + do + { + size_t xCopyLength; + const IPHeader_IPv6_t * pxIPHeader_IPv6; + BaseType_t xReturnCreateWindow; - /* Map the byte stream onto the ProtocolHeaders_t for easy access to the fields. */ + /* Map the byte stream onto the ProtocolHeaders_t for easy access to the fields. */ - /* MISRA Ref 11.3.1 [Misaligned access] */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ - /* coverity[misra_c_2012_rule_11_3_violation] */ - const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) - &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ) ] ) ); + /* MISRA Ref 11.3.1 [Misaligned access] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* coverity[misra_c_2012_rule_11_3_violation] */ + const ProtocolHeaders_t * pxProtocolHeaders = ( ( const ProtocolHeaders_t * ) + &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ) ] ) ); - pxReturn->pxEndPoint = pxNetworkBuffer->pxEndPoint; - pxReturn->bits.bIsIPv6 = pdTRUE_UNSIGNED; + pxReturn->pxEndPoint = pxNetworkBuffer->pxEndPoint; + pxReturn->bits.bIsIPv6 = pdTRUE_UNSIGNED; - /* MISRA Ref 11.3.1 [Misaligned access] */ - /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ - /* coverity[misra_c_2012_rule_11_3_violation] */ - pxIPHeader_IPv6 = ( ( const IPHeader_IPv6_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); - pxReturn->u.xTCP.usRemotePort = FreeRTOS_ntohs( pxTCPPacket->xTCPHeader.usSourcePort ); - ( void ) memcpy( pxReturn->u.xTCP.xRemoteIP.xIP_IPv6.ucBytes, pxIPHeader_IPv6->xSourceAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); - pxReturn->u.xTCP.xTCPWindow.ulOurSequenceNumber = ulInitialSequenceNumber; + /* MISRA Ref 11.3.1 [Misaligned access] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* coverity[misra_c_2012_rule_11_3_violation] */ + pxIPHeader_IPv6 = ( ( const IPHeader_IPv6_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) ); + pxReturn->u.xTCP.usRemotePort = FreeRTOS_ntohs( pxTCPPacket->xTCPHeader.usSourcePort ); + ( void ) memcpy( pxReturn->u.xTCP.xRemoteIP.xIP_IPv6.ucBytes, pxIPHeader_IPv6->xSourceAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); + pxReturn->u.xTCP.xTCPWindow.ulOurSequenceNumber = ulInitialSequenceNumber; - /* Here is the SYN action. */ - pxReturn->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulSequenceNumber ); - prvSocketSetMSS( pxReturn ); + /* Here is the SYN action. */ + pxReturn->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber = FreeRTOS_ntohl( pxProtocolHeaders->xTCPHeader.ulSequenceNumber ); + prvSocketSetMSS( pxReturn ); - prvTCPCreateWindow( pxReturn ); + xReturnCreateWindow = prvTCPCreateWindow( pxReturn ); - vTCPStateChange( pxReturn, eSYN_FIRST ); + /* Did allocating TCP sectors fail? */ + if( xReturnCreateWindow != pdPASS ) + { + /* Close the socket if it was newly created. */ + if( xIsNewSocket == pdTRUE ) + { + vSocketClose( pxReturn ); + } - /* Make a copy of the header up to the TCP header. It is needed later - * on, whenever data must be sent to the peer. */ - if( pxNetworkBuffer->xDataLength > sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ) ) - { - xCopyLength = sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ); - } - else - { - xCopyLength = pxNetworkBuffer->xDataLength; - } + pxReturn = NULL; + break; + } + + vTCPStateChange( pxReturn, eSYN_FIRST ); + + /* Make a copy of the header up to the TCP header. It is needed later + * on, whenever data must be sent to the peer. */ + if( pxNetworkBuffer->xDataLength > sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ) ) + { + xCopyLength = sizeof( pxReturn->u.xTCP.xPacket.u.ucLastPacket ); + } + else + { + xCopyLength = pxNetworkBuffer->xDataLength; + } - ( void ) memcpy( ( void * ) pxReturn->u.xTCP.xPacket.u.ucLastPacket, - ( const void * ) pxNetworkBuffer->pucEthernetBuffer, - xCopyLength ); + ( void ) memcpy( ( void * ) pxReturn->u.xTCP.xPacket.u.ucLastPacket, + ( const void * ) pxNetworkBuffer->pucEthernetBuffer, + xCopyLength ); + } while( ipFALSE_BOOL ); } return pxReturn; diff --git a/source/FreeRTOS_TCP_Transmission.c b/source/FreeRTOS_TCP_Transmission.c index bdfbe4e190..e05c998b7f 100644 --- a/source/FreeRTOS_TCP_Transmission.c +++ b/source/FreeRTOS_TCP_Transmission.c @@ -452,8 +452,9 @@ * (in FreeRTOS_TCP_WIN.c) needs to know them, along with the Maximum Segment * Size (MSS). */ - void prvTCPCreateWindow( FreeRTOS_Socket_t * pxSocket ) + BaseType_t prvTCPCreateWindow( FreeRTOS_Socket_t * pxSocket ) { + BaseType_t xReturn; uint32_t ulRxWindowSize = ( uint32_t ) pxSocket->u.xTCP.uxRxWinSize; uint32_t ulTxWindowSize = ( uint32_t ) pxSocket->u.xTCP.uxTxWinSize; @@ -466,13 +467,15 @@ ( unsigned ) pxSocket->u.xTCP.uxRxStreamSize ) ); } - vTCPWindowCreate( + xReturn = xTCPWindowCreate( &pxSocket->u.xTCP.xTCPWindow, ulRxWindowSize * ipconfigTCP_MSS, ulTxWindowSize * ipconfigTCP_MSS, pxSocket->u.xTCP.xTCPWindow.rx.ulCurrentSequenceNumber, pxSocket->u.xTCP.xTCPWindow.ulOurSequenceNumber, ( uint32_t ) pxSocket->u.xTCP.usMSS ); + + return xReturn; } /*-----------------------------------------------------------*/ diff --git a/source/FreeRTOS_TCP_Transmission_IPv4.c b/source/FreeRTOS_TCP_Transmission_IPv4.c index c69b97d7c9..2b2492957b 100644 --- a/source/FreeRTOS_TCP_Transmission_IPv4.c +++ b/source/FreeRTOS_TCP_Transmission_IPv4.c @@ -457,7 +457,10 @@ BaseType_t prvTCPPrepareConnect_IPV4( FreeRTOS_Socket_t * pxSocket ) /* The initial sequence numbers at our side are known. Later * vTCPWindowInit() will be called to fill in the peer's sequence numbers, but * first wait for a SYN+ACK reply. */ - prvTCPCreateWindow( pxSocket ); + if( prvTCPCreateWindow( pxSocket ) != pdTRUE ) + { + xReturn = pdFALSE; + } } return xReturn; diff --git a/source/FreeRTOS_TCP_Transmission_IPv6.c b/source/FreeRTOS_TCP_Transmission_IPv6.c index 63b7a307aa..125da5acfa 100644 --- a/source/FreeRTOS_TCP_Transmission_IPv6.c +++ b/source/FreeRTOS_TCP_Transmission_IPv6.c @@ -468,7 +468,10 @@ BaseType_t prvTCPPrepareConnect_IPV6( FreeRTOS_Socket_t * pxSocket ) /* The initial sequence numbers at our side are known. Later * vTCPWindowInit() will be called to fill in the peer's sequence numbers, but * first wait for a SYN+ACK reply. */ - prvTCPCreateWindow( pxSocket ); + if( prvTCPCreateWindow( pxSocket ) != pdTRUE ) + { + xReturn = pdFAIL; + } } else { diff --git a/source/FreeRTOS_TCP_WIN.c b/source/FreeRTOS_TCP_WIN.c index 3a53fb058e..543ce28769 100644 --- a/source/FreeRTOS_TCP_WIN.c +++ b/source/FreeRTOS_TCP_WIN.c @@ -777,20 +777,22 @@ * @param[in] ulSequenceNumber The first sequence number. * @param[in] ulMSS The MSS of the connection. */ - void vTCPWindowCreate( TCPWindow_t * pxWindow, - uint32_t ulRxWindowLength, - uint32_t ulTxWindowLength, - uint32_t ulAckNumber, - uint32_t ulSequenceNumber, - uint32_t ulMSS ) + BaseType_t xTCPWindowCreate( TCPWindow_t * pxWindow, + uint32_t ulRxWindowLength, + uint32_t ulTxWindowLength, + uint32_t ulAckNumber, + uint32_t ulSequenceNumber, + uint32_t ulMSS ) { + BaseType_t xReturn = pdPASS; + /* Create and initialize a window. */ #if ( ipconfigUSE_TCP_WIN == 1 ) { if( xTCPSegments == NULL ) { - ( void ) prvCreateSectors(); + xReturn = prvCreateSectors(); } vListInitialise( &( pxWindow->xTxSegments ) ); @@ -804,7 +806,7 @@ if( xTCPWindowLoggingLevel != 0 ) { - FreeRTOS_debug_printf( ( "vTCPWindowCreate: for WinLen = Rx/Tx: %u/%u\n", + FreeRTOS_debug_printf( ( "xTCPWindowCreate: for WinLen = Rx/Tx: %u/%u\n", ( unsigned ) ulRxWindowLength, ( unsigned ) ulTxWindowLength ) ); } @@ -812,6 +814,8 @@ pxWindow->xSize.ulTxWindowLength = ulTxWindowLength; vTCPWindowInit( pxWindow, ulAckNumber, ulSequenceNumber, ulMSS ); + + return xReturn; } /*-----------------------------------------------------------*/ diff --git a/source/include/FreeRTOS_TCP_Transmission.h b/source/include/FreeRTOS_TCP_Transmission.h index ab1eae67b2..df8f4824be 100644 --- a/source/include/FreeRTOS_TCP_Transmission.h +++ b/source/include/FreeRTOS_TCP_Transmission.h @@ -105,7 +105,7 @@ BaseType_t prvTCPPrepareConnect_IPV6( FreeRTOS_Socket_t * pxSocket ); /* * Initialise the data structures which keep track of the TCP windowing system. */ -void prvTCPCreateWindow( FreeRTOS_Socket_t * pxSocket ); +BaseType_t prvTCPCreateWindow( FreeRTOS_Socket_t * pxSocket ); /* * Set the initial properties in the options fields, like the preferred diff --git a/source/include/FreeRTOS_TCP_WIN.h b/source/include/FreeRTOS_TCP_WIN.h index 787717aa35..36ea00cc14 100644 --- a/source/include/FreeRTOS_TCP_WIN.h +++ b/source/include/FreeRTOS_TCP_WIN.h @@ -148,12 +148,12 @@ typedef struct xTCP_WINDOW *=============================================================================*/ /* Create and initialize a window */ -void vTCPWindowCreate( TCPWindow_t * pxWindow, - uint32_t ulRxWindowLength, - uint32_t ulTxWindowLength, - uint32_t ulAckNumber, - uint32_t ulSequenceNumber, - uint32_t ulMSS ); +BaseType_t xTCPWindowCreate( TCPWindow_t * pxWindow, + uint32_t ulRxWindowLength, + uint32_t ulTxWindowLength, + uint32_t ulAckNumber, + uint32_t ulSequenceNumber, + uint32_t ulMSS ); /* Destroy a window (always returns NULL) * It will free some resources: a collection of segments */ diff --git a/test/unit-test/FreeRTOS_TCP_State_Handling_IPv4/FreeRTOS_TCP_State_Handling_IPv4_utest.c b/test/unit-test/FreeRTOS_TCP_State_Handling_IPv4/FreeRTOS_TCP_State_Handling_IPv4_utest.c index acf161694a..03d81f9f32 100644 --- a/test/unit-test/FreeRTOS_TCP_State_Handling_IPv4/FreeRTOS_TCP_State_Handling_IPv4_utest.c +++ b/test/unit-test/FreeRTOS_TCP_State_Handling_IPv4/FreeRTOS_TCP_State_Handling_IPv4_utest.c @@ -122,7 +122,7 @@ void test_prvHandleListen_IPV4_ReuseSocket( void ) ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 1000 ); uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv4_HEADER ); prvSocketSetMSS_ExpectAnyArgs(); - prvTCPCreateWindow_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); vTCPStateChange_Ignore(); pxReturn = prvHandleListen_IPV4( pxSocket, pxNetworkBuffer ); @@ -131,6 +131,38 @@ void test_prvHandleListen_IPV4_ReuseSocket( void ) TEST_ASSERT_EQUAL( 1000, pxReturn->u.xTCP.xTCPWindow.ulOurSequenceNumber ); } +/** + * @brief Flag of reuse socket is enabled and create TCP window failed. + */ +void test_prvHandleListen_IPV4_ReuseSocket_CreateWindowFailed( void ) +{ + FreeRTOS_Socket_t * pxReturn = NULL; + NetworkEndPoint_t xEndPoint = { 0 }; + + xEndPoint.ipv4_settings.ulIPAddress = 0x0800a8c0; + + pxSocket = &xSocket; + + pxNetworkBuffer = &xNetworkBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; + pxNetworkBuffer->pxEndPoint = &xEndPoint; + + TCPPacket_t * pxTCPPacket = ( ( TCPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); + pxTCPPacket->xIPHeader.ulDestinationIPAddress = 0x0800a8c0; + + pxSocket->u.xTCP.bits.bReuseSocket = pdTRUE; + + ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 1000 ); + uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv4_HEADER ); + prvSocketSetMSS_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdFAIL ); + vTCPStateChange_Ignore(); + + pxReturn = prvHandleListen_IPV4( pxSocket, pxNetworkBuffer ); + + TEST_ASSERT_EQUAL( NULL, pxReturn ); +} + /** * @brief Number of child socket is beyond limitation. */ @@ -191,7 +223,7 @@ void test_prvHandleListen_IPV4_NewSocketGood( void ) prvTCPSocketCopy_ExpectAndReturn( &MockReturnSocket, pxSocket, pdTRUE ); uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv4_HEADER ); prvSocketSetMSS_ExpectAnyArgs(); - prvTCPCreateWindow_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); vTCPStateChange_ExpectAnyArgs(); pxReturn = prvHandleListen_IPV4( pxSocket, pxNetworkBuffer ); @@ -200,6 +232,43 @@ void test_prvHandleListen_IPV4_NewSocketGood( void ) TEST_ASSERT_EQUAL( 1000, pxReturn->u.xTCP.xTCPWindow.ulOurSequenceNumber ); } +/** + * @brief Create TCP window failed. + */ +void test_prvHandleListen_IPV4_NewSocket_CreateWindowFailed( void ) +{ + FreeRTOS_Socket_t * pxReturn = NULL; + FreeRTOS_Socket_t MockReturnSocket; + NetworkEndPoint_t xEndPoint = { 0 }; + + xEndPoint.ipv4_settings.ulIPAddress = 0x0800a8c0; + + pxSocket = &xSocket; + + pxNetworkBuffer = &xNetworkBuffer; + pxNetworkBuffer->pucEthernetBuffer = ucEthernetBuffer; + pxNetworkBuffer->pxEndPoint = &xEndPoint; + + TCPPacket_t * pxTCPPacket = ( ( TCPPacket_t * ) pxNetworkBuffer->pucEthernetBuffer ); + pxTCPPacket->xIPHeader.ulDestinationIPAddress = 0x0800a8c0; + + pxSocket->u.xTCP.bits.bReuseSocket = pdFALSE; + pxSocket->u.xTCP.usChildCount = 1; + pxSocket->u.xTCP.usBacklog = 9; + + ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 1000 ); + FreeRTOS_socket_ExpectAnyArgsAndReturn( &MockReturnSocket ); + prvTCPSocketCopy_ExpectAndReturn( &MockReturnSocket, pxSocket, pdTRUE ); + uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv4_HEADER ); + prvSocketSetMSS_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdFAIL ); + vSocketClose_ExpectAndReturn( &MockReturnSocket, NULL ); + + pxReturn = prvHandleListen_IPV4( pxSocket, pxNetworkBuffer ); + + TEST_ASSERT_EQUAL( NULL, pxReturn ); +} + /** * @brief Happy path with valid data length. */ @@ -230,7 +299,7 @@ void test_prvHandleListen_IPV4_NewSocketGoodValidDataLength( void ) prvTCPSocketCopy_ExpectAndReturn( &MockReturnSocket, pxSocket, pdTRUE ); uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv4_HEADER ); prvSocketSetMSS_ExpectAnyArgs(); - prvTCPCreateWindow_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); vTCPStateChange_ExpectAnyArgs(); pxReturn = prvHandleListen_IPV4( pxSocket, pxNetworkBuffer ); diff --git a/test/unit-test/FreeRTOS_TCP_State_Handling_IPv6/FreeRTOS_TCP_State_Handling_IPv6_utest.c b/test/unit-test/FreeRTOS_TCP_State_Handling_IPv6/FreeRTOS_TCP_State_Handling_IPv6_utest.c index 0c0897b309..2c7b2499db 100644 --- a/test/unit-test/FreeRTOS_TCP_State_Handling_IPv6/FreeRTOS_TCP_State_Handling_IPv6_utest.c +++ b/test/unit-test/FreeRTOS_TCP_State_Handling_IPv6/FreeRTOS_TCP_State_Handling_IPv6_utest.c @@ -201,7 +201,7 @@ void test_prvHandleListen_IPV6_ReuseSocket( void ) uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv6_HEADER ); prvSocketSetMSS_ExpectAnyArgs(); - prvTCPCreateWindow_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); vTCPStateChange_Expect( NULL, eSYN_FIRST ); vTCPStateChange_IgnoreArg_pxSocket(); @@ -210,6 +210,42 @@ void test_prvHandleListen_IPV6_ReuseSocket( void ) TEST_ASSERT_EQUAL( pxSocket, pxReturn ); } +/** + * @brief Reuse bit is set in socket handler but the TCP window creation + * fails. + */ +void test_prvHandleListen_IPV6_ReuseSocket_CreateWindowFails( void ) +{ + FreeRTOS_Socket_t * pxReturn; + TCPPacket_IPv6_t * pxTCPPacket = NULL; + uint32_t ulRandomReturn = 0x12345678; + + pxSocket = &xSocket; + pxNetworkBuffer = &xNetworkBuffer; + pxEndPoint = &xEndPoint; + + pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer; + pxNetworkBuffer->pxEndPoint = pxEndPoint; + + /* Set same IPv6 address to endpoint & buffer. */ + pxTCPPacket = ( TCPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer; + memcpy( pxTCPPacket->xIPHeader.xDestinationAddress.ucBytes, xIPv6Address.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); + memcpy( pxEndPoint->ipv6_settings.xIPAddress.ucBytes, xIPv6Address.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); + + xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdPASS ); + xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandomReturn, sizeof( ulRandomReturn ) ); + + pxSocket->u.xTCP.bits.bReuseSocket = pdTRUE; + + uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv6_HEADER ); + prvSocketSetMSS_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdFAIL ); + + pxReturn = prvHandleListen_IPV6( pxSocket, pxNetworkBuffer ); + + TEST_ASSERT_EQUAL( NULL, pxReturn ); +} + /** * @brief Number of child socket is beyond limitation. */ @@ -396,7 +432,7 @@ void test_prvHandleListen_IPV6_NewSocketGood( void ) prvTCPSocketCopy_ExpectAndReturn( pxChildSocket, pxSocket, pdTRUE ); uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv6_HEADER ); prvSocketSetMSS_ExpectAnyArgs(); - prvTCPCreateWindow_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); vTCPStateChange_Expect( NULL, eSYN_FIRST ); vTCPStateChange_IgnoreArg_pxSocket(); @@ -408,6 +444,54 @@ void test_prvHandleListen_IPV6_NewSocketGood( void ) TEST_ASSERT_EQUAL_MEMORY( xIPv6Address.ucBytes, pxReturn->u.xTCP.xRemoteIP.xIP_IPv6.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); } +/** + * @brief Create TCP window fails + */ +void test_prvHandleListen_IPV6_CreateWindowFails( void ) +{ + FreeRTOS_Socket_t * pxReturn; + TCPPacket_IPv6_t * pxTCPPacket = NULL; + uint32_t ulRandomReturn = 0x12345678; + FreeRTOS_Socket_t xChildSocket, * pxChildSocket; + uint16_t usSrcPort = 0x1234; + + pxSocket = &xSocket; + pxNetworkBuffer = &xNetworkBuffer; + pxEndPoint = &xEndPoint; + + pxNetworkBuffer->pucEthernetBuffer = pucEthernetBuffer; + pxNetworkBuffer->pxEndPoint = pxEndPoint; + + /* Set same IPv6 address to endpoint & buffer. */ + pxTCPPacket = ( TCPPacket_IPv6_t * ) pxNetworkBuffer->pucEthernetBuffer; + pxTCPPacket->xTCPHeader.usSourcePort = FreeRTOS_htons( usSrcPort ); + memcpy( pxTCPPacket->xIPHeader.xSourceAddress.ucBytes, xIPv6Address.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); + memcpy( pxTCPPacket->xIPHeader.xDestinationAddress.ucBytes, xIPv6Address.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); + memcpy( pxEndPoint->ipv6_settings.xIPAddress.ucBytes, xIPv6Address.ucBytes, ipSIZE_OF_IPv6_ADDRESS ); + + xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdPASS ); + xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandomReturn, sizeof( ulRandomReturn ) ); + + pxSocket->u.xTCP.bits.bReuseSocket = pdFALSE; + pxSocket->u.xTCP.usChildCount = 1; + pxSocket->u.xTCP.usBacklog = 9; + + memset( &xChildSocket, 0, sizeof( xChildSocket ) ); + pxChildSocket = &xChildSocket; + + FreeRTOS_socket_ExpectAndReturn( FREERTOS_AF_INET6, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP, pxChildSocket ); + prvTCPSocketCopy_ExpectAndReturn( pxChildSocket, pxSocket, pdTRUE ); + uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv6_HEADER ); + prvSocketSetMSS_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdFAIL ); + vSocketClose_ExpectAndReturn( pxChildSocket, NULL ); + + pxReturn = prvHandleListen_IPV6( pxSocket, pxNetworkBuffer ); + + TEST_ASSERT_EQUAL( NULL, pxReturn ); +} + + /** * @brief Happy path with valid data length. */ @@ -448,7 +532,7 @@ void test_prvHandleListen_IPV6_NewSocketGoodValidDataLength( void ) prvTCPSocketCopy_ExpectAndReturn( pxChildSocket, pxSocket, pdTRUE ); uxIPHeaderSizePacket_ExpectAndReturn( pxNetworkBuffer, ipSIZE_OF_IPv6_HEADER ); prvSocketSetMSS_ExpectAnyArgs(); - prvTCPCreateWindow_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); vTCPStateChange_Expect( NULL, eSYN_FIRST ); vTCPStateChange_IgnoreArg_pxSocket(); diff --git a/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c b/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c index 99b3bbc395..24ceff7369 100644 --- a/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c +++ b/test/unit-test/FreeRTOS_TCP_Transmission/FreeRTOS_TCP_Transmission_utest.c @@ -107,7 +107,7 @@ void test_prvTCPMakeSurePrepared_NotPrepared( void ) eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 1000 ); prvSocketSetMSS_ExpectAnyArgs(); - vTCPWindowCreate_ExpectAnyArgs(); + xTCPWindowCreate_ExpectAnyArgsAndReturn( pdPASS ); xResult = prvTCPMakeSurePrepared( pxSocket ); TEST_ASSERT_EQUAL( pdTRUE, xResult ); @@ -1193,7 +1193,7 @@ void test_prvTCPPrepareConnect_Ready( void ) eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 0x11111111 ); prvSocketSetMSS_ExpectAnyArgs(); - vTCPWindowCreate_ExpectAnyArgs(); + xTCPWindowCreate_ExpectAnyArgsAndReturn( pdPASS ); Return = prvTCPPrepareConnect( pxSocket ); TEST_ASSERT_EQUAL( pdTRUE, Return ); @@ -1201,6 +1201,26 @@ void test_prvTCPPrepareConnect_Ready( void ) TEST_ASSERT_EQUAL( 0, pxSocket->u.xTCP.ucRepCount ); } +/* test for prvTCPPrepareConnect function, TCP window creation fails. */ +void test_prvTCPPrepareConnect_Ready_TCPWindowCreateFail( void ) +{ + BaseType_t Return = pdFALSE; + + pxSocket = &xSocket; + + pxSocket->u.xTCP.ucRepCount = 0; + pxSocket->u.xTCP.bits.bConnPrepared = pdFALSE; + pxSocket->bits.bIsIPv6 = pdFALSE; + + eARPGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 0x11111111 ); + prvSocketSetMSS_ExpectAnyArgs(); + xTCPWindowCreate_ExpectAnyArgsAndReturn( pdFAIL ); + + Return = prvTCPPrepareConnect( pxSocket ); + TEST_ASSERT_EQUAL( pdFAIL, Return ); +} + /* test for prvTCPPrepareConnect function */ void test_prvTCPPrepareConnect_No_Arp_Entry( void ) { diff --git a/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_stubs.c b/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_stubs.c index 63e4450285..b53a945ee6 100644 --- a/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_stubs.c +++ b/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_stubs.c @@ -71,13 +71,6 @@ void prvTCPReturn_SetSequenceNumber( FreeRTOS_Socket_t * pxSocket, { } -/* - * Initialise the data structures which keep track of the TCP windowing system. - */ -void prvTCPCreateWindow( FreeRTOS_Socket_t * pxSocket ) -{ -} - /* * Return or send a packet to the other party. */ diff --git a/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_utest.c b/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_utest.c index 70aacd374c..243e9a1451 100644 --- a/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_utest.c +++ b/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/FreeRTOS_TCP_Transmission_IPv6_utest.c @@ -46,6 +46,8 @@ #include "mock_FreeRTOS_TCP_Utils.h" #include "mock_FreeRTOS_TCP_State_Handling.h" #include "mock_FreeRTOS_ND.h" +#include "mock_TCP_Transmission_IPv6_list_macros.h" + #include "FreeRTOS_TCP_Transmission.h" #include "FreeRTOS_TCP_Transmission_IPv6_stubs.c" @@ -462,6 +464,7 @@ void test_prvTCPPrepareConnect_IPV6_CacheMiss_ValidEP( void ) pxGetNetworkBufferWithDescriptor_ExpectAnyArgsAndReturn( NULL ); prvSocketSetMSS_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); xReturn = prvTCPPrepareConnect_IPV6( pxSocket ); @@ -490,6 +493,7 @@ void test_prvTCPPrepareConnect_IPV6_DefaultCase_ValidEP( void ) vNDSendNeighbourSolicitation_ExpectAnyArgs(); prvSocketSetMSS_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); xReturn = prvTCPPrepareConnect_IPV6( pxSocket ); @@ -519,6 +523,7 @@ void test_prvTCPPrepareConnect_IPV6_HappyPath_IPv4( void ) ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 10 ); prvSocketSetMSS_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); xReturn = prvTCPPrepareConnect_IPV6( pxSocket ); @@ -547,6 +552,7 @@ void test_prvTCPPrepareConnect_IPV6_HappyPath_IPv6( void ) ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 10 ); prvSocketSetMSS_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdPASS ); xReturn = prvTCPPrepareConnect_IPV6( pxSocket ); @@ -554,6 +560,34 @@ void test_prvTCPPrepareConnect_IPV6_HappyPath_IPv6( void ) TEST_ASSERT_EQUAL_MEMORY( pxSocket->pxEndPoint, pxEndPoint, sizeof( NetworkEndPoint_t ) ); } +/** + * @brief This function validates successfully created a + * packet but the TCP window creation fails. + */ +void test_prvTCPPrepareConnect_IPV6_CreateTCPWindowFails( void ) +{ + FreeRTOS_Socket_t xSocket, * pxSocket = &xSocket; + NetworkEndPoint_t xEndPoint, * pxEndPoint = &xEndPoint; + NetworkBufferDescriptor_t xNetworkBuffer; + BaseType_t xReturn = pdFALSE; + + memset( pxEndPoint, 0, sizeof( NetworkEndPoint_t ) ); + memset( &xNetworkBuffer, 0, sizeof( NetworkBufferDescriptor_t ) ); + pxSocket->bits.bIsIPv6 = 1; + eNDGetCacheEntry_ExpectAnyArgsAndReturn( eARPCacheHit ); + eNDGetCacheEntry_ReturnThruPtr_ppxEndPoint( &pxEndPoint ); + + uxIPHeaderSizeSocket_ExpectAnyArgsAndReturn( ipSIZE_OF_IPv6_HEADER ); + ulApplicationGetNextSequenceNumber_ExpectAnyArgsAndReturn( 10 ); + + prvSocketSetMSS_ExpectAnyArgs(); + prvTCPCreateWindow_ExpectAnyArgsAndReturn( pdFAIL ); + + xReturn = prvTCPPrepareConnect_IPV6( pxSocket ); + + TEST_ASSERT_EQUAL( pdFAIL, xReturn ); +} + /** * @brief This function validates sending a TCP protocol control packet, * when an un synchronised packet is received. diff --git a/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/TCP_Transmission_IPv6_list_macros.h b/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/TCP_Transmission_IPv6_list_macros.h new file mode 100644 index 0000000000..e721f55b85 --- /dev/null +++ b/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/TCP_Transmission_IPv6_list_macros.h @@ -0,0 +1,37 @@ +/* + * FreeRTOS+TCP + * Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * http://aws.amazon.com/freertos + * http://www.FreeRTOS.org + */ +#ifndef LIST_MACRO_H +#define LIST_MACRO_H + +#include +#include +#include +#include + +BaseType_t prvTCPCreateWindow( FreeRTOS_Socket_t * pxSocket ); + +#endif /* ifndef LIST_MACRO_H */ diff --git a/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/ut.cmake b/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/ut.cmake index df5df3c5ac..47205d3a6c 100644 --- a/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/ut.cmake +++ b/test/unit-test/FreeRTOS_TCP_Transmission_IPv6/ut.cmake @@ -21,6 +21,7 @@ list(APPEND mock_list "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_TCP_State_Handling.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/FreeRTOS_IP_Private.h" "${CMAKE_BINARY_DIR}/Annexed_TCP/NetworkBufferManagement.h" + "${MODULE_ROOT_DIR}/test/unit-test/${project_name}/TCP_Transmission_IPv6_list_macros.h" ) set(mock_include_list "") diff --git a/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_utest.c b/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_utest.c index 99e800e412..365f450201 100644 --- a/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_utest.c +++ b/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_utest.c @@ -242,7 +242,7 @@ void test_vTCPWindowDestroy_list_no_segment_container( void ) vTCPWindowDestroy( &xWindow ); } -void test_vTCPWindowCreate_success( void ) +void test_xTCPWindowCreate_success( void ) { TCPWindow_t xWindow = { 0 }; uint32_t ulRxWindowLength = 0; @@ -250,6 +250,7 @@ void test_vTCPWindowCreate_success( void ) uint32_t ulAckNumber = 0; uint32_t ulSequenceNumber = 0; uint32_t ulMSS = 0; + BaseType_t xReturn; void * mlc = malloc( ipconfigTCP_WIN_SEG_COUNT * sizeof( xTCPSegments[ 0 ] ) ); @@ -270,16 +271,48 @@ void test_vTCPWindowCreate_success( void ) vListInitialise_ExpectAnyArgs(); - vTCPWindowCreate( &xWindow, - ulRxWindowLength, - ulTxWindowLength, - ulAckNumber, - ulSequenceNumber, - ulMSS ); + xReturn = xTCPWindowCreate( &xWindow, + ulRxWindowLength, + ulTxWindowLength, + ulAckNumber, + ulSequenceNumber, + ulMSS ); + TEST_ASSERT_EQUAL( pdPASS, xReturn ); free( mlc ); } -void test_vTCPWindowCreate_tcp_segment_null( void ) +void test_xTCPWindowCreate_AllocationFailed( void ) +{ + TCPWindow_t xWindow = { 0 }; + uint32_t ulRxWindowLength = 0; + uint32_t ulTxWindowLength = 0; + uint32_t ulAckNumber = 0; + uint32_t ulSequenceNumber = 0; + uint32_t ulMSS = 0; + BaseType_t xReturn; + + /* ->prvCreateSectors */ + vListInitialise_ExpectAnyArgs(); + pvPortMalloc_ExpectAnyArgsAndReturn( NULL ); + + /* back */ + vListInitialise_ExpectAnyArgs(); + vListInitialise_ExpectAnyArgs(); + vListInitialise_ExpectAnyArgs(); + vListInitialise_ExpectAnyArgs(); + vListInitialise_ExpectAnyArgs(); + + + xReturn = xTCPWindowCreate( &xWindow, + ulRxWindowLength, + ulTxWindowLength, + ulAckNumber, + ulSequenceNumber, + ulMSS ); + TEST_ASSERT_EQUAL( pdFAIL, xReturn ); +} + +void test_xTCPWindowCreate_tcp_segment_null( void ) { TCPWindow_t xWindow = { 0 }; uint32_t ulRxWindowLength = 0; @@ -287,6 +320,7 @@ void test_vTCPWindowCreate_tcp_segment_null( void ) uint32_t ulAckNumber = 0; uint32_t ulSequenceNumber = 0; uint32_t ulMSS = 0; + BaseType_t xReturn; /* ->prvCreateSectors */ vListInitialise_ExpectAnyArgs(); @@ -299,15 +333,16 @@ void test_vTCPWindowCreate_tcp_segment_null( void ) vListInitialise_ExpectAnyArgs(); - vTCPWindowCreate( &xWindow, - ulRxWindowLength, - ulTxWindowLength, - ulAckNumber, - ulSequenceNumber, - ulMSS ); + xReturn = xTCPWindowCreate( &xWindow, + ulRxWindowLength, + ulTxWindowLength, + ulAckNumber, + ulSequenceNumber, + ulMSS ); + TEST_ASSERT_EQUAL( pdFAIL, xReturn ); } -void test_vTCPWindowCreate_null_tcpSegment( void ) +void test_xTCPWindowCreate_null_tcpSegment( void ) { TCPWindow_t xWindow = { 0 }; uint32_t ulRxWindowLength = 0; @@ -315,6 +350,7 @@ void test_vTCPWindowCreate_null_tcpSegment( void ) uint32_t ulAckNumber = 0; uint32_t ulSequenceNumber = 0; uint32_t ulMSS = 0; + BaseType_t xReturn; xTCPSegments = ( TCPSegment_t * ) 32; @@ -324,12 +360,13 @@ void test_vTCPWindowCreate_null_tcpSegment( void ) vListInitialise_ExpectAnyArgs(); vListInitialise_ExpectAnyArgs(); - vTCPWindowCreate( &xWindow, - ulRxWindowLength, - ulTxWindowLength, - ulAckNumber, - ulSequenceNumber, - ulMSS ); + xReturn = xTCPWindowCreate( &xWindow, + ulRxWindowLength, + ulTxWindowLength, + ulAckNumber, + ulSequenceNumber, + ulMSS ); + TEST_ASSERT_EQUAL( pdPASS, xReturn ); TEST_ASSERT_EQUAL( ulRxWindowLength, xWindow.xSize.ulRxWindowLength ); TEST_ASSERT_EQUAL( ulTxWindowLength, xWindow.xSize.ulTxWindowLength ); } From 0c8210f450a1bdc27416413c51e82a5b0e4dbe80 Mon Sep 17 00:00:00 2001 From: Tony Josi Date: Mon, 17 Jun 2024 09:30:09 +0530 Subject: [PATCH 03/15] Handle malloc failure in dns setcallback (#1155) * Handle malloc failure in xDNSSetCallBack * Fix UTs and CBMC * Fix formatting * Fix merge conflichts --- source/FreeRTOS_DNS.c | 24 ++++-- source/FreeRTOS_DNS_Callback.c | 18 +++-- source/include/FreeRTOS_DNS_Callback.h | 12 +-- .../DNSgetHostByName_cancel_harness.c | 15 ++-- .../FreeRTOS_DNS/FreeRTOS_DNS_utest.c | 76 ++++++++++++++----- .../FreeRTOS_DNS_Callback_utest.c | 18 +++-- 6 files changed, 109 insertions(+), 54 deletions(-) diff --git a/source/FreeRTOS_DNS.c b/source/FreeRTOS_DNS.c index b29eb0cfe5..7ebda549a6 100644 --- a/source/FreeRTOS_DNS.c +++ b/source/FreeRTOS_DNS.c @@ -608,6 +608,10 @@ BaseType_t xHasRandom = pdFALSE; TickType_t uxIdentifier = 0U; + #if ( ipconfigDNS_USE_CALLBACKS == 1 ) + BaseType_t xReturnSetCallback = pdPASS; + #endif + #if ( ipconfigUSE_DNS_CACHE != 0 ) BaseType_t xLengthOk = pdFALSE; #endif @@ -690,12 +694,12 @@ if( xHasRandom != pdFALSE ) { uxReadTimeOut_ticks = 0U; - vDNSSetCallBack( pcHostName, - pvSearchID, - pCallbackFunction, - uxTimeout, - ( TickType_t ) uxIdentifier, - ( xFamily == FREERTOS_AF_INET6 ) ? pdTRUE : pdFALSE ); + xReturnSetCallback = xDNSSetCallBack( pcHostName, + pvSearchID, + pCallbackFunction, + uxTimeout, + ( TickType_t ) uxIdentifier, + ( xFamily == FREERTOS_AF_INET6 ) ? pdTRUE : pdFALSE ); } } else /* When ipconfigDNS_USE_CALLBACKS enabled, ppxAddressInfo is always non null. */ @@ -707,7 +711,13 @@ } #endif /* if ( ipconfigDNS_USE_CALLBACKS == 1 ) */ - if( ( ulIPAddress == 0U ) && ( xHasRandom != pdFALSE ) ) + if( ( ulIPAddress == 0U ) && + + #if ( ipconfigDNS_USE_CALLBACKS == 1 ) + ( xReturnSetCallback == pdPASS ) && + #endif + + ( xHasRandom != pdFALSE ) ) { ulIPAddress = prvGetHostByName( pcHostName, uxIdentifier, diff --git a/source/FreeRTOS_DNS_Callback.c b/source/FreeRTOS_DNS_Callback.c index 6aaf7172df..5a040c90be 100644 --- a/source/FreeRTOS_DNS_Callback.c +++ b/source/FreeRTOS_DNS_Callback.c @@ -129,13 +129,14 @@ * @param[in] uxIdentifier Random number used as ID in the DNS message. * @param[in] xIsIPv6 pdTRUE if the address type should be IPv6. */ - void vDNSSetCallBack( const char * pcHostName, - void * pvSearchID, - FOnDNSEvent pCallbackFunction, - TickType_t uxTimeout, - TickType_t uxIdentifier, - BaseType_t xIsIPv6 ) + BaseType_t xDNSSetCallBack( const char * pcHostName, + void * pvSearchID, + FOnDNSEvent pCallbackFunction, + TickType_t uxTimeout, + TickType_t uxIdentifier, + BaseType_t xIsIPv6 ) { + BaseType_t xReturn = pdPASS; size_t lLength = strlen( pcHostName ); /* MISRA Ref 4.12.1 [Use of dynamic memory]. */ @@ -171,9 +172,12 @@ } else { - FreeRTOS_debug_printf( ( " vDNSSetCallBack : Could not allocate memory: %u bytes", + xReturn = pdFAIL; + FreeRTOS_debug_printf( ( " xDNSSetCallBack : Could not allocate memory: %u bytes", ( unsigned ) ( sizeof( *pxCallback ) + lLength ) ) ); } + + return xReturn; } /*-----------------------------------------------------------*/ diff --git a/source/include/FreeRTOS_DNS_Callback.h b/source/include/FreeRTOS_DNS_Callback.h index 81b40960c6..94955c9252 100644 --- a/source/include/FreeRTOS_DNS_Callback.h +++ b/source/include/FreeRTOS_DNS_Callback.h @@ -53,12 +53,12 @@ BaseType_t xDNSDoCallback( ParseSet_t * pxSet, struct freertos_addrinfo * pxAddress ); - void vDNSSetCallBack( const char * pcHostName, - void * pvSearchID, - FOnDNSEvent pCallbackFunction, - TickType_t uxTimeout, - TickType_t uxIdentifier, - BaseType_t xIsIPv6 ); + BaseType_t xDNSSetCallBack( const char * pcHostName, + void * pvSearchID, + FOnDNSEvent pCallbackFunction, + TickType_t uxTimeout, + TickType_t uxIdentifier, + BaseType_t xIsIPv6 ); void vDNSCheckCallBack( void * pvSearchID ); diff --git a/test/cbmc/proofs/DNS/DNSgetHostByName_cancel/DNSgetHostByName_cancel_harness.c b/test/cbmc/proofs/DNS/DNSgetHostByName_cancel/DNSgetHostByName_cancel_harness.c index 8536a2612e..4ece6565be 100644 --- a/test/cbmc/proofs/DNS/DNSgetHostByName_cancel/DNSgetHostByName_cancel_harness.c +++ b/test/cbmc/proofs/DNS/DNSgetHostByName_cancel/DNSgetHostByName_cancel_harness.c @@ -13,12 +13,12 @@ void vDNSInitialise( void ); -void vDNSSetCallBack( const char * pcHostName, - void * pvSearchID, - FOnDNSEvent pCallbackFunction, - TickType_t xTimeout, - TickType_t xIdentifier, - BaseType_t xIsIPv6 ); +BaseType_t xDNSSetCallBack( const char * pcHostName, + void * pvSearchID, + FOnDNSEvent pCallbackFunction, + TickType_t xTimeout, + TickType_t xIdentifier, + BaseType_t xIsIPv6 ); void * safeMalloc( size_t xWantedSize ) /* Returns a NULL pointer if the wanted size is 0. */ { @@ -59,6 +59,7 @@ void harness() TickType_t xIdentifier; BaseType_t xIsIPv6; size_t len; + BaseType_t xReturn; __CPROVER_assume( len >= 0 && len <= MAX_HOSTNAME_LEN ); char * pcHostName = safeMalloc( len ); @@ -68,6 +69,6 @@ void harness() pcHostName[ len - 1 ] = NULL; } - vDNSSetCallBack( pcHostName, &pvSearchID, pCallback, xTimeout, xIdentifier, xIsIPv6 ); /* Add an item to be able to check the cancel function if the list is non-empty. */ + xReturn = xDNSSetCallBack( pcHostName, &pvSearchID, pCallback, xTimeout, xIdentifier, xIsIPv6 ); /* Add an item to be able to check the cancel function if the list is non-empty. */ FreeRTOS_gethostbyname_cancel( &pvSearchID ); } diff --git a/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c b/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c index 6daae41e46..69ef050dfe 100644 --- a/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c +++ b/test/unit-test/FreeRTOS_DNS/FreeRTOS_DNS_utest.c @@ -609,7 +609,7 @@ void test_FreeRTOS_gethostbyname_a_SetCallback( void ) FreeRTOS_inet_addr_ExpectAndReturn( GOOD_ADDRESS, 0 ); Prepare_CacheLookup_ExpectAnyArgsAndReturn( 0 ); xApplicationGetRandomNumber_IgnoreAndReturn( pdTRUE ); - vDNSSetCallBack_ExpectAnyArgs(); + xDNSSetCallBack_ExpectAnyArgsAndReturn( pdPASS ); DNS_CreateSocket_ExpectAnyArgsAndReturn( NULL ); ret = FreeRTOS_gethostbyname_a( GOOD_ADDRESS, @@ -665,7 +665,7 @@ void test_FreeRTOS_gethostbyname_a_Callback( void ) } /** - * @brief Ensures that if vDNSSetCallBack is called the client is put in + * @brief Ensures that if xDNSSetCallBack is called the client is put in * asynchronous mode, and only one retry is performed by calling * prvGetHostByNameOp instead of prvGetHostByNameOp_WithRetry */ @@ -700,7 +700,7 @@ void test_FreeRTOS_gethostbyname_a_NoCallbackRetryOnce( void ) Prepare_CacheLookup_ExpectAnyArgsAndReturn( 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnThruPtr_pulNumber( &ulNumber ); - vDNSSetCallBack_ExpectAnyArgs(); + xDNSSetCallBack_ExpectAnyArgsAndReturn( pdPASS ); /* in prvGetHostByName */ DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket ); @@ -894,7 +894,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4DomainCacheMiss_Random( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS ); DNS_CreateSocket_ExpectAndReturn( 0U, NULL ); xReturn = FreeRTOS_getaddrinfo_a( GOOD_ADDRESS, "Service", NULL, &pxAddress, dns_callback, NULL, 0U ); @@ -922,7 +922,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6DomainCacheMiss_Random( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); DNS_CreateSocket_ExpectAndReturn( 0U, NULL ); xReturn = FreeRTOS_getaddrinfo_a( GOOD_ADDRESS, "Service", pxHint, &pxAddress, dns_callback, NULL, 0U ); @@ -956,7 +956,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_EndPointNotFound( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); @@ -971,6 +971,40 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_EndPointNotFound( void ) TEST_ASSERT_EQUAL( -pdFREERTOS_ERRNO_ENOENT, xReturn ); } +/** + * @brief Try to get IP address through network but malloc fails while setting + * callback + */ +void test_FreeRTOS_getaddrinfo_a_IPv6Random_SetCallBackFails( void ) +{ + BaseType_t xReturn; + struct freertos_addrinfo xAddress, * pxAddress = &xAddress; + struct freertos_addrinfo xHint, * pxHint = &xHint; + uint32_t ulRandom = 0x1234U; + struct xSOCKET xDNSSocket; + NetworkEndPoint_t xEndPoint; + + memset( &xAddress, 0, sizeof( struct freertos_addrinfo ) ); + memset( &xHint, 0, sizeof( struct freertos_addrinfo ) ); + memset( &xDNSSocket, 0, sizeof( struct xSOCKET ) ); + memset( &xEndPoint, 0, sizeof( xEndPoint ) ); + + xEndPoint.bits.bIPv6 = pdFALSE; + + xHint.ai_family = FREERTOS_AF_INET6; + + FreeRTOS_inet_pton6_ExpectAndReturn( GOOD_ADDRESS, NULL, 0 ); + FreeRTOS_inet_pton6_IgnoreArg_pvDestination(); + Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); + xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); + xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdFAIL ); + + xReturn = FreeRTOS_getaddrinfo_a( GOOD_ADDRESS, "Service", pxHint, &pxAddress, dns_callback, NULL, 0U ); + + TEST_ASSERT_EQUAL( -pdFREERTOS_ERRNO_ENOENT, xReturn ); +} + /** * @brief IPv4 socket bind fail with domain name containing dot */ @@ -1011,7 +1045,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_BindFailWithDot( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); @@ -1080,7 +1114,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_BindFailWithDot( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); @@ -1129,7 +1163,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_BindFailWODot( void ) Prepare_CacheLookup_ExpectAndReturn( LLMNR_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE ); + xDNSSetCallBack_ExpectAndReturn( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); @@ -1177,7 +1211,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_BindFailWODot( void ) Prepare_CacheLookup_ExpectAndReturn( LLMNR_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); @@ -1219,7 +1253,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_InvalidDNSServerIndex( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); @@ -1259,7 +1293,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_InvalidDNSServerIndex( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); @@ -1298,7 +1332,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_UnknownPreference( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); @@ -1364,7 +1398,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_DNSReplySuccess( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); @@ -1533,7 +1567,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_LocalDNSSuccess( void ) Prepare_CacheLookup_ExpectAndReturn( LOCAL_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( LOCAL_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE ); + xDNSSetCallBack_ExpectAndReturn( LOCAL_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket ); @@ -1621,7 +1655,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_LocalDNSSuccess( void ) Prepare_CacheLookup_ExpectAndReturn( LOCAL_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( LOCAL_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( LOCAL_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket ); @@ -1709,7 +1743,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_LocalDNSUnknownPreference( void ) Prepare_CacheLookup_ExpectAndReturn( LOCAL_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( LOCAL_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE ); + xDNSSetCallBack_ExpectAndReturn( LOCAL_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket ); @@ -1781,7 +1815,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_LLMNRDNSSuccess( void ) Prepare_CacheLookup_ExpectAndReturn( LLMNR_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket ); @@ -1860,7 +1894,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv6Random_LLMNRDNSNoEndPoint( void ) Prepare_CacheLookup_ExpectAndReturn( LLMNR_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket ); @@ -1927,7 +1961,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_LLMNRDNSUnknownPreference( void ) Prepare_CacheLookup_ExpectAndReturn( LLMNR_ADDRESS, FREERTOS_AF_INET4, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE ); + xDNSSetCallBack_ExpectAndReturn( LLMNR_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdFALSE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAnyArgsAndReturn( &xDNSSocket ); @@ -2180,7 +2214,7 @@ void test_FreeRTOS_getaddrinfo_a_IPv4Random_PortSpecified( void ) Prepare_CacheLookup_ExpectAndReturn( GOOD_ADDRESS, FREERTOS_AF_INET6, &pxAddress, 0 ); xApplicationGetRandomNumber_ExpectAnyArgsAndReturn( pdTRUE ); xApplicationGetRandomNumber_ReturnMemThruPtr_pulNumber( &ulRandom, sizeof( uint32_t ) ); - vDNSSetCallBack_Expect( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE ); + xDNSSetCallBack_ExpectAndReturn( GOOD_ADDRESS, NULL, dns_callback, 0U, ulRandom, pdTRUE, pdPASS ); /* In prvGetHostByName */ DNS_CreateSocket_ExpectAndReturn( 0U, &xDNSSocket ); diff --git a/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c b/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c index 3a03807845..a23ee1ba6d 100644 --- a/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c +++ b/test/unit-test/FreeRTOS_DNS_Callback/FreeRTOS_DNS_Callback_utest.c @@ -205,9 +205,10 @@ void test_xDNSDoCallback_success_equal_identifier_set_timer( void ) /** * @brief Happy Path! */ -void test_vDNSSetCallback_success( void ) +void test_xDNSSetCallBack_success( void ) { void * pvSearchID = NULL; + BaseType_t xReturn; /* Expectations */ pvPortMalloc_ExpectAnyArgsAndReturn( dnsCallback ); @@ -220,21 +221,23 @@ void test_vDNSSetCallback_success( void ) xTaskResumeAll_ExpectAndReturn( pdFALSE ); /* API Call */ - vDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE ); + xReturn = xDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE ); /* Validations */ TEST_ASSERT_EQUAL( 0, strcmp( dnsCallback->pcName, "hostname" ) ); TEST_ASSERT_EQUAL( dns_callback, dnsCallback->pCallbackFunction ); TEST_ASSERT_EQUAL( pvSearchID, dnsCallback->pvSearchID ); TEST_ASSERT_EQUAL( 56, dnsCallback->uxRemainingTime ); + TEST_ASSERT_EQUAL( pdPASS, xReturn ); } /** * @brief Happy Path! */ -void test_vDNSSetCallback_success_empty_list( void ) +void test_xDNSSetCallBack_success_empty_list( void ) { void * pvSearchID = NULL; + BaseType_t xReturn; /* Expectations */ pvPortMalloc_ExpectAnyArgsAndReturn( dnsCallback ); @@ -249,27 +252,30 @@ void test_vDNSSetCallback_success_empty_list( void ) xTaskResumeAll_ExpectAndReturn( pdFALSE ); /* API Call */ - vDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE ); + xReturn = xDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE ); /* Validations */ TEST_ASSERT_EQUAL( 0, strcmp( dnsCallback->pcName, "hostname" ) ); TEST_ASSERT_EQUAL( dns_callback, dnsCallback->pCallbackFunction ); TEST_ASSERT_EQUAL( pvSearchID, dnsCallback->pvSearchID ); TEST_ASSERT_EQUAL( 56, dnsCallback->uxRemainingTime ); + TEST_ASSERT_EQUAL( pdPASS, xReturn ); } /** * @brief Memory Allocation failed */ -void test_vDNSSetCallback_malloc_failed( void ) +void test_xDNSSetCallBack_malloc_failed( void ) { void * pvSearchID = NULL; + BaseType_t xReturn; /* Expectations */ pvPortMalloc_ExpectAnyArgsAndReturn( NULL ); /* API Call */ - vDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE ); + xReturn = xDNSSetCallBack( "hostname", pvSearchID, dns_callback, 56, 123, pdFALSE ); + TEST_ASSERT_EQUAL( pdFAIL, xReturn ); } From ba4e25c350020abcb787a3a319fdf991bef70538 Mon Sep 17 00:00:00 2001 From: Tony Josi Date: Mon, 17 Jun 2024 14:11:04 +0530 Subject: [PATCH 04/15] Fix Buffer Over-Read (CWE-126) in DNS Response Parser (#1158) * Update SBOM * Rename DNS proof * Rename DNS proof * Fix DNS parse reply proof * Fix CBMC proof * Fix unit tests * Fix formatting * Fix unit tests * Update CMake * Fix build checks * Fix formatting * Remove sbom file --------- Co-authored-by: tony-josi-aws --- source/FreeRTOS_DNS_Parser.c | 2 +- .../DNS_ParseDNSReply/Configurations.json | 50 +++++ .../DNS_ParseDNSReply_harness.c | 211 ++++++++++++++++++ test/cbmc/proofs/ParseDNSReply/Makefile.json | 68 ------ .../ParseDNSReply/ParseDNSReply_harness.c | 130 ----------- .../FreeRTOS_DNS_Parser_utest.c | 4 +- 6 files changed, 263 insertions(+), 202 deletions(-) create mode 100644 test/cbmc/proofs/DNS_ParseDNSReply/Configurations.json create mode 100644 test/cbmc/proofs/DNS_ParseDNSReply/DNS_ParseDNSReply_harness.c delete mode 100644 test/cbmc/proofs/ParseDNSReply/Makefile.json delete mode 100644 test/cbmc/proofs/ParseDNSReply/ParseDNSReply_harness.c diff --git a/source/FreeRTOS_DNS_Parser.c b/source/FreeRTOS_DNS_Parser.c index d8f26c197a..0b328d16d7 100644 --- a/source/FreeRTOS_DNS_Parser.c +++ b/source/FreeRTOS_DNS_Parser.c @@ -646,7 +646,7 @@ } uxResult = DNS_SkipNameField( pxSet->pucByte, - sizeof( pxSet->pcName ) ); + pxSet->uxSourceBytesRemaining ); /* Check for a malformed response. */ if( uxResult == 0U ) diff --git a/test/cbmc/proofs/DNS_ParseDNSReply/Configurations.json b/test/cbmc/proofs/DNS_ParseDNSReply/Configurations.json new file mode 100644 index 0000000000..d228156514 --- /dev/null +++ b/test/cbmc/proofs/DNS_ParseDNSReply/Configurations.json @@ -0,0 +1,50 @@ +{ + "ENTRY": "DNS_ParseDNSReply", + "TEST_PAYLOAD_SIZE": 5, + "TEST_IPV4_PACKET_SIZE": 59, + "TEST_IPV6_PACKET_SIZE": 79, + "CBMCFLAGS": + [ + "--unwind 1", + "--unwindset DNS_ParseDNSReply.0:{TEST_PAYLOAD_SIZE}", + "--unwindset DNS_ReadNameField.0:{TEST_PAYLOAD_SIZE}", + "--unwindset DNS_ReadNameField.1:{TEST_PAYLOAD_SIZE}", + "--unwindset parseDNSAnswer.0:{TEST_PAYLOAD_SIZE}", + "--unwindset strncpy.0:{TEST_PAYLOAD_SIZE}" + ], + "OPT": + [ + "--export-file-local-symbols" + ], + "OBJS": + [ + "$(ENTRY)_harness.goto", + "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS_Parser.goto", + "$(FREERTOS_PLUS_TCP)/test/cbmc/stubs/cbmc.goto" + ], + "DEF": + [ + { + "IPv4": + [ + "TEST_PACKET_SIZE={TEST_IPV4_PACKET_SIZE}", + "ipconfigUSE_LLMNR=1", + "ipconfigUSE_MDNS=1", + "IS_TESTING_IPV6=0" + ] + }, + { + "IPv6": + [ + "TEST_PACKET_SIZE={TEST_IPV6_PACKET_SIZE}", + "ipconfigUSE_LLMNR=1", + "ipconfigUSE_MDNS=1", + "IS_TESTING_IPV6=1" + ] + } + ], + "INC": + [ + "$(FREERTOS_PLUS_TCP)/test/cbmc/include" + ] +} \ No newline at end of file diff --git a/test/cbmc/proofs/DNS_ParseDNSReply/DNS_ParseDNSReply_harness.c b/test/cbmc/proofs/DNS_ParseDNSReply/DNS_ParseDNSReply_harness.c new file mode 100644 index 0000000000..9fae89ddc8 --- /dev/null +++ b/test/cbmc/proofs/DNS_ParseDNSReply/DNS_ParseDNSReply_harness.c @@ -0,0 +1,211 @@ +/* Standard includes. */ +#include + +/* FreeRTOS includes. */ +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" +#include "list.h" +#include "semphr.h" + +/* FreeRTOS+TCP includes. */ +#include "FreeRTOS_IP.h" +#include "FreeRTOS_DNS.h" +#include "FreeRTOS_DNS_Parser.h" +#include "NetworkBufferManagement.h" +#include "NetworkInterface.h" +#include "IPTraceMacroDefaults.h" + +#include "cbmc.h" +#include "../../utility/memory_assignments.c" + +/**************************************************************** +* Signature of function under test +****************************************************************/ + +uint32_t DNS_ParseDNSReply( uint8_t * pucUDPPayloadBuffer, + size_t uxBufferLength, + struct freertos_addrinfo ** ppxAddressInfo, + BaseType_t xExpected, + uint16_t usPort ); + +NetworkBufferDescriptor_t xNetworkBuffer; +int lIsIPv6Packet; + +size_t uxIPHeaderSizePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer ) +{ + #if IS_TESTING_IPV6 + return ipSIZE_OF_IPv6_HEADER; + #else + return ipSIZE_OF_IPv4_HEADER; + #endif +} + +NetworkBufferDescriptor_t * pxUDPPayloadBuffer_to_NetworkBuffer( const void * pvBuffer ) +{ + __CPROVER_assert( pvBuffer != NULL, "Precondition: pvBuffer != NULL" ); + NetworkBufferDescriptor_t * pxRBuf; + + if( nondet_bool() ) + { + pxRBuf = NULL; + } + else + { + pxRBuf = &xNetworkBuffer; + } + + return pxRBuf; +} + +uint32_t ulChar2u32( const uint8_t * pucPtr ) +{ + __CPROVER_assert( __CPROVER_r_ok( pucPtr, 4 ), "must be 4 bytes legal address to read" ); +} + +uint16_t usChar2u16( const uint8_t * pucPtr ) +{ + __CPROVER_assert( __CPROVER_r_ok( pucPtr, 2 ), "must be 2 bytes legal address to read" ); +} + +const char * FreeRTOS_inet_ntop( BaseType_t xAddressFamily, + const void * pvSource, + char * pcDestination, + socklen_t uxSize ) +{ + __CPROVER_assert( __CPROVER_r_ok( pcDestination, uxSize ), "input buffer must be available" ); + + #if IS_TESTING_IPV6 + __CPROVER_assert( ( xAddressFamily == FREERTOS_AF_INET6 && __CPROVER_r_ok( pvSource, 16 ) ), "input address must be available" ); + #else + __CPROVER_assert( ( xAddressFamily == FREERTOS_AF_INET && __CPROVER_r_ok( pvSource, 4 ) ), "input address must be available" ); + #endif +} + +BaseType_t xApplicationDNSQueryHook_Multi( struct xNetworkEndPoint * pxEndPoint, + const char * pcName ) +{ + __CPROVER_assert( strlen( pcName ) < ipconfigDNS_CACHE_NAME_LENGTH, "The length of domain name must be less than cache size" ); +} + +void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer ) +{ + __CPROVER_assert( pxNetworkBuffer, "network descriptor must be valid." ); + __CPROVER_assert( pxNetworkBuffer->pucEthernetBuffer, "network buffer must be valid." ); + + free( pxNetworkBuffer->pucEthernetBuffer ); + free( pxNetworkBuffer ); +} + +/* The checksum generation is stubbed out since the actual checksum + * does not matter. The stub will return an indeterminate value each time. */ +uint16_t usGenerateChecksum( uint16_t usSum, + const uint8_t * pucNextData, + size_t uxByteCount ) +{ + uint16_t usReturn; + + __CPROVER_assert( __CPROVER_r_ok( pucNextData, uxByteCount ), "Data must be valid" ); + + /* Return an indeterminate value. */ + return usReturn; +} + +/* The checksum generation is stubbed out since the actual checksum + * does not matter. The stub will return an indeterminate value each time. */ +uint16_t usGenerateProtocolChecksum( const uint8_t * const pucEthernetBuffer, + size_t uxBufferLength, + BaseType_t xOutgoingPacket ) +{ + uint16_t usReturn; + + __CPROVER_assert( __CPROVER_r_ok( pucEthernetBuffer, uxBufferLength ), "Data must be valid" ); + + /* Return an indeterminate value. */ + return usReturn; +} + +/* pxDuplicateNetworkBufferWithDescriptor() is proved separately */ +NetworkBufferDescriptor_t * pxDuplicateNetworkBufferWithDescriptor( const NetworkBufferDescriptor_t * const pxNetworkBuffer, + size_t xNewLength ) +{ + NetworkBufferDescriptor_t * pxNetworkBuffer = safeMalloc( sizeof( NetworkBufferDescriptor_t ) ); + + if( ensure_memory_is_valid( pxNetworkBuffer, xNewLength ) ) + { + pxNetworkBuffer->pucEthernetBuffer = safeMalloc( xNewLength ); + __CPROVER_assume( pxNetworkBuffer->pucEthernetBuffer ); + pxNetworkBuffer->xDataLength = xNewLength; + } + + return pxNetworkBuffer; +} + +/* vReturnEthernetFrame() is proved separately */ +void vReturnEthernetFrame( NetworkBufferDescriptor_t * pxNetworkBuffer, + BaseType_t xReleaseAfterSend ) +{ + __CPROVER_assert( pxNetworkBuffer != NULL, "xNetworkBuffer != NULL" ); + __CPROVER_assert( pxNetworkBuffer->pucEthernetBuffer != NULL, "pxNetworkBuffer->pucEthernetBuffer != NULL" ); + __CPROVER_assert( __CPROVER_r_ok( pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength ), "Data must be valid" ); +} + +uint32_t parseDNSAnswer( ParseSet_t * pxSet, + struct freertos_addrinfo ** ppxAddressInfo, + size_t * uxBytesRead ) +{ + uint32_t result; + + __CPROVER_assert( __CPROVER_r_ok( pxSet->pucByte, pxSet->uxSourceBytesRemaining ), "Data must be valid" ); + + return result; +} + +/**************************************************************** +* Proof of prvParseDNSReply +****************************************************************/ + +void harness() +{ + size_t uxBufferLength; + uint16_t usPort; + struct freertos_addrinfo * pxAddressInfo; + BaseType_t xExpected; + NetworkEndPoint_t * pxNetworkEndPoint_Temp = ( NetworkEndPoint_t * ) safeMalloc( sizeof( NetworkEndPoint_t ) ); + const uint32_t ulIpv4UdpOffset = 42, ulIpv6UdpOffset = 62; + uint8_t * pPayloadBuffer; + size_t uxPayloadBufferLength; + + __CPROVER_assert( TEST_PACKET_SIZE < CBMC_MAX_OBJECT_SIZE, + "TEST_PACKET_SIZE < CBMC_MAX_OBJECT_SIZE" ); + + __CPROVER_assume( uxBufferLength < CBMC_MAX_OBJECT_SIZE ); + __CPROVER_assume( uxBufferLength <= TEST_PACKET_SIZE ); + + lIsIPv6Packet = IS_TESTING_IPV6; + + xNetworkBuffer.pucEthernetBuffer = safeMalloc( uxBufferLength ); + xNetworkBuffer.xDataLength = uxBufferLength; + xNetworkBuffer.pxEndPoint = pxNetworkEndPoint_Temp; + + __CPROVER_assume( xNetworkBuffer.pucEthernetBuffer != NULL ); + + if( lIsIPv6Packet ) + { + __CPROVER_assume( uxBufferLength >= ulIpv6UdpOffset ); /* 62 is total size of IPv4 UDP header, including ethernet, IPv6, UDP headers. */ + pPayloadBuffer = xNetworkBuffer.pucEthernetBuffer + ulIpv6UdpOffset; + uxPayloadBufferLength = uxBufferLength - ulIpv6UdpOffset; + } + else + { + __CPROVER_assume( uxBufferLength >= ulIpv4UdpOffset ); /* 42 is total size of IPv4 UDP header, including ethernet, IPv4, UDP headers. */ + pPayloadBuffer = xNetworkBuffer.pucEthernetBuffer + ulIpv4UdpOffset; + uxPayloadBufferLength = uxBufferLength - ulIpv4UdpOffset; + } + + uint32_t index = DNS_ParseDNSReply( pPayloadBuffer, + uxPayloadBufferLength, + &pxAddressInfo, + xExpected, + usPort ); +} diff --git a/test/cbmc/proofs/ParseDNSReply/Makefile.json b/test/cbmc/proofs/ParseDNSReply/Makefile.json deleted file mode 100644 index aefd62da62..0000000000 --- a/test/cbmc/proofs/ParseDNSReply/Makefile.json +++ /dev/null @@ -1,68 +0,0 @@ -# The proof depends on one parameter: -# NETWORK_BUFFER_SIZE is the size of the network buffer being parsed -# The buffer size must be bounded because we must bound the number of -# iterations loops iterating over the buffer. - -{ - "ENTRY": "ParseDNSReply", - -################################################################ -# This is the network buffer size. -# Reasonable values are size > 12 = sizeof(xDNSMessage) - "NETWORK_BUFFER_SIZE": 40, - -################################################################ -# This is the size of the buffer into which the name is copied. -# Set to any positive value. -# In the source, NAME_SIZE=254 and NETWORK_BUFFER_SIZE >> NAME_SIZE -# In the proof, NAME_SIZE >= 4 required for good coverage. - "NAME_SIZE": "10", - -################################################################ -# Loop prvParseDNSReply.0: -# file lib/FreeRTOS-Plus-TCP/source/FreeRTOS_DNS.c line 915 - "PARSELOOP0": "prvParseDNSReply.0", - -# M = sizeof( DNSMessage_t ) = 12 -# U = sizeof( uint32_t) = 4 -# Loop bound is (NETWORK_BUFFER_SIZE - M) div (U+1) + 1 tight for SIZE >= M -# Loop bound is 1 for 0 <= SIZE < M - "PARSELOOP0_UNWIND": - "__eval 1 if {NETWORK_BUFFER_SIZE} < 12 else ({NETWORK_BUFFER_SIZE} - 12) / 5 + 1", - -################################################################ -# Loop prvParseDNSReply.1: -# file lib/FreeRTOS-Plus-TCP/source/FreeRTOS_DNS.c line 989 - "PARSELOOP1": "prvParseDNSReply.1", - -# A = sizeof( DNSAnswerRecord_t ) = 10 -# M = sizeof( DNSMessage_t ) = 12 -# U = sizeof( uint32_t) = 4 -# Loop bound is (NETWORK_BUFFER_SIZE - M - A) div (A+1) + A + 1 tight -# for SIZE >= M + A -# Loop bound is (NETWORK_BUFFER_SIZE - M) + 1 for M <= SIZE < M + A -# Loop bound is 1 for 0 <= SIZE < M - "PARSELOOP1_UNWIND": - "__eval 1 if {NETWORK_BUFFER_SIZE} < 12 else ({NETWORK_BUFFER_SIZE} - 11 if {NETWORK_BUFFER_SIZE} < 22 else ({NETWORK_BUFFER_SIZE} - 12 - 10) / 11 + 11)", - -################################################################ - - "CBMCFLAGS": - [ - "--unwind 1", - "--unwindset {PARSELOOP0}:{PARSELOOP0_UNWIND},{PARSELOOP1}:{PARSELOOP1_UNWIND},prvProcessDNSCache.0:5" - ], - - "OBJS": - [ - "$(ENTRY)_harness.goto", - "$(FREERTOS_PLUS_TCP)/source/FreeRTOS_DNS.goto", - "$(FREERTOS_PLUS_TCP)/test/FreeRTOS-Kernel/tasks.goto" - ], - - "DEF": - [ - "NETWORK_BUFFER_SIZE={NETWORK_BUFFER_SIZE}", - "NAME_SIZE={NAME_SIZE}" - ] -} diff --git a/test/cbmc/proofs/ParseDNSReply/ParseDNSReply_harness.c b/test/cbmc/proofs/ParseDNSReply/ParseDNSReply_harness.c deleted file mode 100644 index 74e594fbd2..0000000000 --- a/test/cbmc/proofs/ParseDNSReply/ParseDNSReply_harness.c +++ /dev/null @@ -1,130 +0,0 @@ -/* Standard includes. */ -#include - -/* FreeRTOS includes. */ -#include "FreeRTOS.h" -#include "task.h" -#include "queue.h" -#include "list.h" -#include "semphr.h" - -/* FreeRTOS+TCP includes. */ -#include "FreeRTOS_IP.h" -#include "FreeRTOS_Sockets.h" -#include "FreeRTOS_IP_Private.h" -#include "FreeRTOS_UDP_IP.h" -#include "FreeRTOS_DNS.h" -#include "FreeRTOS_DNS_Parser.h" -#include "NetworkBufferManagement.h" -#include "NetworkInterface.h" -#include "IPTraceMacroDefaults.h" - -#include "cbmc.h" - -/**************************************************************** -* Signature of function under test -****************************************************************/ - -uint32_t prvParseDNSReply( uint8_t * pucUDPPayloadBuffer, - size_t uxBufferLength, - BaseType_t xExpected ); - -/**************************************************************** -* Abstraction of DNS_ReadNameField proved in ReadNameField -****************************************************************/ - -size_t DNS_ReadNameField( const uint8_t * pucByte, - size_t uxRemainingBytes, - char * pcName, - size_t uxDestLen ) -{ - __CPROVER_assert( NETWORK_BUFFER_SIZE < CBMC_MAX_OBJECT_SIZE, - "NETWORK_BUFFER_SIZE < CBMC_MAX_OBJECT_SIZE" ); - __CPROVER_assert( NAME_SIZE < CBMC_MAX_OBJECT_SIZE, - "NAME_SIZE < CBMC_MAX_OBJECT_SIZE" ); - __CPROVER_assert( NAME_SIZE >= 4, - "NAME_SIZE >= 4 required for good coverage." ); - - - /* Preconditions */ - __CPROVER_assert( uxRemainingBytes < CBMC_MAX_OBJECT_SIZE, - "ReadNameField: uxRemainingBytes < CBMC_MAX_OBJECT_SIZE)" ); - __CPROVER_assert( uxDestLen < CBMC_MAX_OBJECT_SIZE, - "ReadNameField: uxDestLen < CBMC_MAX_OBJECT_SIZE)" ); - - __CPROVER_assert( uxRemainingBytes <= NETWORK_BUFFER_SIZE, - "ReadNameField: uxRemainingBytes <= NETWORK_BUFFER_SIZE)" ); - - /* This precondition in the function contract for prvReadNameField - * fails because prvCheckOptions called prvReadNameField with the - * constant value 254. - * __CPROVER_assert(uxDestLen <= NAME_SIZE, - * "ReadNameField: uxDestLen <= NAME_SIZE)"); - */ - - __CPROVER_assert( pucByte != NULL, - "ReadNameField: pucByte != NULL )" ); - __CPROVER_assert( pcName != NULL, - "ReadNameField: pcName != NULL )" ); - - __CPROVER_assert( uxDestLen > 0, - "ReadNameField: uxDestLen > 0)" ); - - /* Return value */ - size_t index; - - /* Postconditions */ - __CPROVER_assume( index <= uxDestLen + 1 && index <= uxRemainingBytes ); - - return index; -} - -/**************************************************************** -* Abstraction of DNS_SkipNameField proved in SkipNameField -****************************************************************/ - -size_t DNS_SkipNameField( const uint8_t * pucByte, - size_t uxLength ) -{ - __CPROVER_assert( NETWORK_BUFFER_SIZE < CBMC_MAX_OBJECT_SIZE, - "NETWORK_BUFFER_SIZE < CBMC_MAX_OBJECT_SIZE" ); - - - /* Preconditions */ - __CPROVER_assert( uxLength < CBMC_MAX_OBJECT_SIZE, - "SkipNameField: uxLength < CBMC_MAX_OBJECT_SIZE)" ); - __CPROVER_assert( uxLength <= NETWORK_BUFFER_SIZE, - "SkipNameField: uxLength <= NETWORK_BUFFER_SIZE)" ); - __CPROVER_assert( pucByte != NULL, - "SkipNameField: pucByte != NULL)" ); - - /* Return value */ - size_t index; - - /* Postconditions */ - __CPROVER_assume( index <= uxLength ); - - return index; -} - -/**************************************************************** -* Proof of prvParseDNSReply -****************************************************************/ - -void harness() -{ - size_t uxBufferLength; - BaseType_t xExpected; - uint8_t * pucUDPPayloadBuffer = malloc( uxBufferLength ); - - __CPROVER_assert( NETWORK_BUFFER_SIZE < CBMC_MAX_OBJECT_SIZE, - "NETWORK_BUFFER_SIZE < CBMC_MAX_OBJECT_SIZE" ); - - __CPROVER_assume( uxBufferLength < CBMC_MAX_OBJECT_SIZE ); - __CPROVER_assume( uxBufferLength <= NETWORK_BUFFER_SIZE ); - __CPROVER_assume( pucUDPPayloadBuffer != NULL ); - - uint32_t index = prvParseDNSReply( pucUDPPayloadBuffer, - uxBufferLength, - xExpected ); -} diff --git a/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c b/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c index 61d2babcae..cee6d148a6 100644 --- a/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c +++ b/test/unit-test/FreeRTOS_DNS_Parser/FreeRTOS_DNS_Parser_utest.c @@ -3064,12 +3064,10 @@ void test_parseDNSAnswer_recordNOTstored_gt_count_diffUsType( void ) pxDNSAnswerRecord->usDataLength = FreeRTOS_htons( ipSIZE_OF_IPv4_ADDRESS ); pxDNSAnswerRecord->usType = ( dnsTYPE_AAAA_HOST ); - usChar2u16_ExpectAnyArgsAndReturn( dnsTYPE_AAAA_HOST ); /* usType */ - ret = parseDNSAnswer( &xSet, &pxAddressInfo, &uxBytesRead ); TEST_ASSERT_EQUAL( 0, ret ); - TEST_ASSERT_EQUAL( 40, uxBytesRead ); + TEST_ASSERT_EQUAL( 0, uxBytesRead ); } /** From b79b2e0f8d4d726c5487722b0a51f0ce4060c330 Mon Sep 17 00:00:00 2001 From: Michael Tautschnig Date: Mon, 17 Jun 2024 11:03:35 +0200 Subject: [PATCH 05/15] Bump CBMC version to 5.95.1 (#1153) This will make proofs use the latest stable release of CBMC. Co-authored-by: Nikhil Kamath <110539926+amazonKamath@users.noreply.github.com> Co-authored-by: Tony Josi --- .github/workflows/ci.yml | 2 +- test/cbmc/proofs/Socket/lTCPAddRxdata/TCPAddRxdata_harness.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4a1de02ec8..ba6a8c1660 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -406,7 +406,7 @@ jobs: - name: Set up CBMC runner uses: FreeRTOS/CI-CD-Github-Actions/set_up_cbmc_runner@main with: - cbmc_version: "5.61.0" + cbmc_version: "5.95.1" - env: stepName: Install Dependencies diff --git a/test/cbmc/proofs/Socket/lTCPAddRxdata/TCPAddRxdata_harness.c b/test/cbmc/proofs/Socket/lTCPAddRxdata/TCPAddRxdata_harness.c index fb73ca397d..6e0b9278a2 100644 --- a/test/cbmc/proofs/Socket/lTCPAddRxdata/TCPAddRxdata_harness.c +++ b/test/cbmc/proofs/Socket/lTCPAddRxdata/TCPAddRxdata_harness.c @@ -36,7 +36,7 @@ void * pvPortMallocLarge( size_t xWantedSize ) void harness() { - FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated( sizeof( FreeRTOS_Socket_t ) ); + FreeRTOS_Socket_t * pxSocket = ensure_FreeRTOS_Socket_t_is_allocated(); size_t uxOffset; const uint8_t * pcData; uint32_t ulByteCount; From 4c4223a16a2bb1d22d9acf889004abbd3e8e122c Mon Sep 17 00:00:00 2001 From: Tony Josi Date: Tue, 18 Jun 2024 10:27:32 +0530 Subject: [PATCH 06/15] Replace strcpy with strncpy (#1157) * Replace strcpy with strncpy * Fix CBMC --- source/FreeRTOS_DNS.c | 2 +- source/FreeRTOS_DNS_Cache.c | 2 +- source/FreeRTOS_DNS_Callback.c | 2 +- test/cbmc/proofs/DNS/CreateDNSMessage/Makefile.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/FreeRTOS_DNS.c b/source/FreeRTOS_DNS.c index 7ebda549a6..0eb249e4c3 100644 --- a/source/FreeRTOS_DNS.c +++ b/source/FreeRTOS_DNS.c @@ -1517,7 +1517,7 @@ uxIndex = uxStart + 1U; /* Copy in the host name. */ - ( void ) strcpy( ( char * ) &( pucUDPPayloadBuffer[ uxIndex ] ), pcHostName ); + ( void ) strncpy( ( char * ) &( pucUDPPayloadBuffer[ uxIndex ] ), pcHostName, strlen( pcHostName ) + 1U ); /* Walk through the string to replace the '.' characters with byte * counts. pucStart holds the address of the byte count. Walking the diff --git a/source/FreeRTOS_DNS_Cache.c b/source/FreeRTOS_DNS_Cache.c index 4c3f5715ae..7c8e236383 100644 --- a/source/FreeRTOS_DNS_Cache.c +++ b/source/FreeRTOS_DNS_Cache.c @@ -448,7 +448,7 @@ /* Add or update the item. */ if( strlen( pcName ) < ( size_t ) ipconfigDNS_CACHE_NAME_LENGTH ) { - ( void ) strcpy( xDNSCache[ uxFreeEntry ].pcName, pcName ); + ( void ) strncpy( xDNSCache[ uxFreeEntry ].pcName, pcName, ipconfigDNS_CACHE_NAME_LENGTH ); ( void ) memcpy( &( xDNSCache[ uxFreeEntry ].xAddresses[ 0 ] ), pxIP, sizeof( *pxIP ) ); diff --git a/source/FreeRTOS_DNS_Callback.c b/source/FreeRTOS_DNS_Callback.c index 5a040c90be..15bddbfe51 100644 --- a/source/FreeRTOS_DNS_Callback.c +++ b/source/FreeRTOS_DNS_Callback.c @@ -155,7 +155,7 @@ vDNSTimerReload( FreeRTOS_min_uint32( 1000U, ( uint32_t ) uxTimeout ) ); } - ( void ) strcpy( pxCallback->pcName, pcHostName ); + ( void ) strncpy( pxCallback->pcName, pcHostName, lLength + 1U ); pxCallback->pCallbackFunction = pCallbackFunction; pxCallback->pvSearchID = pvSearchID; pxCallback->uxRemainingTime = uxTimeout; diff --git a/test/cbmc/proofs/DNS/CreateDNSMessage/Makefile.json b/test/cbmc/proofs/DNS/CreateDNSMessage/Makefile.json index 5bb6f67d9d..8961c19ff1 100644 --- a/test/cbmc/proofs/DNS/CreateDNSMessage/Makefile.json +++ b/test/cbmc/proofs/DNS/CreateDNSMessage/Makefile.json @@ -7,7 +7,7 @@ [ "--unwind 1", "--unwindset strlen.0:{HOSTNAME_UNWIND}", - "--unwindset strcpy.0:{HOSTNAME_UNWIND}", + "--unwindset strncpy.0:{HOSTNAME_UNWIND}", "--unwindset __CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage.0:{HOSTNAME_UNWIND}", "--unwindset __CPROVER_file_local_FreeRTOS_DNS_c_prvCreateDNSMessage.1:{HOSTNAME_UNWIND}", "--nondet-static" From 0c232efb4afb82dab4cdc9ef32b97f941b9fbe8c Mon Sep 17 00:00:00 2001 From: Tony Josi Date: Tue, 18 Jun 2024 12:24:23 +0530 Subject: [PATCH 07/15] Fix MISRA violations (#1159) --- source/FreeRTOS_DNS_Parser.c | 2 ++ source/FreeRTOS_RA.c | 2 +- source/FreeRTOS_Sockets.c | 3 ++- source/FreeRTOS_TCP_IP.c | 4 ++++ source/FreeRTOS_TCP_State_Handling_IPv4.c | 2 +- source/FreeRTOS_TCP_State_Handling_IPv6.c | 2 +- 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/source/FreeRTOS_DNS_Parser.c b/source/FreeRTOS_DNS_Parser.c index 0b328d16d7..13fb75a858 100644 --- a/source/FreeRTOS_DNS_Parser.c +++ b/source/FreeRTOS_DNS_Parser.c @@ -330,6 +330,7 @@ #if ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 ) uxResult = DNS_ReadNameField( &xSet, sizeof( xSet.pcName ) ); + ( void ) uxResult; #endif } } @@ -359,6 +360,7 @@ { uxResult = DNS_ReadNameField( &xSet, sizeof( xSet.pcName ) ); + ( void ) uxResult; } else #endif /* ipconfigUSE_DNS_CACHE || ipconfigDNS_USE_CALLBACKS */ diff --git a/source/FreeRTOS_RA.c b/source/FreeRTOS_RA.c index d0e6991e6f..446dfae98c 100644 --- a/source/FreeRTOS_RA.c +++ b/source/FreeRTOS_RA.c @@ -489,7 +489,7 @@ if( pxEndPoint->xRAData.bits.bRouterReplied != pdFALSE_UNSIGNED ) { /* Obtained configuration from a router. */ - uxNewReloadTime = pdMS_TO_TICKS( 1000U * pxEndPoint->xRAData.ulPreferredLifeTime ); + uxNewReloadTime = pdMS_TO_TICKS( ( 1000U * ( uint64_t ) pxEndPoint->xRAData.ulPreferredLifeTime ) ); pxEndPoint->xRAData.eRAState = eRAStatePreLease; iptraceRA_SUCCEEDED( &( pxEndPoint->ipv6_settings.xIPAddress ) ); FreeRTOS_printf( ( "RA: succeeded, using IP address %pip Reload after %u seconds\n", diff --git a/source/FreeRTOS_Sockets.c b/source/FreeRTOS_Sockets.c index d143d16463..83d0cb0455 100644 --- a/source/FreeRTOS_Sockets.c +++ b/source/FreeRTOS_Sockets.c @@ -2893,6 +2893,8 @@ BaseType_t FreeRTOS_setsockopt( Socket_t xSocket, /* The type cast of the pointer expression "A" to * type "B" removes const qualifier from the pointed to type. */ + ipconfigISO_STRICTNESS_VIOLATION_START; + /* MISRA Ref 11.8.1 [Function pointer and use of const pointer] */ /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-118 */ @@ -2901,7 +2903,6 @@ BaseType_t FreeRTOS_setsockopt( Socket_t xSocket, /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-111 */ /* coverity[misra_c_2012_rule_11_8_violation] */ /* coverity[misra_c_2012_rule_11_1_violation] */ - ipconfigISO_STRICTNESS_VIOLATION_START; pxSocket->pxUserWakeCallback = ( SocketWakeupCallback_t ) pvOptionValue; ipconfigISO_STRICTNESS_VIOLATION_END; xReturn = 0; diff --git a/source/FreeRTOS_TCP_IP.c b/source/FreeRTOS_TCP_IP.c index 528224b407..dafbf3c0a4 100644 --- a/source/FreeRTOS_TCP_IP.c +++ b/source/FreeRTOS_TCP_IP.c @@ -277,6 +277,10 @@ static BaseType_t vTCPRemoveTCPChild( const FreeRTOS_Socket_t * pxChildSocket ) { BaseType_t xReturn = pdFALSE; + + /* MISRA Ref 11.3.1 [Misaligned access] */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* coverity[misra_c_2012_rule_11_3_violation] */ const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( xBoundTCPSocketsList.xListEnd ) ); /* MISRA Ref 11.3.1 [Misaligned access] */ diff --git a/source/FreeRTOS_TCP_State_Handling_IPv4.c b/source/FreeRTOS_TCP_State_Handling_IPv4.c index 4badde1383..d7da55d499 100644 --- a/source/FreeRTOS_TCP_State_Handling_IPv4.c +++ b/source/FreeRTOS_TCP_State_Handling_IPv4.c @@ -200,7 +200,7 @@ FreeRTOS_Socket_t * prvHandleListen_IPV4( FreeRTOS_Socket_t * pxSocket, /* Close the socket if it was newly created. */ if( xIsNewSocket == pdTRUE ) { - vSocketClose( pxReturn ); + ( void ) vSocketClose( pxReturn ); } pxReturn = NULL; diff --git a/source/FreeRTOS_TCP_State_Handling_IPv6.c b/source/FreeRTOS_TCP_State_Handling_IPv6.c index ab9020995b..d13211a02f 100644 --- a/source/FreeRTOS_TCP_State_Handling_IPv6.c +++ b/source/FreeRTOS_TCP_State_Handling_IPv6.c @@ -200,7 +200,7 @@ FreeRTOS_Socket_t * prvHandleListen_IPV6( FreeRTOS_Socket_t * pxSocket, /* Close the socket if it was newly created. */ if( xIsNewSocket == pdTRUE ) { - vSocketClose( pxReturn ); + ( void ) vSocketClose( pxReturn ); } pxReturn = NULL; From 9a88c9fb375387a733c7f1579a24ab0964461358 Mon Sep 17 00:00:00 2001 From: Tony Josi Date: Mon, 24 Jun 2024 14:14:08 +0530 Subject: [PATCH 08/15] [v4.2.0] Update version number and kernel version (#1160) * Update version number and kernel version * Fix unit test with latst kernel * Fix formatting * Update manifest * Revert kernel update * Revert "Fix formatting" This reverts commit d1e3585a133ef658f30c6d0985226da1ac8736d1. * Revert "Fix unit test with latst kernel" This reverts commit 0158df5be0013147e80f7270e62be8f1ef1db3aa. * Revert "Update manifest" This reverts commit 28405b2507613d5fe6b67b4a5fd1e8af71aed97f. * Reduce DNS CBMC proof packet size * Revert "Revert kernel update" This reverts commit 02df5d5441fc19b9484589e0841894fb234b6c2f. * Revert "Revert "Fix unit test with latst kernel"" This reverts commit 0f36ae6f271a7ebe62cb99c0a2863a02fb0acbf9. * Revert "Revert "Update manifest"" This reverts commit 7496148d7978691643717fbccdb6f450b75a5d85. * Revert "Revert "Fix formatting"" This reverts commit 5f6663d9b1c6482ec67c4e72e9e8e3b71cb03d92. --- docs/doxygen/config.doxyfile | 2 +- manifest.yml | 4 ++-- test/FreeRTOS-Kernel | 2 +- test/cbmc/proofs/DNS_ParseDNSReply/Configurations.json | 6 +++--- test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_stubs.c | 4 ++-- .../FreeRTOS_ARP_DataLenLessThanMinPacket_stubs.c | 4 ++-- test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c | 4 ++-- test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_stubs.c | 4 ++-- test/unit-test/FreeRTOS_Tiny_TCP/FreeRTOS_Tiny_TCP_stubs.c | 4 ++-- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/doxygen/config.doxyfile b/docs/doxygen/config.doxyfile index 76b46aedec..9f406bd078 100644 --- a/docs/doxygen/config.doxyfile +++ b/docs/doxygen/config.doxyfile @@ -48,7 +48,7 @@ PROJECT_NAME = FreeRTOS-Plus-TCP # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = V4.1.0 +PROJECT_NUMBER = V4.2.0 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/manifest.yml b/manifest.yml index 503347f619..5f19b66e96 100644 --- a/manifest.yml +++ b/manifest.yml @@ -1,12 +1,12 @@ name: "FreeRTOS-Plus-TCP" -version: "V4.1.0" +version: "V4.2.0" description: "Thread safe FreeRTOS TCP/IP stack working on top of the FreeRTOS-Kernel to implement the TCP/IP protocol. Suitable for microcontrollers." license: "MIT" dependencies: - name: "FreeRTOS-Kernel" - version: "V11.0.1" + version: "V11.1.0" license: "MIT" repository: type: "git" diff --git a/test/FreeRTOS-Kernel b/test/FreeRTOS-Kernel index 0240cd55f2..dbf70559b2 160000 --- a/test/FreeRTOS-Kernel +++ b/test/FreeRTOS-Kernel @@ -1 +1 @@ -Subproject commit 0240cd55f20be7100439b606086709b74a105cb1 +Subproject commit dbf70559b27d39c1fdb68dfb9a32140b6a6777a0 diff --git a/test/cbmc/proofs/DNS_ParseDNSReply/Configurations.json b/test/cbmc/proofs/DNS_ParseDNSReply/Configurations.json index d228156514..80f783f4cd 100644 --- a/test/cbmc/proofs/DNS_ParseDNSReply/Configurations.json +++ b/test/cbmc/proofs/DNS_ParseDNSReply/Configurations.json @@ -1,8 +1,8 @@ { "ENTRY": "DNS_ParseDNSReply", - "TEST_PAYLOAD_SIZE": 5, - "TEST_IPV4_PACKET_SIZE": 59, - "TEST_IPV6_PACKET_SIZE": 79, + "TEST_PAYLOAD_SIZE": 2, + "TEST_IPV4_PACKET_SIZE": 29, + "TEST_IPV6_PACKET_SIZE": 49, "CBMCFLAGS": [ "--unwind 1", diff --git a/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_stubs.c b/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_stubs.c index 829eaa17e7..4bb309b72f 100644 --- a/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_stubs.c +++ b/test/unit-test/FreeRTOS_ARP/FreeRTOS_ARP_stubs.c @@ -78,7 +78,7 @@ void vApplicationDaemonTaskStartupHook( void ) } void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer, StackType_t ** ppxTimerTaskStackBuffer, - uint32_t * pulTimerTaskStackSize ) + configSTACK_DEPTH_TYPE * puxTimerTaskStackSize ) { } void vPortDeleteThread( void * pvTaskToDelete ) @@ -125,7 +125,7 @@ void vPortCloseRunningThread( void * pvTaskToDelete, } void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, - uint32_t * pulIdleTaskStackSize ) + configSTACK_DEPTH_TYPE * puxIdleTaskStackSize ) { } void vConfigureTimerForRunTimeStats( void ) diff --git a/test/unit-test/FreeRTOS_ARP_DataLenLessThanMinPacket/FreeRTOS_ARP_DataLenLessThanMinPacket_stubs.c b/test/unit-test/FreeRTOS_ARP_DataLenLessThanMinPacket/FreeRTOS_ARP_DataLenLessThanMinPacket_stubs.c index a8f3bca4e7..3b5e529963 100644 --- a/test/unit-test/FreeRTOS_ARP_DataLenLessThanMinPacket/FreeRTOS_ARP_DataLenLessThanMinPacket_stubs.c +++ b/test/unit-test/FreeRTOS_ARP_DataLenLessThanMinPacket/FreeRTOS_ARP_DataLenLessThanMinPacket_stubs.c @@ -74,7 +74,7 @@ void vApplicationDaemonTaskStartupHook( void ) } void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer, StackType_t ** ppxTimerTaskStackBuffer, - uint32_t * pulTimerTaskStackSize ) + configSTACK_DEPTH_TYPE * puxTimerTaskStackSize ) { } void vPortDeleteThread( void * pvTaskToDelete ) @@ -121,7 +121,7 @@ void vPortCloseRunningThread( void * pvTaskToDelete, } void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, - uint32_t * pulIdleTaskStackSize ) + configSTACK_DEPTH_TYPE * puxIdleTaskStackSize ) { } void vConfigureTimerForRunTimeStats( void ) diff --git a/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c b/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c index 350372d895..c3a2dd4e83 100644 --- a/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c +++ b/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c @@ -134,7 +134,7 @@ void vApplicationDaemonTaskStartupHook( void ) } void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer, StackType_t ** ppxTimerTaskStackBuffer, - uint32_t * pulTimerTaskStackSize ) + configSTACK_DEPTH_TYPE * puxTimerTaskStackSize ) { } void vPortDeleteThread( void * pvTaskToDelete ) @@ -181,7 +181,7 @@ void vPortCloseRunningThread( void * pvTaskToDelete, } void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, - uint32_t * pulIdleTaskStackSize ) + configSTACK_DEPTH_TYPE * puxIdleTaskStackSize ) { } void vConfigureTimerForRunTimeStats( void ) diff --git a/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_stubs.c b/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_stubs.c index 1177c3d519..ac2ce0f751 100644 --- a/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_stubs.c +++ b/test/unit-test/FreeRTOS_TCP_WIN/FreeRTOS_TCP_WIN_stubs.c @@ -95,7 +95,7 @@ void vApplicationDaemonTaskStartupHook( void ) void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer, StackType_t ** ppxTimerTaskStackBuffer, - uint32_t * pulTimerTaskStackSize ) + configSTACK_DEPTH_TYPE * puxTimerTaskStackSize ) { } @@ -144,7 +144,7 @@ void vPortCloseRunningThread( void * pvTaskToDelete, void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, - uint32_t * pulIdleTaskStackSize ) + configSTACK_DEPTH_TYPE * puxIdleTaskStackSize ) { } diff --git a/test/unit-test/FreeRTOS_Tiny_TCP/FreeRTOS_Tiny_TCP_stubs.c b/test/unit-test/FreeRTOS_Tiny_TCP/FreeRTOS_Tiny_TCP_stubs.c index 13f0ee5351..d0b303547b 100644 --- a/test/unit-test/FreeRTOS_Tiny_TCP/FreeRTOS_Tiny_TCP_stubs.c +++ b/test/unit-test/FreeRTOS_Tiny_TCP/FreeRTOS_Tiny_TCP_stubs.c @@ -88,7 +88,7 @@ void vApplicationDaemonTaskStartupHook( void ) } void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer, StackType_t ** ppxTimerTaskStackBuffer, - uint32_t * pulTimerTaskStackSize ) + configSTACK_DEPTH_TYPE * puxTimerTaskStackSize ) { } void vPortDeleteThread( void * pvTaskToDelete ) @@ -135,7 +135,7 @@ void vPortCloseRunningThread( void * pvTaskToDelete, } void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, - uint32_t * pulIdleTaskStackSize ) + configSTACK_DEPTH_TYPE * puxIdleTaskStackSize ) { } void vConfigureTimerForRunTimeStats( void ) From e512b5cc306b491893743ae2e151ccdf76f9b475 Mon Sep 17 00:00:00 2001 From: Tony Josi Date: Mon, 24 Jun 2024 14:32:27 +0530 Subject: [PATCH 09/15] [v4.2.0] Update changelog (#1161) * Update changelog * Fix formatting --- History.txt | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/History.txt b/History.txt index 5b33b4d65a..3275574f99 100644 --- a/History.txt +++ b/History.txt @@ -1,5 +1,74 @@ Documentation and download available at https://www.FreeRTOS.org/ +Changes between FreeRTOS-plus-TCP V4.2.0 and V4.1.0 released June 24, 2024 + + It was possible for a carefully crafted DNS response with domain name + length value greater than the actual domain name length, to cause a buffer + over-read within the DNS Response Parser. This issue affects applications + using DNS functionality of the FreeRTOS-Plus-TCP stack. + Applications that do not use DNS functionality are not affected, + even when the DNS functionality is enabled. + This issue has been fixed by modifying the code to ensure that the DNS + Response Parser never attempts to read beyond the DNS + response buffer boundary. + We would like to thank Paschal Amusuo, James C. Davis, and + Aravind Machiry of Purdue University, for reporting this issue. + + Fixed possible freed memory being reused while creating TCP sockets. + We thank @htibosch for their contribution. + + Fixed possible NULL pointer dereference in TCP transmission. + We thank @anordal for their contribution. + + Added network interface port for ARM Corstone-315 (MPS4_CS315). + We thank @david-hazi-arm for their contribution. + + Fixed MISRA C 2012 issues in the code + + Replaced the usage strcpy with strncpy + + Improved memory allocation failure handling in `vDNSSetCallBack` by + propagating error signal back. We thank @hlef for reporting this issue. + + Improved memory allocation failure handling in `prvCreateSectors` by + propagating error signal back. We thank @hlef for reporting this issue. + + Enabled build on CI with sanitizers, fixed all AddressSanitizer + and UB-Sanitizer errors. We thank @anordal for their contribution. + + Fixed mDNS lookups while parsing the mDNS answers. + We thank @htibosch for their contribution. + + Fixed DNS name resolution responses when the device IP address + is `0.0.0.0`. We thank @evpopov for their contribution. + + Avoided FreeRTOS-Plus-TCP forcing to use the compilation options + set in the library CMake project in user projects. + We thank @apcountryman for their contribution. + + Enabled user control of compiler analysis for non ISO statements. + We thank @thirtytwobits for their contribution + + Fixed use of removed macro in ATSAME5x network interface. + We thank @apcountryman for their contribution. + + Fixed inconsistent use of `ipconfigCOMPATIBLE_WITH_SINGLE` + & `ipconfigIPv4_BACKWARD_COMPATIBLE` + + Resolved Unit Test Build Warnings + + Added network interface functions for multicast MAC address filtering. + We thank @evpopov for their contribution. + + Fixed missing `ipconfigUSE_DNS_CACHE` check in FreeRTOS_DNS.c. + + Avoided compiler warnings about the printf formats in IPv6 modules. + We thank @htibosch for their contribution. + + Removed deprecated macro `ipconfigMULTI_INTERFACE`. + We thank @HTRamsey for their contribution. + + Removed unused function xProcessedTCPMessage. + We thank @HTRamsey for their contribution. + + Removed deprecated macros ipLOCAL_MAC_ADDRESS and + `ipLOCAL_IP_ADDRESS_POINTER`. We thank @HTRamsey for their contribution. + + Fixed eARPGetCacheEntryGateWay to properly report when no valid gateway is found + for a packet that needs to be sent outside the local network. + We thank @evpopov for their contribution. + + Combined duplicated IPv4/IPv6 TCP code. + We thank @HTRamsey for their contribution. + + Improved validation of configuration macros in the default + IP config using static compile time checks. + We thank @HTRamsey for their contribution. + + Repaired ARP unit tests which were accessing packet memory + outside of allocated bounds. + + Moved CMake compile options to test builds to avoid build issues in + user projects that might be not be supporting compiler options used + in the original Cmake. We thank @apcountryman for their contribution. + + Cleaned up CMake by adding: additional unit tests, incorporating missing + network interface support, removing unused "config files" that are no longer + required, and fixing file name issues in the unit testing framework. + We thank @HTRamsey for their contribution. + Changes between FreeRTOS-plus-TCP V4.1.0 and V4.0.0 released March 8, 2024 + Add new Network Interface for Corstone-300 FVP (MPS3_AN552). We thank @urutva for their contribution. From dc25b2ab3c1f80e1df11ae992274024db8aa6c0f Mon Sep 17 00:00:00 2001 From: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com> Date: Mon, 1 Jul 2024 23:38:23 +0800 Subject: [PATCH 10/15] Update LTS 202406 information (#1165) * Update LTS 202406 information * Update capitalized version --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index eda390d7fe..4832106f5a 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,12 @@ FreeRTOS-Plus-TCP is a lightweight TCP/IP stack for FreeRTOS. It provides a fami This library has undergone static code analysis and checks for compliance with the [MISRA coding standard](https://www.misra.org.uk/). Any deviations from the MISRA C:2012 guidelines are documented under [MISRA Deviations](https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md). The library is validated for memory safety and data structure invariance through the [CBMC automated reasoning tool](https://www.cprover.org/cbmc/) for the functions that parse data originating from the network. The library is also protocol tested using Maxwell protocol tester for both IPv4 and IPv6. +**FreeRTOS-Plus-TCP Library V4.2.1 +[source code](https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/tree/V4.2.1/source) +is part of the +[FreeRTOS 202406.00 LTS](https://github.com/FreeRTOS/FreeRTOS-LTS/tree/202406.00-LTS) +release.** + ## Getting started The easiest way to use version 4.0.0 and later of FreeRTOS-Plus-TCP is to refer the Getting started Guide (found [here](https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/GettingStarted.md)) Another way is to start with the pre-configured IPv4 Windows Simulator demo (found in [this directory](https://github.com/FreeRTOS/FreeRTOS/tree/main/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_Minimal_Windows_Simulator)) or IPv6 Multi-endpoint Windows Simulator demo (found in [this directory](https://github.com/FreeRTOS/FreeRTOS/tree/main/FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_IPv6_Demo/IPv6_Multi_WinSim_demo)). That way you will have the correct FreeRTOS source files included, and the correct include paths configured. Once a demo application is building and executing you can remove the demo application files, and start to add in your own application source files. See the [FreeRTOS Kernel Quick Start Guide](https://www.freertos.org/FreeRTOS-quick-start-guide.html) for detailed instructions and other useful links. From 3979677450093a59735fbc0f180077ade0171f68 Mon Sep 17 00:00:00 2001 From: Nico van Duijn Date: Mon, 8 Jul 2024 17:31:30 +0200 Subject: [PATCH 11/15] Allow FetchContent usage in external projects (#1166) --- CMakeLists.txt | 6 ++++-- README.md | 9 ++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 426937904a..c68019ad3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.21) cmake_policy(SET CMP0048 NEW) # project version cmake_policy(SET CMP0076 NEW) # full paths @@ -174,4 +174,6 @@ add_subdirectory(source) add_subdirectory(tools) add_subdirectory(test) -FetchContent_MakeAvailable(freertos_kernel cmock) +if(PROJECT_IS_TOP_LEVEL) + FetchContent_MakeAvailable(freertos_kernel cmock) +endif() \ No newline at end of file diff --git a/README.md b/README.md index 4832106f5a..870125ebbf 100644 --- a/README.md +++ b/README.md @@ -60,13 +60,12 @@ FetchContent_Declare( freertos_plus_tcp - this particular example supports a native and cross-compiled build option. ```cmake -set( FREERTOS_PLUS_FAT_DEV_SUPPORT OFF CACHE BOOL "" FORCE) # Select the native compile PORT -set( FREERTOS_PLUS_FAT_PORT "POSIX" CACHE STRING "" FORCE) -# Select the cross-compile PORT +set( FREERTOS_PLUS_TCP_NETWORK_IF "POSIX" CACHE STRING "" FORCE) +# Or: select a cross-compile PORT if (CMAKE_CROSSCOMPILING) - # Eg. Zynq 2019_3 version of port - set(FREERTOS_PLUS_FAT_PORT "ZYNQ_2019_3" CACHE STRING "" FORCE) + # Eg. STM32Hxx version of port + set(FREERTOS_PLUS_TCP_NETWORK_IF "STM32HXX" CACHE STRING "" FORCE) endif() FetchContent_MakeAvailable(freertos_plus_tcp) From 297cce545a6b95a00b127f80649d1635bda53029 Mon Sep 17 00:00:00 2001 From: Hein Tibosch Date: Wed, 10 Jul 2024 14:39:41 +0800 Subject: [PATCH 12/15] Replace 'xMDNS_MACAddressIPv6' with 'xMDNS_MacAddressIPv6' to increase uniformity (#1169) --- source/FreeRTOS_DNS.c | 2 +- source/include/FreeRTOS_DNS.h | 7 ++++++- .../portable/NetworkInterface/DriverSAM/NetworkInterface.c | 2 +- .../portable/NetworkInterface/STM32Fxx/NetworkInterface.c | 2 +- source/portable/NetworkInterface/Zynq/NetworkInterface.c | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/source/FreeRTOS_DNS.c b/source/FreeRTOS_DNS.c index 0eb249e4c3..f3eca76055 100644 --- a/source/FreeRTOS_DNS.c +++ b/source/FreeRTOS_DNS.c @@ -150,7 +150,7 @@ * The MAC-addresses are provided here in case a network * interface needs it. */ - const MACAddress_t xMDNS_MACAddressIPv6 = { { 0x33, 0x33, 0x00, 0x00, 0x00, 0xFB } }; + const MACAddress_t xMDNS_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x00, 0x00, 0xFB } }; #endif /* ( ipconfigUSE_MDNS == 1 ) && ( ipconfigUSE_IPv6 != 0 ) */ diff --git a/source/include/FreeRTOS_DNS.h b/source/include/FreeRTOS_DNS.h index 927921ec28..c69db0e939 100644 --- a/source/include/FreeRTOS_DNS.h +++ b/source/include/FreeRTOS_DNS.h @@ -71,7 +71,12 @@ uint32_t ulDNSHandlePacket( const NetworkBufferDescriptor_t * pxNetworkBuffer ); extern const IPv6_Address_t ipMDNS_IP_ADDR_IPv6; /* The MDNS IPv6 MAC address is 33:33:00:01:00:03 */ - extern const MACAddress_t xMDNS_MACAddressIPv6; + +/* This type-name was formally "misspelled" as + * xMDNS_MACAddressIPv6 with "MAC": */ + extern const MACAddress_t xMDNS_MacAddressIPv6; + /* Guarantee backward compatibility. */ + #define xMDNS_MACAddressIPv6 xMDNS_MacAddressIPv6 #endif /* ipconfigUSE_MDNS */ /** @brief While doing integration tests, it is necessary to influence the choice diff --git a/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c b/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c index c787bbd0b8..88679b7a74 100644 --- a/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c +++ b/source/portable/NetworkInterface/DriverSAM/NetworkInterface.c @@ -787,7 +787,7 @@ static BaseType_t prvGMACInit( NetworkInterface_t * pxInterface ) #if ( ipconfigUSE_MDNS == ipconfigENABLE ) { - prvAddAllowedMACAddress( pxInterface, xMDNS_MACAddressIPv6.ucBytes ); + prvAddAllowedMACAddress( pxInterface, xMDNS_MacAddressIPv6.ucBytes ); } #endif /* ipconfigUSE_MDNS */ } diff --git a/source/portable/NetworkInterface/STM32Fxx/NetworkInterface.c b/source/portable/NetworkInterface/STM32Fxx/NetworkInterface.c index 64e8071f58..2e06048bd0 100644 --- a/source/portable/NetworkInterface/STM32Fxx/NetworkInterface.c +++ b/source/portable/NetworkInterface/STM32Fxx/NetworkInterface.c @@ -537,7 +537,7 @@ BaseType_t xSTM32F_NetworkInterfaceInitialise( NetworkInterface_t * pxInterface #endif #if ( ( ipconfigUSE_MDNS == 1 ) && ( ipconfigUSE_IPv6 != 0 ) ) { - prvMACAddressConfig( &xETH, xMACEntry, ( uint8_t * ) xMDNS_MACAddressIPv6.ucBytes ); + prvMACAddressConfig( &xETH, xMACEntry, ( uint8_t * ) xMDNS_MacAddressIPv6.ucBytes ); xMACEntry += 8; } #endif diff --git a/source/portable/NetworkInterface/Zynq/NetworkInterface.c b/source/portable/NetworkInterface/Zynq/NetworkInterface.c index 25dfd8e0fe..aa0cd363f7 100644 --- a/source/portable/NetworkInterface/Zynq/NetworkInterface.c +++ b/source/portable/NetworkInterface/Zynq/NetworkInterface.c @@ -288,7 +288,7 @@ static BaseType_t xZynqNetworkInterfaceInitialise( NetworkInterface_t * pxInterf #if ( ( ipconfigUSE_MDNS == 1 ) && ( ipconfigUSE_IPv6 != 0 ) ) XEmacPs_SetHash( pxEMAC_PS, ( void * ) xMDNS_MacAddress.ucBytes ); - XEmacPs_SetHash( pxEMAC_PS, ( void * ) xMDNS_MACAddressIPv6.ucBytes ); + XEmacPs_SetHash( pxEMAC_PS, ( void * ) xMDNS_MacAddressIPv6.ucBytes ); #endif pxEndPoint = FreeRTOS_NextEndPoint( pxInterface, pxEndPoint ); From 921f0eb95411db7bd3528b5b4b72691493399c84 Mon Sep 17 00:00:00 2001 From: "Ching-Hsin,Lee" Date: Fri, 12 Jul 2024 12:13:37 +0800 Subject: [PATCH 13/15] Update version number macro in header file * Update version number V4.2.999 in header file to indicate main branch development builds version --- .github/workflows/release.yml | 2 +- source/include/FreeRTOS_IP.h | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6018d07f23..fd11afee3b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -55,7 +55,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - ref: ${{ github.event.inputs.commit_id }} + ref: ${{ github.event.inputs.version_number }} path: FreeRTOS-Plus-TCP submodules: recursive - name: Checkout disabled submodules diff --git a/source/include/FreeRTOS_IP.h b/source/include/FreeRTOS_IP.h index cfbbca8bcf..3053bb7597 100644 --- a/source/include/FreeRTOS_IP.h +++ b/source/include/FreeRTOS_IP.h @@ -44,13 +44,11 @@ /* Constants defining the current version of the FreeRTOS+TCP * network stack. */ -#define ipFR_TCP_VERSION_NUMBER "V4.0.999" +#define ipFR_TCP_VERSION_NUMBER "V4.2.999" #define ipFR_TCP_VERSION_MAJOR 4 -#define ipFR_TCP_VERSION_MINOR 0 +#define ipFR_TCP_VERSION_MINOR 2 /* Development builds are always version 999. */ #define ipFR_TCP_VERSION_BUILD 999 -/* Using TCP version to support backward compatibility in the Demo files. */ -#define FREERTOS_PLUS_TCP_VERSION 10 /* Some constants defining the sizes of several parts of a packet. * These defines come before including the configuration header files. */ From b20ab9f88cf54063d5684c80c805f4246b2496ed Mon Sep 17 00:00:00 2001 From: "Ching-Hsin,Lee" Date: Fri, 12 Jul 2024 12:29:42 +0800 Subject: [PATCH 14/15] Update for format --- source/include/FreeRTOS_IP.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/include/FreeRTOS_IP.h b/source/include/FreeRTOS_IP.h index 3053bb7597..8b422576af 100644 --- a/source/include/FreeRTOS_IP.h +++ b/source/include/FreeRTOS_IP.h @@ -44,11 +44,11 @@ /* Constants defining the current version of the FreeRTOS+TCP * network stack. */ -#define ipFR_TCP_VERSION_NUMBER "V4.2.999" -#define ipFR_TCP_VERSION_MAJOR 4 -#define ipFR_TCP_VERSION_MINOR 2 +#define ipFR_TCP_VERSION_NUMBER "V4.2.999" +#define ipFR_TCP_VERSION_MAJOR 4 +#define ipFR_TCP_VERSION_MINOR 2 /* Development builds are always version 999. */ -#define ipFR_TCP_VERSION_BUILD 999 +#define ipFR_TCP_VERSION_BUILD 999 /* Some constants defining the sizes of several parts of a packet. * These defines come before including the configuration header files. */ From 9e445d295c5d43d12cea4cfc586b69f8b937b7bb Mon Sep 17 00:00:00 2001 From: "Ching-Hsin,Lee" Date: Tue, 16 Jul 2024 17:32:34 +0800 Subject: [PATCH 15/15] Update LTS 202406.01 information --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 870125ebbf..08ed92b14a 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,10 @@ FreeRTOS-Plus-TCP is a lightweight TCP/IP stack for FreeRTOS. It provides a fami This library has undergone static code analysis and checks for compliance with the [MISRA coding standard](https://www.misra.org.uk/). Any deviations from the MISRA C:2012 guidelines are documented under [MISRA Deviations](https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md). The library is validated for memory safety and data structure invariance through the [CBMC automated reasoning tool](https://www.cprover.org/cbmc/) for the functions that parse data originating from the network. The library is also protocol tested using Maxwell protocol tester for both IPv4 and IPv6. -**FreeRTOS-Plus-TCP Library V4.2.1 -[source code](https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/tree/V4.2.1/source) +**FreeRTOS-Plus-TCP Library V4.2.2 +[source code](https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/tree/V4.2.2/source) is part of the -[FreeRTOS 202406.00 LTS](https://github.com/FreeRTOS/FreeRTOS-LTS/tree/202406.00-LTS) +[FreeRTOS 202406.01 LTS](https://github.com/FreeRTOS/FreeRTOS-LTS/tree/202406.01-LTS) release.** ## Getting started