Skip to content
Open
Changes from 1 commit
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
6 changes: 4 additions & 2 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 = INET_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 @@ -553,13 +554,14 @@ PHP_FUNCTION(inet_ntop)
#ifdef HAVE_IPV6
if (address_len == 16) {
af = AF_INET6;
buffersize = INET6_ADDRSTRLEN;
} else
#endif
if (address_len != 4) {
RETURN_FALSE;
}

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

Expand Down
Loading