Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: excedentary => extraneous.

192.168.42.42), while Linux don't.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't => 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];
if (strcmp(addr, inet_ntop(AF_INET, &ip, str, sizeof(str))) != 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in theory inet_ntop should not fail since inet_pton is called above right ? I would prefer, however, assigning its result to a var and evaluating with a ZEND_ASSERT()

RETURN_FALSE;
}
#endif
RETURN_LONG(ntohl(ip.s_addr));
}
/* }}} */
Expand Down
Loading