]> granicus.if.org Git - php/commitdiff
Fixed bug #49757 (long2ip() can return wrong value in a multi-threaded applications).
authorIlia Alshanetsky <iliaa@php.net>
Mon, 5 Oct 2009 14:45:54 +0000 (14:45 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Mon, 5 Oct 2009 14:45:54 +0000 (14:45 +0000)
# original patch by Florian Anderiasch

NEWS
ext/standard/basic_functions.c

diff --git a/NEWS b/NEWS
index 29beec2808d28ea3216bf74806337b3870991c87..31ae09c45395d8415d944e62647a7833a197bee6 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,8 @@ PHP                                                                        NEWS
 - 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 #49732 (crashes when using fileinfo when timestamp conversion
   fails). (Pierre)
 - Fixed bug #49698 (Unexpected change in strnatcasecmp()). (Rasmus)
index b84ea36d2e79278d6d74bafd4a5f4786f1b85e5b..37546a3037ed1b78b9a922f38eec0b2003da1fe8 100644 (file)
@@ -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
 }
 /* }}} */