Skip to content

Commit afbfe4c

Browse files
committed
bugfix: the timeout overflow checks did not work on 32-bit systems.
1 parent aee660b commit afbfe4c

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/ngx_http_lua_socket_tcp.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2711,9 +2711,8 @@ ngx_http_lua_socket_tcp_settimeout(lua_State *L)
27112711
}
27122712

27132713
timeout = (ngx_int_t) lua_tonumber(L, 2);
2714-
if (timeout > (ngx_int_t) NGX_MAX_INT32_VALUE) {
2715-
return luaL_error(L, "lua tcp socket timeout %f will overflow",
2716-
(lua_Number) timeout);
2714+
if (timeout >> 31) {
2715+
return luaL_error(L, "timeout value too large");
27172716
}
27182717

27192718
lua_pushinteger(L, timeout);
@@ -2759,21 +2758,18 @@ ngx_http_lua_socket_tcp_settimeouts(lua_State *L)
27592758
}
27602759

27612760
connect_timeout = (ngx_int_t) lua_tonumber(L, 2);
2762-
if (connect_timeout > (ngx_int_t) NGX_MAX_INT32_VALUE) {
2763-
return luaL_error(L, "lua tcp socket connect timeout %f will overflow",
2764-
(lua_Number) connect_timeout);
2761+
if (connect_timeout >> 31) {
2762+
return luaL_error(L, "timeout value too large");
27652763
}
27662764

27672765
send_timeout = (ngx_int_t) lua_tonumber(L, 3);
2768-
if (send_timeout > (ngx_int_t) NGX_MAX_INT32_VALUE) {
2769-
return luaL_error(L, "lua tcp socket send timeout %f will overflow",
2770-
(lua_Number) send_timeout);
2766+
if (send_timeout >> 31) {
2767+
return luaL_error(L, "timeout value too large");
27712768
}
27722769

27732770
read_timeout = (ngx_int_t) lua_tonumber(L, 4);
2774-
if (read_timeout > (ngx_int_t) NGX_MAX_INT32_VALUE) {
2775-
return luaL_error(L, "lua tcp socket read timeout %f will overflow",
2776-
(lua_Number) read_timeout);
2771+
if (read_timeout >> 31) {
2772+
return luaL_error(L, "timeout value too large");
27772773
}
27782774

27792775
lua_rawseti(L, 1, SOCKET_READ_TIMEOUT_INDEX);

t/147-tcp-socket-timeouts.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ failed to receive a line: closed []
560560
GET /t
561561
--- response_body_like
562562
settimeouts: ok
563-
failed to set timeouts: lua tcp socket connect timeout 2147483648(?:\.\d+)? will overflow
563+
failed to set timeouts: timeout value too large
564564
--- no_error_log
565565
[error]
566566

@@ -591,7 +591,7 @@ failed to set timeouts: lua tcp socket connect timeout 2147483648(?:\.\d+)? will
591591
GET /t
592592
--- response_body_like
593593
settimeouts: ok
594-
failed to set timeouts: lua tcp socket send timeout 2147483648(?:\.\d+)? will overflow
594+
failed to set timeouts: timeout value too large
595595
--- no_error_log
596596
[error]
597597

@@ -622,6 +622,6 @@ failed to set timeouts: lua tcp socket send timeout 2147483648(?:\.\d+)? will ov
622622
GET /t
623623
--- response_body_like
624624
settimeouts: ok
625-
failed to set timeouts: lua tcp socket read timeout 2147483648(?:\.\d+)? will overflow
625+
failed to set timeouts: timeout value too large
626626
--- no_error_log
627627
[error]

0 commit comments

Comments
 (0)