Skip to content

Commit acda31f

Browse files
authored
bugfix: backport: avoid buf double free in ngx.print if lua body filt… (#68)
1 parent a5571f7 commit acda31f

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
diff --git src/ngx_http_lua_bodyfilterby.c src/ngx_http_lua_bodyfilterby.c
2+
index 632f5afe..a8a382ac 100644
3+
--- src/ngx_http_lua_bodyfilterby.c
4+
+++ src/ngx_http_lua_bodyfilterby.c
5+
@@ -299,7 +299,7 @@ ngx_http_lua_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
6+
out = NULL;
7+
ngx_chain_update_chains(r->pool,
8+
&ctx->free_bufs, &ctx->filter_busy_bufs, &out,
9+
- (ngx_buf_tag_t) &ngx_http_lua_module);
10+
+ (ngx_buf_tag_t) &ngx_http_lua_body_filter);
11+
if (rc != NGX_OK
12+
&& ctx->filter_busy_bufs != NULL
13+
&& (r->connection->buffered
14+
@@ -378,7 +378,7 @@ ngx_http_lua_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
15+
16+
ngx_chain_update_chains(r->pool,
17+
&ctx->free_bufs, &ctx->filter_busy_bufs, &out,
18+
- (ngx_buf_tag_t) &ngx_http_lua_module);
19+
+ (ngx_buf_tag_t) &ngx_http_lua_body_filter);
20+
21+
return rc;
22+
}
23+
@@ -657,6 +657,7 @@ ngx_http_lua_body_filter_param_set(lua_State *L, ngx_http_request_t *r,
24+
return luaL_error(L, "no memory");
25+
}
26+
27+
+ cl->buf->tag = (ngx_buf_tag_t) &ngx_http_lua_body_filter;
28+
if (type == LUA_TTABLE) {
29+
cl->buf->last = ngx_http_lua_copy_str_in_table(L, 3, cl->buf->last);
30+
31+
@@ -674,6 +675,8 @@ done:
32+
if (cl == NULL) {
33+
return luaL_error(L, "no memory");
34+
}
35+
+
36+
+ cl->buf->tag = (ngx_buf_tag_t) &ngx_http_lua_body_filter;
37+
}
38+
39+
if (last) {

t/ngx-buf-double-free.t

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use t::APISIX_NGINX 'no_plan';
2+
3+
run_tests();
4+
5+
__DATA__
6+
7+
=== TEST 1: ngx.say (integer)
8+
--- config
9+
location /t {
10+
content_by_lua_block {
11+
local str = string.rep(".", 1300)
12+
ngx.print(str)
13+
ngx.flush()
14+
ngx.print("small chunk")
15+
ngx.flush()
16+
}
17+
body_filter_by_lua_block {local dummy=1}
18+
}
19+
--- request
20+
GET /t
21+
--- response_body_like: small chunk

0 commit comments

Comments
 (0)