From: Ilia Alshanetsky Date: Mon, 5 Oct 2009 14:45:54 +0000 (+0000) Subject: Fixed bug #49757 (long2ip() can return wrong value in a multi-threaded applications). X-Git-Tag: php-5.2.12RC1~86 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c21d59c08e60546c2bfa2e1e15b3bf64ba49f269;p=php Fixed bug #49757 (long2ip() can return wrong value in a multi-threaded applications). # original patch by Florian Anderiasch --- diff --git a/NEWS b/NEWS index 96aac69db9..e8b70ce005 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ (Rasmus) - Fixed a open_basedir bypass in posix_mkfifo() identified by Grzegorz Stachowiak. (Rasmus) +- Fixed bug #49757 (long2ip() can return wrong value in a multi-threaded + applications). (Ilia, Florian Anderiasch) - Fixed bug #49698 (Unexpected change in strnatcasecmp()). (Rasmus) - Fixed bug #49647 (DOMUserData does not exist). (Rob) - Fixed bug #49630 (imap_listscan function missing). (Felipe) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 17f1c649f8..0e4eb0b6af 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -4375,6 +4375,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; @@ -4383,7 +4386,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 } /* }}} */