From 93ab5e9c523ed580fda95dd5d41e9857161b12a3 Mon Sep 17 00:00:00 2001 From: Reshma V Kumar Date: Wed, 25 Feb 2026 11:43:37 -0500 Subject: [PATCH 1/4] Fix ip2long in AIX to treat IPs with leading zeros as invalid like LINUX --- ext/standard/basic_functions.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 16c34a21966e9..61fc9ce92ab5e 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -598,6 +598,17 @@ PHP_FUNCTION(ip2long) if (addr_len == 0 || inet_pton(AF_INET, addr, &ip) != 1) { RETURN_FALSE; } +#ifdef _AIX + /* + AIX accepts IP strings with excedentary 0 (192.168.042.42 will be treated as + 192.168.42.42), while Linux don't. + For consistency, we convert back the IP to a string and check if it is equal to + the original string. If not, the IP should be considered invalid. + */ + if (strcmp(addr, inet_ntoa(ip)) != 0) { + RETURN_FALSE; + } +#endif RETURN_LONG(ntohl(ip.s_addr)); } /* }}} */ From 268b698afb6265b4841180e2b011c9dcdae56eba Mon Sep 17 00:00:00 2001 From: Reshma V Kumar Date: Wed, 11 Mar 2026 20:38:38 -0400 Subject: [PATCH 2/4] Replace inet_ntoa with inet_ntop in ip2long --- ext/standard/basic_functions.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 61fc9ce92ab5e..53a8083a321ac 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -605,7 +605,8 @@ PHP_FUNCTION(ip2long) For consistency, we convert back the IP to a string and check if it is equal to the original string. If not, the IP should be considered invalid. */ - if (strcmp(addr, inet_ntoa(ip)) != 0) { + char str[INET_ADDRSTRLEN]; + if (strcmp(addr, inet_ntop(AF_INET, &ip, str, sizeof(str))) != 0) { RETURN_FALSE; } #endif From 1dc13d227d767d10d6836d09c96a9ca1ec2d8c0d Mon Sep 17 00:00:00 2001 From: Reshma V Kumar Date: Thu, 12 Mar 2026 02:47:23 -0400 Subject: [PATCH 3/4] Modify indentation --- ext/standard/basic_functions.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 53a8083a321ac..be280ba097299 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -598,18 +598,18 @@ PHP_FUNCTION(ip2long) if (addr_len == 0 || inet_pton(AF_INET, addr, &ip) != 1) { RETURN_FALSE; } -#ifdef _AIX - /* - AIX accepts IP strings with excedentary 0 (192.168.042.42 will be treated as - 192.168.42.42), while Linux don't. - For consistency, we convert back the IP to a string and check if it is equal to - the original string. If not, the IP should be considered invalid. - */ - char str[INET_ADDRSTRLEN]; - if (strcmp(addr, inet_ntop(AF_INET, &ip, str, sizeof(str))) != 0) { - RETURN_FALSE; - } -#endif + #ifdef _AIX + /* + AIX accepts IP strings with excedentary 0 (192.168.042.42 will be treated as + 192.168.42.42), while Linux don't. + For consistency, we convert back the IP to a string and check if it is equal to + the original string. If not, the IP should be considered invalid. + */ + char str[INET_ADDRSTRLEN]; + if (strcmp(addr, inet_ntop(AF_INET, &ip, str, sizeof(str))) != 0) { + RETURN_FALSE; + } + #endif RETURN_LONG(ntohl(ip.s_addr)); } /* }}} */ From ca5855793050b87c2605e0cbb8f96fabe2d4d7cd Mon Sep 17 00:00:00 2001 From: Reshma V Kumar Date: Fri, 13 Mar 2026 13:35:18 -0400 Subject: [PATCH 4/4] Fix indentation --- ext/standard/basic_functions.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index be280ba097299..530072c14e00b 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -598,18 +598,18 @@ PHP_FUNCTION(ip2long) if (addr_len == 0 || inet_pton(AF_INET, addr, &ip) != 1) { RETURN_FALSE; } - #ifdef _AIX - /* - AIX accepts IP strings with excedentary 0 (192.168.042.42 will be treated as - 192.168.42.42), while Linux don't. - For consistency, we convert back the IP to a string and check if it is equal to - the original string. If not, the IP should be considered invalid. - */ - char str[INET_ADDRSTRLEN]; - if (strcmp(addr, inet_ntop(AF_INET, &ip, str, sizeof(str))) != 0) { - RETURN_FALSE; - } - #endif +#ifdef _AIX + /* + AIX accepts IP strings with excedentary 0 (192.168.042.42 will be treated as + 192.168.42.42), while Linux don't. + For consistency, we convert back the IP to a string and check if it is equal to + the original string. If not, the IP should be considered invalid. + */ + char str[INET_ADDRSTRLEN]; + if (strcmp(addr, inet_ntop(AF_INET, &ip, str, sizeof(str))) != 0) { + RETURN_FALSE; + } +#endif RETURN_LONG(ntohl(ip.s_addr)); } /* }}} */