iliaa           Tue Apr 28 22:31:26 2009 UTC

  Modified files:              (Branch: PHP_5_2)
    /php-src/ext/standard       basic_functions.c 
    /php-src/ext/standard/tests/network ip2long_variation1.phpt 
    /php-src    NEWS 
  Log:
  
  MFB: Fixed bug #47365 (ip2long() may allow some invalid values on certain
  64bit systems)
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?r1=1.725.2.31.2.80&r2=1.725.2.31.2.81&diff_format=u
Index: php-src/ext/standard/basic_functions.c
diff -u php-src/ext/standard/basic_functions.c:1.725.2.31.2.80 
php-src/ext/standard/basic_functions.c:1.725.2.31.2.81
--- php-src/ext/standard/basic_functions.c:1.725.2.31.2.80      Wed Dec 31 
11:17:44 2008
+++ php-src/ext/standard/basic_functions.c      Tue Apr 28 22:31:25 2009
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: basic_functions.c,v 1.725.2.31.2.80 2008/12/31 11:17:44 sebastian Exp 
$ */
+/* $Id: basic_functions.c,v 1.725.2.31.2.81 2009/04/28 22:31:25 iliaa Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -4329,38 +4329,45 @@
 /* }}} */
 #endif /* HAVE_INET_PTON */
 
-
-
 /* {{{ proto int ip2long(string ip_address)
    Converts a string containing an (IPv4) Internet Protocol dotted address 
into a proper address */
 PHP_FUNCTION(ip2long)
 {
-       zval **str;
+       char *addr;
+       int addr_len;
+#ifdef HAVE_INET_PTON
+       struct in_addr ip;
+#else
        unsigned long int ip;
+#endif
 
-       if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) 
{
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &addr, 
&addr_len) == FAILURE) {
+               return;
        }
 
-       convert_to_string_ex(str);
-
-       if (Z_STRLEN_PP(str) == 0 || (ip = inet_addr(Z_STRVAL_PP(str))) == 
INADDR_NONE) {
-               /* the only special case when we should return -1 ourselves,
+#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
-                * not -1 or ~0 because of 32/64bit issues.
-                */
-               if (Z_STRLEN_PP(str) == sizeof("255.255.255.255") - 1 &&
-                       !memcmp(Z_STRVAL_PP(str), "255.255.255.255", 
sizeof("255.255.255.255") - 1)) {
+                * not -1 or ~0 because of 32/64bit issues. */
+               if (addr_len == sizeof("255.255.255.255") - 1 &&
+                       !memcmp(addr, "255.255.255.255", 
sizeof("255.255.255.255") - 1)
+               ) {
                        RETURN_LONG(0xFFFFFFFF);
                }
-               
                RETURN_FALSE;
        }
-
        RETURN_LONG(ntohl(ip));
+#endif
 }
 /* }}} */
 
+
 /* {{{ proto string long2ip(int proper_address)
    Converts an (IPv4) Internet network address into a string in Internet 
standard dotted format */
 PHP_FUNCTION(long2ip)
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/network/ip2long_variation1.phpt?r1=1.2.2.2&r2=1.2.2.3&diff_format=u
Index: php-src/ext/standard/tests/network/ip2long_variation1.phpt
diff -u php-src/ext/standard/tests/network/ip2long_variation1.phpt:1.2.2.2 
php-src/ext/standard/tests/network/ip2long_variation1.phpt:1.2.2.3
--- php-src/ext/standard/tests/network/ip2long_variation1.phpt:1.2.2.2  Fri Jan 
23 15:34:24 2009
+++ php-src/ext/standard/tests/network/ip2long_variation1.phpt  Tue Apr 28 
22:31:25 2009
@@ -114,19 +114,19 @@
 *** 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)
 
 --float .5--
-int(5)
+bool(false)
 
 --empty array--
 Error: 8 - Array to string conversion, %s(%d)
@@ -163,13 +163,13 @@
 bool(false)
 
 --lowercase true--
-int(1)
+bool(false)
 
 --lowercase false--
 bool(false)
 
 --uppercase TRUE--
-int(1)
+bool(false)
 
 --uppercase FALSE--
 bool(false)
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.1478&r2=1.2027.2.547.2.1479&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.1478 php-src/NEWS:1.2027.2.547.2.1479
--- php-src/NEWS:1.2027.2.547.2.1478    Tue Apr 28 13:01:04 2009
+++ php-src/NEWS        Tue Apr 28 22:31:25 2009
@@ -48,6 +48,8 @@
 - Fixed bug #47598 (FILTER_VALIDATE_EMAIL is locale aware). (Ilia)
 - Fixed bug #47487 (performance degraded when reading large chunks after fix of
   bug #44607). (Arnaud)
+- Fixed bug #47365 (ip2long() may allow some invalid values on certain 64bit  
+  systems). (Ilia)
 - Fixed bug #47435 (FILTER_FLAG_NO_PRIV_RANGE does not work with ipv6
   addresses in the filter extension). (Ilia)
 - Fixed bug #47430 (Errors after writing to nodeValue parameter of an absent 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to