From d490222e5ba9cf0c4eda281079ce93fdee898208 Mon Sep 17 00:00:00 2001 From: "Sivalingam, Sivaraj (Contractor)" Date: Tue, 22 Sep 2026 23:23:37 -0400 Subject: [PATCH] RDKB-67047: Apply null pointer safeguards in is_ValidIpAddressv6_port() Reason for change: Apply null pointer safeguards to validate if the host name doesn't contain proper "[" and "]" tags. Test Procedure: Run " dmcli eRT setv Device.IPv6rd.InterfaceSetting.1.Alias string "[2001:0db8:85a3:0000:0000:8a2e:0370:7334" &" and make sure CcspPandMSsp process doesn't restart Risks: Low Priority: P1 Signed-off-by: Sivaraj_Sivalingam@comcast.com --- .../ansc/AnscStringUtil/ansc_string_util.c | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/source/util_api/ansc/AnscStringUtil/ansc_string_util.c b/source/util_api/ansc/AnscStringUtil/ansc_string_util.c index 5f36ef98f..907c918bc 100644 --- a/source/util_api/ansc/AnscStringUtil/ansc_string_util.c +++ b/source/util_api/ansc/AnscStringUtil/ansc_string_util.c @@ -498,9 +498,29 @@ BOOL is_ValidIpAddressv6_port(PUCHAR pString) return FALSE; char *hostcpy = strdup((const char*)pString); char *hostdup = strdup((const char*)pString); + if ((!hostcpy) || (!hostdup)) + { + free(hostcpy); + free(hostdup); + return FALSE; + } char* ipv6 = strtok(hostcpy,"]"); ipv6 = strtok(ipv6,"["); + /* ipv6 can be NULL if hostcpy did not contain a valid "[...]" token */ + if (!ipv6) + { + free(hostcpy); + free(hostdup); + return FALSE; + } char *port_ptr = strchr(hostdup,']'); + /* port_ptr can be NULL if hostdup does not contain ']' */ + if (!port_ptr) + { + free(hostcpy); + free(hostdup); + return FALSE; + } if(port_ptr[1]) { if((port_ptr[1]==':') && (isdigit(port_ptr[2]))) @@ -509,16 +529,16 @@ BOOL is_ValidIpAddressv6_port(PUCHAR pString) port_ptr = strtok(NULL,":"); } else - { - /* CID 252351, 252353 fix */ - free(hostcpy); - free(hostdup); + { + /* CID 252351, 252353 fix */ + free(hostcpy); + free(hostdup); return FALSE; - } + } } if(is_Ipv6_address((PUCHAR)ipv6)) { - if(port_ptr[1]) + if(port_ptr && port_ptr[1]) { if(is_ValidPort((PUCHAR)port_ptr)) ret = TRUE;