]> granicus.if.org Git - php/commitdiff
Fixed bug #71100 (long2ip() doesn't accept integers in strict mode)
authorXinchen Hui <laruence@gmail.com>
Mon, 14 Dec 2015 06:55:44 +0000 (14:55 +0800)
committerXinchen Hui <laruence@gmail.com>
Mon, 14 Dec 2015 06:55:44 +0000 (14:55 +0800)
NEWS
UPGRADING
ext/standard/basic_functions.c
ext/standard/tests/network/ip.phpt
ext/standard/tests/network/ip_x86_64.phpt
ext/standard/tests/network/long2ip_variation1.phpt

diff --git a/NEWS b/NEWS
index fa627f6e0c3190f77eb35e492fae5e7f4665ab98..9f0ff8622ddabec4e651450467f7d60e5ab9c56d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,8 @@ PDO_Firebird:
   . Fixed bug #60052 (Integer returned as a 64bit integer on X64_86). (Mariuz)
 
 Standard:
+  . Fixed bug #71100 (long2ip() doesn't accept integers in strict mode).
+    (Laruence)
   . Implemented FR #55716 (Add an option to pass a custom stream context to
     get_headers()). (Ferenc)
   . Implemented FR #69359 (Provide a way to fetch the current environment
index 8929404d985a0910a310e7bbff33769b3f2e398b..ff983ca25bb1b51c95599768b298e9c2e613c205 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -45,6 +45,7 @@ PHP 7.1 UPGRADE NOTES
 - The first $varname argument for getenv() is no longer mandatory, the
   current environment variables will be returned as an associative array
   when omitted.
+- long2ip accepts interge as parameter now
 
 ========================================
 6. New Functions
index 5334e26439b780c9693a8e60bf74f2ca0d4cf4f6..e9613717bee4b350c5aeedf0e72295df48730973 100644 (file)
@@ -3978,22 +3978,17 @@ PHP_FUNCTION(ip2long)
    Converts an (IPv4) Internet network address into a string in Internet standard dotted format */
 PHP_FUNCTION(long2ip)
 {
-       /* "It's a long but it's not, PHP ints are signed */
-       char *ip;
-       size_t ip_len;
-       uint32_t n;
+       zend_ulong ip;
        struct in_addr myaddr;
 #ifdef HAVE_INET_PTON
        char str[40];
 #endif
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &ip, &ip_len) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &ip) == FAILURE) {
                return;
        }
 
-       n = strtoul(ip, NULL, 0);
-
-       myaddr.s_addr = htonl(n);
+       myaddr.s_addr = htonl(ip);
 #ifdef HAVE_INET_PTON
        if (inet_ntop(AF_INET, &myaddr, str, sizeof(str))) {
                RETURN_STRING(str);
index 3fc1b9dcf4a5d5f2e01e854c1e223b0b1aae3671..81b7c37c7300893d807152abef5ef5c12684ea75 100644 (file)
@@ -41,27 +41,29 @@ int(167772161)
 string(8) "10.0.0.1"
 int(-1)
 string(15) "255.255.255.255"
-int(-256)
+int(-1)
 string(13) "255.255.255.0"
 int(0)
 string(7) "0.0.0.0"
 int(1118019956)
 string(14) "66.163.161.116"
 
-Warning: ip2long() expects exactly 1 parameter, 0 given in %s on line %d
+Warning: ip2long() expects exactly 1 parameter, 0 given in %sip.php on line %d
 NULL
 bool(false)
 bool(false)
 int(1869573999)
 
-Warning: ip2long() expects parameter 1 to be string, array given in %s on line %d
+Warning: ip2long() expects parameter 1 to be string, array given in %sip.php on line %d
 NULL
 
-Warning: long2ip() expects exactly 1 parameter, 0 given in %s on line %d
+Warning: long2ip() expects exactly 1 parameter, 0 given in %sip.php on line %d
 NULL
 string(13) "255.254.82.80"
-string(7) "0.0.0.0"
 
-Warning: long2ip() expects parameter 1 to be string, array given in %s on line %d
+Warning: long2ip() expects parameter 1 to be integer, string given in %sip.php on line %d
+NULL
+
+Warning: long2ip() expects parameter 1 to be integer, array given in %sip.php on line %d
 NULL
 Done
index 1fcb8b2043cf61f661ca8f13112cfaf4a37a9638..45a48ca9dfcf1eacca82a856ea6657ebe46b755f 100644 (file)
@@ -48,20 +48,22 @@ string(7) "0.0.0.0"
 int(1118019956)
 string(14) "66.163.161.116"
 
-Warning: ip2long() expects exactly 1 parameter, 0 given in %s on line %d
+Warning: ip2long() expects exactly 1 parameter, 0 given in %sip_x86_64.php on line %d
 NULL
 bool(false)
 bool(false)
 int(1869573999)
 
-Warning: ip2long() expects parameter 1 to be string, array given in %s on line %d
+Warning: ip2long() expects parameter 1 to be string, array given in %sip_x86_64.php on line %d
 NULL
 
-Warning: long2ip() expects exactly 1 parameter, 0 given in %s on line %d
+Warning: long2ip() expects exactly 1 parameter, 0 given in %sip_x86_64.php on line %d
 NULL
 string(13) "255.254.82.80"
-string(7) "0.0.0.0"
 
-Warning: long2ip() expects parameter 1 to be string, array given in %s on line %d
+Warning: long2ip() expects parameter 1 to be integer, string given in %sip_x86_64.php on line %d
+NULL
+
+Warning: long2ip() expects parameter 1 to be integer, array given in %sip_x86_64.php on line %d
 NULL
 Done
index 2dc6fb123b31feaa9b7457aaf82475357ab5aa95..e7336712beb166364913fec7b2e8fa53b113048e 100644 (file)
@@ -126,19 +126,19 @@ string(15) "255.255.255.246"
 string(7) "0.0.0.0"
 
 --empty array--
-Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d)
+Error: 2 - long2ip() expects parameter 1 to be integer, array given, %slong2ip_variation1.php(%d)
 NULL
 
 --int indexed array--
-Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d)
+Error: 2 - long2ip() expects parameter 1 to be integer, array given, %slong2ip_variation1.php(%d)
 NULL
 
 --associative array--
-Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d)
+Error: 2 - long2ip() expects parameter 1 to be integer, array given, %slong2ip_variation1.php(%d)
 NULL
 
 --nested arrays--
-Error: 2 - long2ip() expects parameter 1 to be string, array given, %s(%d)
+Error: 2 - long2ip() expects parameter 1 to be integer, array given, %slong2ip_variation1.php(%d)
 NULL
 
 --uppercase NULL--
@@ -160,28 +160,35 @@ string(7) "0.0.0.1"
 string(7) "0.0.0.0"
 
 --empty string DQ--
-string(7) "0.0.0.0"
+Error: 2 - long2ip() expects parameter 1 to be integer, string given, %slong2ip_variation1.php(%d)
+NULL
 
 --empty string SQ--
-string(7) "0.0.0.0"
+Error: 2 - long2ip() expects parameter 1 to be integer, string given, %slong2ip_variation1.php(%d)
+NULL
 
 --string DQ--
-string(7) "0.0.0.0"
+Error: 2 - long2ip() expects parameter 1 to be integer, string given, %slong2ip_variation1.php(%d)
+NULL
 
 --string SQ--
-string(7) "0.0.0.0"
+Error: 2 - long2ip() expects parameter 1 to be integer, string given, %slong2ip_variation1.php(%d)
+NULL
 
 --mixed case string--
-string(7) "0.0.0.0"
+Error: 2 - long2ip() expects parameter 1 to be integer, string given, %slong2ip_variation1.php(%d)
+NULL
 
 --heredoc--
-string(7) "0.0.0.0"
+Error: 2 - long2ip() expects parameter 1 to be integer, string given, %slong2ip_variation1.php(%d)
+NULL
 
 --instance of classWithToString--
-string(7) "0.0.0.0"
+Error: 2 - long2ip() expects parameter 1 to be integer, object given, %slong2ip_variation1.php(%d)
+NULL
 
 --instance of classWithoutToString--
-Error: 2 - long2ip() expects parameter 1 to be string, object given, %s(%d)
+Error: 2 - long2ip() expects parameter 1 to be integer, object given, %slong2ip_variation1.php(%d)
 NULL
 
 --undefined var--
@@ -191,6 +198,6 @@ string(7) "0.0.0.0"
 string(7) "0.0.0.0"
 
 --resource--
-Error: 2 - long2ip() expects parameter 1 to be string, resource given, %s(%d)
+Error: 2 - long2ip() expects parameter 1 to be integer, resource given, %slong2ip_variation1.php(%d)
 NULL
 ===DONE===