Skip to content

Commit f340037

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: ext/standard: Fix ip2long in AIX to treat IPs with leading zeros as invalid like LINUX
2 parents 359b9a5 + e88e049 commit f340037

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

ext/standard/basic_functions.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,20 @@ PHP_FUNCTION(ip2long)
599599
if (addr_len == 0 || inet_pton(AF_INET, addr, &ip) != 1) {
600600
RETURN_FALSE;
601601
}
602+
#ifdef _AIX
603+
/*
604+
AIX accepts IP strings with extraneous 0 (192.168.042.42 will be treated as
605+
192.168.42.42), while Linux doesn't.
606+
For consistency, we convert back the IP to a string and check if it is equal to
607+
the original string. If not, the IP should be considered invalid.
608+
*/
609+
char str[INET_ADDRSTRLEN];
610+
const char* result = inet_ntop(AF_INET, &ip, str, sizeof(str));
611+
ZEND_ASSERT(result != NULL);
612+
if (strcmp(addr, result) != 0) {
613+
RETURN_FALSE;
614+
}
615+
#endif
602616
RETURN_LONG(ntohl(ip.s_addr));
603617
}
604618
/* }}} */

0 commit comments

Comments
 (0)