]> 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

ext/standard/basic_functions.c

index 955c03063589e8e9d393a4f15b797295e8d14a95..a0b999c7b2d1c061bf2c9ed6c015f61314e8387a 100644 (file)
@@ -3923,6 +3923,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;
@@ -3931,7 +3934,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_RT_STRING(str, ZSTR_DUPLICATE);
+       } else {
+               RETURN_FALSE;
+       }
+#else
        RETURN_RT_STRING(inet_ntoa(myaddr), ZSTR_DUPLICATE);
+#endif
 }
 /* }}} */