1
0
mirror of https://github.com/FreeRTOS/FreeRTOS-Plus-TCP synced 2025-10-21 15:10:39 +08:00
Commit Graph

35 Commits

Author SHA1 Message Date
Tony Josi
0c232efb4a Fix MISRA violations (#1159) 2024-06-18 12:24:23 +05:30
Andreas Nordal
f5cbeb5238 Let's fix the tests enough to run with AddressSanitizer and UB Sanitizer and enable those in CI (#1151)
* 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 <tonyjosi@amazon.com>
2024-06-14 16:11:40 +05:30
Tony Josi
ba6ba81f64 Fix freed memory being reused (#1148)
* Add changes

* Fix build

* TCP API utests

* Fix UTs

* Fix state handling APIs

* Fix CBMC proofs

* Fix formatting

* Updating with review feedback
2024-06-04 10:50:55 +05:30
Holden
e448c83ca4 Combine Duplicate IPv4/IPv6 TCP code (#1087)
* merge identical TCP processing code

* Uncrustify: triggered by comment.

* fix doxygen issue

* Fix CBMC proof and MISRA

---------

Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: tony-josi-aws <tonyjosi@amazon.com>
2024-03-15 14:14:04 +05:30
Tony Josi
ef14a0871f Fix declarations after statements (#1106)
* Fix C90: Wno-declaration-after-statement

* Uncrustify: triggered by comment

---------

Co-authored-by: GitHub Action <action@github.com>
2024-02-23 17:52:12 +05:30
Holden
be2555b3b0 Improve Default Macros (#782)
* Delete duplicate default defines

* Remove errno definitions that exist in projdefs.h

* Clean & Organize FreeRTOSIPConfigDefaults.h

* Move deprecated definitions to their own file

* Definitions Documentation Improvements

* Tracing default definitions improvements

* Organize and add to deprecated definitions

* Remove FreeRTOS_errno_TCP.h

* Fixes for definitions updates

* Address review comments

* Start enforcing macro value limits and make some doc more succinct

* enforce ipconfig macro bounds

* repair config default and reduce unnecessary changes

* Add more descriptions of ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM (#947)

* Fixes mDNS over IPv6. (#949)

Co-authored-by: Emil Popov <epopov@cardinalkinetic.com>
Co-authored-by: ActoryOu <jay2002824@gmail.com>
Co-authored-by: Monika Singh <moninom@amazon.com>

* remove enabled checks

* Remove enable checks from trace macros

* Update cmake sources

* add missing defines

* revert unnecessary changes

* formatting

* fix lexicon

* fix build issue and remove deprecated macro usage from tests

* fix build issues and formatting

* disable pdFREERTOS_ERRNO_EAFNOSUPPORT check

* update kernel submodule for tests

* macro definition fixes

* fix some test build issues

* Temporary passing state

* Fix unittest

* Fix CBMC

* Update CBMC proof

* Update Macro comments

* revert changes

* Fix MISRA 4.4

* Fix MISRA 20.7 violation

* Fix spell checker

* Update Hein's comment

---------

Co-authored-by: Holden <holden-zenithaerotech.com>
Co-authored-by: ActoryOu <jay2002824@gmail.com>
Co-authored-by: Emil Popov <evpopov@gmail.com>
Co-authored-by: Emil Popov <epopov@cardinalkinetic.com>
Co-authored-by: Monika Singh <moninom@amazon.com>
Co-authored-by: ActoryOu <ousc@amazon.com>
2023-11-01 12:33:52 +05:30
Soren Ptak
eed294c0ec CI-CD Updates (#1014)
* Use new version of CI-CD Actions,  checkout@v3 instead of checkout@v2 on all jobs
* Use cSpell spell check, and use ubuntu-20.04 for formatting check
* Add in bot formatting action
2023-09-05 14:31:24 -07:00
Monika Singh
b23fa86ac4 Add and fix -Wconversion errors (#980)
* Fix Wconverstion

* Enable Wconversion warning

* Add fix

* Fix MISRA

* Fix coverity

* Add comments
2023-07-27 15:56:36 +05:30
Monika Singh
bc908689c3 Add Unit Test Coverage for FreeRTOS_TCP_IP and FreeRTOS_TCP_IP_IPV4 (#881)
* Add coverage for TCP_IP

* Remove duplicate asserts

* Add comments and fix spell check

* Update spell check

---------

Co-authored-by: kar-rahul-aws <118818625+kar-rahul-aws@users.noreply.github.com>
2023-06-01 09:30:51 +05:30
Tony Josi
1f98752059 Adding IPv4/v6 build level separation: integration branch (#855)
* use matching endpoint instead of first endpoint

* update with @htibosch  latest changes

* fix formatting

* fix misra and spellings

* code clean up

* wip separation IP

* separation IP

* separation IP

* wip buils separation

* fixing unit tests

* fix unit tests

* fix formatting

* wip , next prvProcessNetworkDownEvent

* adding build separation to ip utils

* fix unit tests

* fix formatting

* update xCheckRequiresARPResolution

* update vARPAgeCache

* update vARPAgeCache

* misra checks

* fix formatting

* fix misra

* wip s/w: FreeRTOS_recvfrom

* wip sockets till prvSocketBindAdd

* adding  build separation to FreeRTOS_Sockets.c

* add build config support to FreeRTOS_inet_pton FreeRTOS_inet_ntop FreeRTOS_GetIPType

* adding build config support

* fix build  issues

* check misra

* minor fix

* fix unit tests

* fix unit tests build

* Uncrustify: triggered by comment

* fix formatting

* build separate FreeRTOS_TCP_IP.c

* build separate FreeRTOS_TCP_Reception.c

* misra fix

* build separate FreeRTOS_TCP_State_Handling.c

* build separate FreeRTOS_TCP_Transmission.c

* build separate FreeRTOS_TCP_Transmission.c fix build

* adding build separation for FreeRTOS_TCP_Utils.c and FreeRTOS_TCP_Transmission.c

* fix formatting

* UDP: Build Separation Changes

Changes in UDP files to support IPv4 and IPv6 Build Separation.

* fix IPv4 build issues post build sep merge

* IPv4 only build

* more - fix IPv4 build issues post build sep merge

* fix DHCP v4

* fix v6 build

* add v6 build checks

* separate v4v6 tcp files

* fix rebase conflicts

* fix formatting

* fix build when TCP disabled

* add more build checks

* adding more ipv4 flags to v4 specific files

* fix udp unit tests

* add build config build tests to CI

* fix formatting

* fix build checks yml

* DNS: Build Separation Changes

Changes for supporting IPv4 and IPv6 build separation in DNS.

* Routing: Build Separtion Changes

Changes for supporting IPv4 and IPv6 build separation in Routing.

* DNS build fix and rebase to latest changes

* fix formatting

* fix unit tests

* fix formatting

* fix MISRA

* updaating ARP functions to be available on all configs

* plus_tcp_demo_cli build config changes

* fix formatting, guard FreeRTOS_FillEndPoint inside ipconfigUSE_IPv4 check

* more build sepration changes to routing

* build separation plus_tcp_demo_cli.c

* fixing issues with routing, fix formatting

* adding pxFindEndpoint of plus_tcp_demo_cli inside ipconfigUSE_IPv6 != 0 check

* minor build fix

* moving usDNSType of endpoint struct out of ipconfigUSE_IPv6 check

* update code to use IP family while using socket APIs

* moving vSetMultiCastIPv4MacAddress to FreeRTOS_IPv4_Utils.c

* fix routing

* build DNS only if IPv4 is enabled

* fix review feedback

* fix build

* fix build

* fix formatting

* fix comment

* fix wrt reeview feedback

* fix unit tests

* cleanup FreeRTOS_MatchingEndpoint

* fix FreeRTOS_MatchingEndpoint to handle cusstom frames

---------

Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: shubnil <103672514+shubnil@users.noreply.github.com>
2023-05-09 19:48:59 +05:30
Kody Stribrny
f15537303c Fix Clang warnings (#809)
Corrects several warnings from Clang flags
for Clang 13.

Inspired by @phelter's bug report
https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/issues/558
2023-04-18 11:00:00 +00:00
Monika Singh
9a955f27ac Add changes for Coverity fix (#729)
* Fix Coverity issues

* Fix Misra 4.4 violation:The comment resembles a code snippet

* Misra: Rule 10.4 violations

* Misra: Rule 11.8 violations

* Misra: Rule 12.1 violations

* Misra: Rule 8.2, 8.4, 8.5, and 8.9 violations

* Misra: Rule 5.3, 5.8, 21.1 and 21.2  violations

* Misra: Rule 5.7 violations

* Misra: Rule 8.3 violations

* Misra: Rule Reverse NULL violations

* Misra: Rule 10.3, 10.8 and 8.13 violations

* Fix 11.3 and suppress 11.4

* Misra: Rule 14.3, 15.7, 17.2 and 17.7 violations

* Misra: Rule 2.2 and 2.7 violation

* Misra: Rule 21.6, 8.5 and 8.13 violation

* Fix UT compilation

* Update comments

* Fix Spell checker

* Update snprintf
2023-02-28 12:55:20 +05:30
Hein Tibosch
ff11a1484a Dev integration hein.v8 (#738)
* Updating tcp utilities

* Some more change in dev_integration_hein.v8

* In FreeRTOS_DNS_Parser.c : use 'ipUDP_PAYLOAD_OFFSET_IPv4' in stead of 'ipIP_PAYLOAD_OFFSET'

* And a few more corrections

* Changes to WinPCap network interface, removed debugging code

* After applying uncrustify

* Oops, I forgot the push changes in include files.

* Now removing it, hopefully

---------

Co-authored-by: Nikhil Kamath <110539926+amazonKamath@users.noreply.github.com>
Co-authored-by: Monika Singh <108652024+moninom1@users.noreply.github.com>
2023-02-23 14:50:27 +05:30
Tony Josi
907ae56c27 Fix build and proof failures for CBMC TCP proofs (#710)
* Use CBMC XML output to enable VSCode debugger (#673)

Prior to this commit, CBMC would emit logging information in plain text
format, which does not contain information required for the CBMC VSCode
debugger. This commit makes CBMC use XML instead of plain text.

Co-authored-by: Mark Tuttle <tuttle@acm.org>

* fix the CBMC proof build and fail due to non inclusion of actaul src files

* fix the CBMC proof build and fail due to non inclusion of actaul src files

* adding tcp transmission v4 src to build

* fix cbmc proof for CheckOptionsInner

* updating as per review comments

* fix check option CBMC proofs

* removing unused assumptions

---------

Co-authored-by: Kareem Khazem <karkhaz@amazon.com>
Co-authored-by: Mark Tuttle <tuttle@acm.org>
2023-02-21 09:31:51 +05:30
Hein Tibosch
f44df85c54 Make sure that a socket in the SYN phase doesn't get closed twice (#703) 2023-02-07 15:46:08 +05:30
Monika Singh
0490d89319 Add Protocol Testing fixes (#694)
* Fix compilation and add Protocol testing fixes

* Update debug function with correct config flag
2023-01-31 21:56:54 +05:30
Hein Tibosch
f88dea60ca Reparations and recommendations for the dev/IPv6_integration branch (#664)
* Reparations and recommendations for the dev/IPv6_integration branch
* Applied uncrustify
* More changes after testing ARP, ICMP4, ICMP6, UDPv4 and UDPv6, DNSv6
* A few changes to DNS after testing it
2023-01-25 18:33:44 +05:30
Monika Singh
7315e4b3ba Fix FreeRTOS_IP test cases (#666)
* Fix FreeRTOS_IP and FreeRTOS_IP_DiffConfig test cases
* Remove test_prvProcessIPEventsAndTimers_eNetworkDownEvent test Case
 - eNetworkDownEvent no longer support xNetworkUp variable, the network status
is kept in pxEndPoint->bits.bEndPointUp.
* Run Uncrustify.

Co-authored-by: GitHub Action <action@github.com>
2023-01-16 21:07:57 +05:30
kar-rahul-aws
bf32bf336e Demo changes for IPv4 Endpoint changes (#660)
* Update FreeRTOS_ARP.c
* Update FreeRTOS_UDP_IPv4.c
* Update FreeRTOS_TCP_Transmission_IPV4.c
* Update FreeRTOS_IP.c
* Update FreeRTOS_DHCP.c
* Update FreeRTOS_DNS.c
* Update NetworkInterface.c

Add Functions  To avoid scheduler suspension: xPacketBouncedBack and prvStreamBufferAdd
2023-01-10 19:27:49 +05:30
Monika Singh
4624fb0e00 Remove use of ipconfigCOMPATIBLE_WITH_SINGLE (#646)
As ipconfigCOMPATIBLE_WITH_SINGLE is never enabled and used partially, removing the rest of the instances of the same.
Ran uncrustify.
2022-12-21 20:09:40 +05:30
xuelix
1b8cb751bb Fixing MISRA violations for FreeRTOS_TCP* files (#620)
Fix TCP compilation errors
Add missing fix of TCP compilation
Update for TCP misra violation fix
2022-12-19 15:34:54 +05:30
xuelix
087794a9e5 Fix TCP compilation errors (#610)
* Fix TCP compilation errors

* Add missing fix of TCP compilation
2022-12-15 12:02:17 +05:30
shubnil
6bff70c0e0 IPv6 Changes for TCP protocol (#595)
The change add support for IPv6 anf TCP.
Files modified/added:
    FreeRTOS_TCP_IP.c
    FreeRTOS_TCP_IP_IPV4.c
    FreeRTOS_TCP_IP_IPV6.c
    FreeRTOS_TCP_Reception.c
    FreeRTOS_TCP_State_Handling.c
    FreeRTOS_TCP_State_Handling_IPV4.c
    FreeRTOS_TCP_State_Handling_IPV6.c
    FreeRTOS_TCP_Transmission.c
    FreeRTOS_TCP_Transmission_IPV6.c
    FreeRTOS_TCP_Transmission_IPv4.c
    FreeRTOS_TCP_Utils.c
    FreeRTOS_TCP_Utils_IPV4.c
    FreeRTOS_TCP_Utils_IPV6.c
2022-12-14 11:35:15 -08:00
Monika Singh
5e56f7739f Add IPv6 data path changes to FreeRTOS_Socket.c (#583)
* Add EndPoint changes to FreeRTOS_Socket.c

* Split Socket.c to IPv4 and IPv6 files

* Combine freertos_sockaddr for IPv4 and IPv6

* Update sendto and recv function to handle IPv4 and IPv6 case

* Run uncrustify
2022-12-05 13:48:17 +05:30
Monika Singh
902d6bc975 Add Header size functions for IPv6 and IPv4 (#569)
* Add common Header size function for IPv6 and IPv4

* MISRA: Fix rule 1.1, 10.3, 20.9 and suppress rule 20.5

Co-authored-by: Monika Singh <moninom@amazon.com>
2022-11-07 09:59:22 +05:30
Monika Singh
6b20f521dd Add IPv6 specific header files and structures. (#566)
* Add IPv6 specific header files.

* Update according to Coding Guidelines and Uncrustify

* Adding common IP file to handle common strctures

Co-authored-by: Monika Singh <moninom@amazon.com>
2022-11-04 14:03:43 +05:30
Hein Tibosch
188a9d02f4 IPv4/single: connect() should return immediately after a protocol error and other things (#559)
* IPv4/single: Let connect() return as soon as socket gets closed

* Let both connect() and accept() return after a 'eSOCKET_CLOSED' event

* Included hang protection of orphaned socket from PR #545

* Lexicon.txt change

* Remove a variable that was not used

* Update source/FreeRTOS_Sockets.c

Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>

* Update source/FreeRTOS_TCP_IP.c

Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>

* moved declaration to beginning of block

* Update source/FreeRTOS_TCP_IP.c

Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>

* Uncrustify: triggered by comment.

* Fix unit test expectations

* Avoid a recursive call to vTCPStateChange()

* Uncrustify: triggered by comment.

* Fix CBMC proof assumptions

* Get unit-test coverage up

* Fix timers unit-tests

* Socket unit-test for closed socket

* Fix a unit-test expectations

* Fix spell check

* Uncrustify: triggered by comment.

* Using debug_printf in stead of printf for logging.

* Use debug printf instead of printf in 2 locations

Co-authored-by: Hein Tibosch <hein@htibosch.net>
Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>
Co-authored-by: GitHub Action <action@github.com>
2022-10-11 14:20:13 -07:00
Aniruddha Kanhere
1ab6eb8885 Update version numbers and licensing info (#541)
* Update source location for coverity

* Add coverage checker

* Add build check with default configuration

* Fix build combination and DNS error

* uncrustified and fixed cmakelists

* This commit updates version number in all files to Development-Branch

* Update version number macros

* This commit fixes a typo in version number macro

* Added a 'critical section' to prevent a race condition in stream buffers

* Uncrustify: triggered by comment.

* Fixed unit-tests by adding mocked functions

* Initial commit of file README.md

* Update README.md

* Fix the title of README file in coverity

* Addressed issue comments

* Update command

* Add details about remaining exception

* Move file to original location

* Remove use of sudo in commands

* Fix links; added coverity version note

* Update README.md

* Remove CMake installation instructions

* Update manifest/history and copyright year

* Update kernel version to 10.4.5

* Update remaining copyright year instances

* Update the version number macros

* Update license header titles

* Remove kernel license header and add TCP header

Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
2022-08-12 16:21:44 -07:00
alfred gedeon
4ac10c84a3 Misra fix or suppress remaining violations (#529)
* Fix Remaning misra issues

* Suppress rule 8.6

* Fix/Suppress more misra violations

* Style: for formatting

* Style: fix formatting

* Style: fix spelling

* Fix Rule 11.1

* Fix undeteced suppressions

* Enable 32 bits

* Fix more misra leftover violations

* Add justification for a missed violation

* Fix comment for rule 8.13

* Fix comment

* fix misra comments

* Update MISRA.md

Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>

* Update source/FreeRTOS_Sockets.c

Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>

* Update source/portable/BufferManagement/BufferAllocation_2.c

Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>

* Update MISRA.md

Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>

* Update MISRA.md

Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>

* Suppress Rule 8.9

* Fix build error

* fix build error

* Fix coverity supression bugs

Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>
2022-08-08 10:45:09 -07:00
alfred gedeon
80876f5301 Consolidate all misra inline violation justifications into a single file (#521)
* Consolidate all misra inline violation justification into a single file

* Style: fix formatting error

* Style: fix formatting error

* Fix build error

* fix merge errors

* fix merge conflicts

* Style: improve misra exception file

* Updated the justification for MISRA rule 2.2 violation

* Fix comments and justification for MISRA rule 8.9

* Update justification for MISRA rule 11.3

* Updated wording of violation of rule 11.4 ref 5

* Updated the justification of rule 11.4 ref 29

* Fixed comment and justification for ref 31

* Update rule 11.6

* Fix some violations

* Update justifications of various violations

* Fix formatting

* Remove the previous verison of violation table

* Update formatting to separate reference numbers from the text

* Update ref for rule 2.2 and 8.9

* Update rule 11.3 references

* Added rule 11.4

* Added rule 11.6

* Added rule 11.8

* Update refs in MISRA.md

* Add rule 14.3

* Fix 21.6, 17.2 and 20.10

* Fix spell check

* Fix mis-spelled words and address review comments

* Add link to 8.9

* Add 11.3 link

* Add link for 11.4

* Add links for 14.3

* Add remaining links

* Updated some justifications and simplified code to remove deviation

* Fixed spelling errors

* Fix justification for rule 11.3 violation

* Update the link to be a hyperlink

* Update comments for misaligned access

* Add link to project wide suppression file

* Updated wording in MISRA config

* Fix grammar and reorder file

* Address comments

Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>
2022-07-26 11:30:42 -07:00
alfred gedeon
0ceebc2685 MISRA: suppress rule 10.5 (#506)
* MISRA: suppress rule 10.5

* Fix misra rule 10.5 violations

* Fix format error and missing include

* Change variable name to match type

* Merge: fix conflicts

* Fix pr comments

* Spell: remove spelling error comments

* Fix ut failure
2022-07-20 09:24:22 -07:00
alfred gedeon
4e151a0dc6 MISRA: fix rule 8.9 violations (#511)
* MISRA: fix rule 8.9 violations

* Style: Fix format error and build error

* Style: format error and build error

* Fix build error

* Doc: fix doxygen error

* Retrigger the CI

* Comment: make comment follow the code move

Co-authored-by: Aniruddha Kanhere <60444055+AniruddhaKanhere@users.noreply.github.com>
2022-07-14 00:18:57 -07:00
xuelix
ab519329f4 Misra rule 11.3, 11.4 suppression and 4.6 fix (#512)
* Misra rule 11.3 inline suppression

* Added several MISRA deviations

* MISRA Rule 11.4 inline suppression

* Misra violation fix 4.6

* Misra rule 1.2 suppression
2022-07-12 14:20:52 -07:00
Aniruddha Kanhere
f44d36d5ce Update version number of TCP to development (#516)
* Update source location for coverity

* Add coverage checker

* Add build check with default configuration

* Fix build combination and DNS error

* uncrustified and fixed cmakelists

* This commit updates version number in all files to Development-Branch

* Update version number macros

* This commit fixes a typo in version number macro
2022-07-06 10:29:48 -07:00
Aniruddha Kanhere
a4124602cc Merge changes to main.
This commit brings in the refactoring and restructuring changes
from IntegrationTesting1 branch to the main branch.
It also includes additional unit tests for 100% coverage.
The rationale behind not creating a PR is that the conflicts were too
huge to be resolved correctly. Thus, a force push to the main branch is
being done.
2022-05-26 12:42:45 -07:00