File tree Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -593,10 +593,15 @@ PHP_FUNCTION(ip2long)
593593 struct in_addr ip ;
594594
595595 ZEND_PARSE_PARAMETERS_START (1 , 1 )
596- Z_PARAM_STRING (addr , addr_len )
596+ Z_PARAM_PATH (addr , addr_len )
597597 ZEND_PARSE_PARAMETERS_END ();
598598
599- if (addr_len == 0 || inet_pton (AF_INET , addr , & ip ) != 1 ) {
599+ if (addr_len == 0 ) {
600+ zend_argument_must_not_be_empty_error (1 );
601+ RETURN_THROWS ();
602+ }
603+
604+ if (inet_pton (AF_INET , addr , & ip ) != 1 ) {
600605 RETURN_FALSE ;
601606 }
602607 RETURN_LONG (ntohl (ip .s_addr ));
Original file line number Diff line number Diff line change @@ -7,28 +7,36 @@ if (PHP_INT_SIZE == 4) die("skip this test is for >32bit platform only");
77--FILE--
88<?php
99
10- $ array = array (
10+ $ array = [
1111 "127.0.0.1 " ,
1212 "10.0.0.1 " ,
1313 "255.255.255.255 " ,
1414 "255.255.255.0 " ,
1515 "0.0.0.0 " ,
1616 "66.163.161.116 " ,
17- ) ;
17+ ] ;
1818
1919foreach ($ array as $ ip ) {
2020 var_dump ($ long = ip2long ($ ip ));
2121 var_dump (long2ip ($ long ));
2222}
23-
24- var_dump (ip2long ("" ));
2523var_dump (ip2long ("777.777.777.777 " ));
2624var_dump (ip2long ("111.111.111.111 " ));
2725
2826var_dump (long2ip (-110000 ));
2927var_dump (long2ip (PHP_INT_MAX ));
3028var_dump (long2ip (PHP_INT_MIN ));
3129
30+ try {
31+ var_dump (ip2long ("" ));
32+ } catch (Throwable $ e ) {
33+ echo $ e ::class, ': ' , $ e ->getMessage (), PHP_EOL ;
34+ }
35+ try {
36+ var_dump (ip2long ("127 \00.0.1 " ));
37+ } catch (Throwable $ e ) {
38+ echo $ e ::class, ': ' , $ e ->getMessage (), PHP_EOL ;
39+ }
3240echo "Done \n" ;
3341?>
3442--EXPECT--
@@ -45,9 +53,10 @@ string(7) "0.0.0.0"
4553int(1118019956)
4654string(14) "66.163.161.116"
4755bool(false)
48- bool(false)
4956int(1869573999)
5057string(13) "255.254.82.80"
5158string(15) "255.255.255.255"
5259string(7) "0.0.0.0"
60+ ValueError: ip2long(): Argument #1 ($ip) must not be empty
61+ ValueError: ip2long(): Argument #1 ($ip) must not contain any null bytes
5362Done
You can’t perform that action at this time.
0 commit comments