From b7b0eecfe2ee8aa04abb646dd63586291311c43c Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Thu, 16 May 2019 21:39:32 -0700 Subject: [PATCH] [ip6] add additional parse validation to Ip6::Address::FromString (#3830) --- src/core/net/ip6_address.cpp | 2 ++ tests/unit/test_ip6_address.cpp | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/core/net/ip6_address.cpp b/src/core/net/ip6_address.cpp index 5d34de995..0bd765adf 100644 --- a/src/core/net/ip6_address.cpp +++ b/src/core/net/ip6_address.cpp @@ -328,6 +328,8 @@ otError Address::FromString(const char *aBuf) VerifyOrExit(++count <= 4, error = OT_ERROR_PARSE); } + VerifyOrExit(colonp || dst == endp, error = OT_ERROR_PARSE); + while (colonp && dst > colonp) { *endp-- = *dst--; diff --git a/tests/unit/test_ip6_address.cpp b/tests/unit/test_ip6_address.cpp index b54cd7133..e6b83aeb0 100644 --- a/tests/unit/test_ip6_address.cpp +++ b/tests/unit/test_ip6_address.cpp @@ -169,6 +169,26 @@ void TestIp6AddressFromString(void) OT_ERROR_PARSE }, + // Invalid embedded IPv4 address. + { + ".", + {0}, + OT_ERROR_PARSE + }, + + // Invalid embedded IPv4 address. + { + ":.", + {0}, + OT_ERROR_PARSE + }, + + // Invalid embedded IPv4 address. + { + "::.", + {0}, + OT_ERROR_PARSE + }, }; for (uint32_t index = 0; index < OT_ARRAY_LENGTH(testVectors); index++)