diff options
| author | Ilia Alshanetsky <iliaa@php.net> | 2009-10-05 14:45:54 +0000 |
|---|---|---|
| committer | Ilia Alshanetsky <iliaa@php.net> | 2009-10-05 14:45:54 +0000 |
| commit | a3430a6b24c06d613af2eabb33be639cc389de5a (patch) | |
| tree | 825d802f0954e9e46cf836c878bd0dc3a3cf0021 /ext/standard/basic_functions.c | |
| parent | ffb07732f7418d78d74454a7850d358f95753a23 (diff) | |
| download | php-git-a3430a6b24c06d613af2eabb33be639cc389de5a.tar.gz | |
Fixed bug #49757 (long2ip() can return wrong value in a multi-threaded applications).
# original patch by Florian Anderiasch
Diffstat (limited to 'ext/standard/basic_functions.c')
| -rw-r--r-- | ext/standard/basic_functions.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index b84ea36d2e..37546a3037 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -3932,6 +3932,9 @@ PHP_FUNCTION(long2ip) int ip_len; unsigned long n; struct in_addr myaddr; +#ifdef HAVE_INET_PTON + char str[40]; +#endif if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ip, &ip_len) == FAILURE) { return; @@ -3940,7 +3943,15 @@ PHP_FUNCTION(long2ip) n = strtoul(ip, NULL, 0); myaddr.s_addr = htonl(n); +#ifdef HAVE_INET_PTON + if (inet_ntop(AF_INET, &myaddr, str, sizeof(str))) { + RETURN_STRING(str, 1); + } else { + RETURN_FALSE; + } +#else RETURN_STRING(inet_ntoa(myaddr), 1); +#endif } /* }}} */ |
