Skip to content

Commit 73ed3ae

Browse files
committed
fix: param type and addr struct build
1 parent a3d9c7a commit 73ed3ae

File tree

3 files changed

+12
-28
lines changed

3 files changed

+12
-28
lines changed

src/ngx_http_lua_socket_tcp.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -869,14 +869,16 @@ ngx_http_lua_socket_tcp_bind(lua_State *L)
869869

870870
port = 0;
871871
/* handle case: host:port */
872-
if (n == 3 && lua_isnumber(L, 3)) {
873-
874-
/* Hit the following parameter combination:
875-
* sock:bind("127.0.0.1", port)
876-
*/
872+
/* Hit the following parameter combination:
873+
* sock:bind("127.0.0.1", port) */
874+
if (n == 3) {
875+
if (!lua_isnumber(L, 3)) {
876+
lua_pushnil(L);
877+
lua_pushliteral(L, "bad port number: need int type");
878+
return 2;
879+
}
877880

878881
port = (int) lua_tointeger(L, 3);
879-
880882
if (port < 0 || port > 65535) {
881883
lua_pushnil(L);
882884
lua_pushfstring(L, "bad port number: %d", port);
@@ -886,13 +888,16 @@ ngx_http_lua_socket_tcp_bind(lua_State *L)
886888

887889
text = (u_char *) luaL_checklstring(L, 2, &len);
888890

889-
local = ngx_http_lua_parse_address_with_port(L, text, len, port);
891+
local = ngx_http_lua_parse_addr(L, text, len);
890892
if (local == NULL) {
891893
lua_pushnil(L);
892894
lua_pushfstring(L, "bad address");
893895
return 2;
894896
}
895897

898+
if (port > 0) {
899+
ngx_inet_set_port(addr->sockaddr, (in_port_t) port);
900+
}
896901
/* TODO: we may reuse the userdata here */
897902
lua_rawseti(L, 1, SOCKET_BIND_INDEX);
898903
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,

src/ngx_http_lua_util.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4555,24 +4555,6 @@ ngx_http_lua_parse_addr(lua_State *L, u_char *text, size_t len)
45554555
}
45564556

45574557

4558-
ngx_addr_t *
4559-
ngx_http_lua_parse_address_with_port(lua_State *L, u_char *text,
4560-
size_t len, int port)
4561-
{
4562-
ngx_addr_t *addr;
4563-
4564-
addr = ngx_http_lua_parse_addr(L, text, len);
4565-
if (addr == NULL) {
4566-
return addr;
4567-
}
4568-
4569-
if (port > 0) {
4570-
ngx_inet_set_port(addr->sockaddr, (in_port_t) port);
4571-
}
4572-
return addr;
4573-
}
4574-
4575-
45764558
void
45774559
ngx_http_lua_ffi_bypass_if_checks(ngx_http_request_t *r)
45784560
{

src/ngx_http_lua_util.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,6 @@ ngx_int_t ngx_http_lua_decode_base64mime(ngx_str_t *dst, ngx_str_t *src);
265265

266266
ngx_addr_t *ngx_http_lua_parse_addr(lua_State *L, u_char *text, size_t len);
267267

268-
ngx_addr_t *ngx_http_lua_parse_address_with_port(lua_State *L, u_char *text,
269-
size_t len, int port);
270-
271268
size_t ngx_http_lua_escape_log(u_char *dst, u_char *src, size_t size);
272269

273270

0 commit comments

Comments
 (0)