]> granicus.if.org Git - php/commitdiff
- Merge: long2ip() can return wrong value in a multi-threaded applications
authorPierre Joye <pajoye@php.net>
Fri, 9 Oct 2009 17:41:29 +0000 (17:41 +0000)
committerPierre Joye <pajoye@php.net>
Fri, 9 Oct 2009 17:41:29 +0000 (17:41 +0000)
ext/standard/basic_functions.c

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
 }
 /* }}} */