]> granicus.if.org Git - php/commitdiff
Fixed bug #47365 (ip2long() may allow some invalid values on certain 64bit
authorIlia Alshanetsky <iliaa@php.net>
Tue, 28 Apr 2009 22:27:00 +0000 (22:27 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 28 Apr 2009 22:27:00 +0000 (22:27 +0000)
systems)

ext/standard/basic_functions.c
ext/standard/tests/network/ip2long_variation1.phpt

index b65c4575fa9567651494efdef8d63c4dff9d3c17..fcf45d06027c3cd990c6b1f7bbc7af5386e8e8ff 100644 (file)
@@ -3897,12 +3897,22 @@ PHP_FUNCTION(ip2long)
 {
        char *addr;
        int addr_len;
+#ifdef HAVE_INET_PTON
+       struct in_addr ip;
+#else
        unsigned long int ip;
+#endif
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, &addr_len) == FAILURE) {
                return;
        }
 
+#ifdef HAVE_INET_PTON
+       if (addr_len == 0 || inet_pton(AF_INET, addr, &ip) != 1) {
+               RETURN_FALSE;
+       }
+       RETURN_LONG(ntohl(ip.s_addr));
+#else
        if (addr_len == 0 || (ip = inet_addr(addr)) == INADDR_NONE) {
                /* The only special case when we should return -1 ourselves,
                 * because inet_addr() considers it wrong. We return 0xFFFFFFFF and
@@ -3915,6 +3925,7 @@ PHP_FUNCTION(ip2long)
                RETURN_FALSE;
        }
        RETURN_LONG(ntohl(ip));
+#endif
 }
 /* }}} */
 
index 18e026b87c2563ed9ae9760535b7fbe152f82363..ac3c9c81e19ec127d70812bedff99940c10aa038 100644 (file)
@@ -114,19 +114,19 @@ fclose($res);
 *** Testing ip2long() : usage variation ***
 
 --int 0--
-int(0)
+bool(false)
 
 --int 1--
-int(1)
+bool(false)
 
 --int 12345--
-int(12345)
+bool(false)
 
 --int -12345--
 bool(false)
 
 --float 10.5--
-int(167772165)
+bool(false)
 
 --float -10.5--
 bool(false)
@@ -138,7 +138,7 @@ bool(false)
 bool(false)
 
 --float .5--
-int(5)
+bool(false)
 
 --empty array--
 Error: 2 - ip2long() expects parameter 1 to be string, array given, %s(%d)
@@ -163,13 +163,13 @@ bool(false)
 bool(false)
 
 --lowercase true--
-int(1)
+bool(false)
 
 --lowercase false--
 bool(false)
 
 --uppercase TRUE--
-int(1)
+bool(false)
 
 --uppercase FALSE--
 bool(false)