File tree Expand file tree Collapse file tree 4 files changed +44
-5
lines changed
Expand file tree Collapse file tree 4 files changed +44
-5
lines changed Original file line number Diff line number Diff line change @@ -513,7 +513,7 @@ ngx_http_lua_socket_tcp_connect(lua_State *L)
513513 if (n == 3 ) {
514514 port = luaL_checkinteger (L , 3 );
515515
516- if (port < 0 || port > 65536 ) {
516+ if (port < 0 || port > 65535 ) {
517517 lua_pushnil (L );
518518 lua_pushfstring (L , "bad port number: %d" , port );
519519 return 2 ;
@@ -942,7 +942,7 @@ ngx_http_lua_socket_resolve_handler(ngx_resolver_ctx_t *ctx)
942942#else
943943 /* for nginx older than 1.5.8 */
944944
945- len = NGX_INET_ADDRSTRLEN + sizeof (":65536 " ) - 1 ;
945+ len = NGX_INET_ADDRSTRLEN + sizeof (":65535 " ) - 1 ;
946946
947947 p = ngx_pnalloc (r -> pool , len + sizeof (struct sockaddr_in ));
948948 if (p == NULL ) {
Original file line number Diff line number Diff line change @@ -221,7 +221,7 @@ ngx_http_lua_socket_udp_setpeername(lua_State *L)
221221 if (n == 3 ) {
222222 port = luaL_checkinteger (L , 3 );
223223
224- if (port < 0 || port > 65536 ) {
224+ if (port < 0 || port > 65535 ) {
225225 lua_pushnil (L );
226226 lua_pushfstring (L , "bad port number: %d" , port );
227227 return 2 ;
@@ -574,7 +574,7 @@ ngx_http_lua_socket_resolve_handler(ngx_resolver_ctx_t *ctx)
574574#else
575575 /* for nginx older than 1.5.8 */
576576
577- len = NGX_INET_ADDRSTRLEN + sizeof (":65536 " ) - 1 ;
577+ len = NGX_INET_ADDRSTRLEN + sizeof (":65535 " ) - 1 ;
578578
579579 p = ngx_pnalloc (r -> pool , len + sizeof (struct sockaddr_in ));
580580 if (p == NULL ) {
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use Test::Nginx::Socket::Lua;
44
55repeat_each(2);
66
7- plan tests => repeat_each() * 193 ;
7+ plan tests => repeat_each() * 196 ;
88
99our $HtmlDir = html_dir;
1010
@@ -3727,3 +3727,22 @@ failed to connect: www.google.com could not be resolved
37273727hello!
37283728--- error_log eval
37293729qr{\[alert\] .*? send\(\) failed \(\d+: Operation not permitted\) while resolving}
3730+
3731+
3732+
3733+ === TEST 62: the upper bound of port range should be 2^16 - 1
3734+ --- config
3735+ location /t {
3736+ content_by_lua_block {
3737+ local sock, err = ngx.socket.connect("127.0.0.1", 65536)
3738+ if not sock then
3739+ ngx.say("failed to connect: ", err)
3740+ end
3741+ }
3742+ }
3743+ --- request
3744+ GET /t
3745+ --- response_body
3746+ failed to connect: bad port number: 65536
3747+ --- no_error_log
3748+ [error]
Original file line number Diff line number Diff line change @@ -1104,3 +1104,23 @@ qr/runtime error: content_by_lua\(nginx\.conf:\d+\):14: bad request/
11041104
11051105-- - no_error_log
11061106[alert]
1107+
1108+
1109+
1110+ === TEST 20 : the upper bound of port range should be 2 ^ 16 - 1
1111+ -- - config
1112+ location / t {
1113+ content_by_lua_block {
1114+ local sock = ngx. socket. udp()
1115+ local ok , err = sock: setpeername(" 127.0.0.1" , 65536 )
1116+ if not ok then
1117+ ngx. say (" failed to connect: " , err)
1118+ end
1119+ }
1120+ }
1121+ -- - request
1122+ GET / t
1123+ -- - response_body
1124+ failed to connect : bad port number: 65536
1125+ -- - no_error_log
1126+ [error]
You can’t perform that action at this time.
0 commit comments