Skip to content

Commit 5134a9c

Browse files
jayceagentzh
authored andcommitted
bugfix: segmentation faults might happen when ngx.exec() was fed with unsafe URIs (openresty#905)
Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
1 parent 397f366 commit 5134a9c

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/ngx_http_lua_control.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ ngx_http_lua_ngx_exec(lua_State *L)
105105

106106
ngx_http_lua_check_if_abortable(L, ctx);
107107

108-
if (ngx_http_parse_unsafe_uri(r, &uri, &args, &flags)
109-
!= NGX_OK)
110-
{
111-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
108+
flags = NGX_HTTP_LOG_UNSAFE;
109+
110+
if (ngx_http_parse_unsafe_uri(r, &uri, &args, &flags) != NGX_OK) {
111+
return luaL_error(L, "unsafe uri");
112112
}
113113

114114
if (n == 2) {

t/024-access/exec.t

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
use Test::Nginx::Socket::Lua;
44

55
repeat_each(2);
6-
#repeat_each(1);
76

8-
plan tests => blocks() * repeat_each() * 2;
7+
plan tests => repeat_each() * (blocks() * 2 + 2);
98

109
#no_diff();
1110
#no_long_string();
@@ -349,3 +348,24 @@ hello
349348
--- response_body
350349
hello, bah
351350

351+
352+
353+
=== TEST 16: github issue #905: unsafe uri
354+
--- config
355+
location /read {
356+
access_by_lua_block {
357+
ngx.exec("/hi/../");
358+
}
359+
}
360+
location /hi {
361+
echo "Hello";
362+
}
363+
--- request
364+
GET /read
365+
--- response_body_like: 500 Internal Server Error
366+
--- error_code: 500
367+
--- error_log eval
368+
[
369+
'unsafe URI "/hi/../" was detected',
370+
qr/runtime error: access_by_lua\(nginx.conf:\d+\):2: unsafe uri/,
371+
]

0 commit comments

Comments
 (0)