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
9 changes: 6 additions & 3 deletions ext/standard/basic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,8 @@ PHP_FUNCTION(inet_ntop)
char *address;
size_t address_len;
int af = AF_INET;
char buffer[40];
socklen_t buffersize = INET6_ADDRSTRLEN;
char buffer[INET6_ADDRSTRLEN];
Copy link
Contributor

Choose a reason for hiding this comment

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

Is anything INET6_* defined when HAVE_IPV6 is not?

Also, is it safe to use shorter buffersize when compiled /wo IPv6 support and then run on system /w IPv6 support?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is anything INET6_* defined when HAVE_IPV6 is not?

Yes it is independant from ipv6 support and, alone, does not indicate the system supports it.

Also, is it safe to use shorter buffersize when compiled /wo IPv6 support and then run on system /w IPv6 support?

Yes in that case the best course is to reverse the logic.


ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(address, address_len)
Expand All @@ -555,11 +556,13 @@ PHP_FUNCTION(inet_ntop)
af = AF_INET6;
} else
#endif
if (address_len != 4) {
if (address_len == 4) {
buffersize = INET_ADDRSTRLEN;
} else {
RETURN_FALSE;
}

if (!inet_ntop(af, address, buffer, sizeof(buffer))) {
if (!inet_ntop(af, address, buffer, buffersize)) {
RETURN_FALSE;
}

Expand Down
Loading