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

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

index 50e54aec58450633af13d78b3baf4f12e42ef97a..59d9aefb8ada4ae58ccc29644549ef875e82dd8d 100644 (file)
@@ -3877,12 +3877,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
@@ -3895,6 +3905,7 @@ PHP_FUNCTION(ip2long)
                RETURN_FALSE;
        }
        RETURN_LONG(ntohl(ip));
+#endif
 }
 /* }}} */
 
index 1a9ea4b64d8042b727818534c97a1e4a13bd5a03..b2afcd740ff054a1ed05e833af9c671bb37e85e1 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 binary 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)