You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2026/10/28 09:03:34 UTC

(mynewt-core) 03/03: net/ip/mn_socket: Add tests for invalid IPv4 addresses

This is an automated email from the ASF dual-hosted git repository.

sjanc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 06a08aa7d34e48b1d158d6404a28a20e1cc96688
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Sun Oct 25 23:26:19 2026 +0100

    net/ip/mn_socket: Add tests for invalid IPv4 addresses
    
    Verify that addresses with more or less than 4 octets or with empty
    octets are rejected and that nothing is written past the address.
    
    Assisted-by: Claude:claude-opus-5-5
---
 net/ip/mn_socket/selftest/src/testcases/inet_pton_test.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/net/ip/mn_socket/selftest/src/testcases/inet_pton_test.c b/net/ip/mn_socket/selftest/src/testcases/inet_pton_test.c
index 58606e350..b4b422065 100644
--- a/net/ip/mn_socket/selftest/src/testcases/inet_pton_test.c
+++ b/net/ip/mn_socket/selftest/src/testcases/inet_pton_test.c
@@ -34,11 +34,9 @@ TEST_CASE_SELF(inet_pton_test)
         { "001.002.005.006", { 1, 2, 5, 6 } }
     };
     struct test_vec invalid_vec[] = {
-        { "a.b.c.d" },
-        { "1a.b3.4.2" },
-        { "1.3.4.2a" },
-        { "1111.3.4.2" },
-        { "3.256.1.0" },
+        { "a.b.c.d" },   { "1a.b3.4.2" }, { "1.3.4.2a" }, { "1111.3.4.2" },
+        { "3.256.1.0" }, { "1.2.3.4.5" }, { "1.2.3.4." }, { "1.2.3" },
+        { "1..2.3" },    { ".1.2.3" },    { "" },
     };
     int i;
 
@@ -47,10 +45,12 @@ TEST_CASE_SELF(inet_pton_test)
         rc = mn_inet_pton(MN_PF_INET, ok_vec[i].str, addr);
         TEST_ASSERT(rc == 1);
         TEST_ASSERT(!memcmp(ok_vec[i].cmp, addr, sizeof(uint32_t)));
-        TEST_ASSERT(addr[5] == 0xa5);
+        TEST_ASSERT(addr[4] == 0xa5);
     }
     for (i = 0; i < sizeof(invalid_vec) / sizeof(invalid_vec[0]); i++) {
+        memset(addr, 0xa5, sizeof(addr));
         rc = mn_inet_pton(MN_PF_INET, invalid_vec[i].str, addr);
         TEST_ASSERT(rc == 0);
+        TEST_ASSERT(addr[4] == 0xa5);
     }
 }