From: Pierre Joye Date: Fri, 9 Oct 2009 17:41:29 +0000 (+0000) Subject: - Merge: long2ip() can return wrong value in a multi-threaded applications X-Git-Tag: php-5.3.1RC2~41 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2fc07dcac4012b4343de75e7010e40a0ccea4549;p=php - Merge: long2ip() can return wrong value in a multi-threaded applications --- 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 } /* }}} */