File tree Expand file tree Collapse file tree 4 files changed +32
-2
lines changed Expand file tree Collapse file tree 4 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,8 @@ PHP NEWS
8484 TCP_REUSPORT_LB_CURDOM, TCP_BBR_ALGORITHM constants.
8585 . socket_create_listen() throws an exception on invalid port value.
8686 (David Carlier)
87+ . socket_bind() throws an exception on invalid port value.
88+ (David Carlier)
8789
8890- Standard:
8991 . Fixed crypt() tests on musl when using --with-external-libcrypt
Original file line number Diff line number Diff line change @@ -125,8 +125,8 @@ PHP 8.5 UPGRADE NOTES
125125 last_error to EBADF and raises an E_WARNING message.
126126
127127- Sockets:
128- . socket_create_listen throws a ValueError if the port is
129- lower than 0 or greater than 65535.
128+ . socket_create_listen and socket_bind throw a ValueError
129+ if the port is lower than 0 or greater than 65535.
130130
131131- Zlib:
132132 . The "use_include_path" argument for the
Original file line number Diff line number Diff line change @@ -1288,6 +1288,11 @@ PHP_FUNCTION(socket_bind)
12881288 php_sock = Z_SOCKET_P (arg1 );
12891289 ENSURE_SOCKET_VALID (php_sock );
12901290
1291+ if (port < 0 || port > USHRT_MAX ) {
1292+ zend_argument_value_error (3 , "must be between 0 and %u" , USHRT_MAX );
1293+ RETURN_THROWS ();
1294+ }
1295+
12911296 switch (php_sock -> type ) {
12921297 case AF_UNIX :
12931298 {
Original file line number Diff line number Diff line change 1+ --TEST--
2+ socket_bind() with invalid ports.
3+ --EXTENSIONS--
4+ sockets
5+ --FILE--
6+ <?php
7+ $ s_c = socket_create (AF_INET , SOCK_STREAM , SOL_TCP );
8+
9+ try {
10+ socket_bind ($ s_c , '0.0.0.0 ' , -1 );
11+ } catch (\ValueError $ e ) {
12+ echo $ e ->getMessage () . PHP_EOL ;
13+ }
14+
15+ try {
16+ socket_bind ($ s_c , '0.0.0.0 ' , 65536 );
17+ } catch (\ValueError $ e ) {
18+ echo $ e ->getMessage () . PHP_EOL ;
19+ }
20+ ?>
21+ --EXPECT--
22+ socket_bind(): Argument #3 ($port) must be between 0 and 65535
23+ socket_bind(): Argument #3 ($port) must be between 0 and 65535
You can’t perform that action at this time.
0 commit comments