Commit e88e04909c1 for php.net
commit e88e04909c127f2e525465c523f71f308063dd7c
Author: Reshma V Kumar <reskumar@in.ibm.com>
Date: Wed Feb 25 11:43:37 2026 -0500
ext/standard: Fix ip2long in AIX to treat IPs with leading zeros as invalid like LINUX
close GH-21296
diff --git a/NEWS b/NEWS
index c4c7f989638..c2767fd3c30 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,7 @@ PHP NEWS
- Standard:
. Fixed bug GH-21689 (version_compare() incorrectly handles versions ending
with a dot). (timwolla)
+ . Fixed ip2long() leading zeros handling inconsistency on AIX. (ayappanec)
07 May 2026, PHP 8.4.21
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index cf54fbbe651..a1bf86d0bcf 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -598,6 +598,20 @@ PHP_FUNCTION(ip2long)
if (addr_len == 0 || inet_pton(AF_INET, addr, &ip) != 1) {
RETURN_FALSE;
}
+#ifdef _AIX
+ /*
+ AIX accepts IP strings with extraneous 0 (192.168.042.42 will be treated as
+ 192.168.42.42), while Linux doesn'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];
+ const char* result = inet_ntop(AF_INET, &ip, str, sizeof(str));
+ ZEND_ASSERT(result != NULL);
+ if (strcmp(addr, result) != 0) {
+ RETURN_FALSE;
+ }
+#endif
RETURN_LONG(ntohl(ip.s_addr));
}
/* }}} */