Skip to content

Commit 9cfcb06

Browse files
committed
bugfix: segmentation fault might happen in nginx 1.4.x when calling ngx.req.set_header on the Cookie request headers because recent versions of nginx no longer always initialize r->headers_in.cookies. thanks Rob W for reporting this issue as #237.
1 parent 06da40f commit 9cfcb06

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/ngx_http_lua_headers_in.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,17 @@ ngx_http_set_cookie_header(ngx_http_request_t *r,
424424
dd("clear headers in cookies: %d", (int) r->headers_in.cookies.nelts);
425425
}
426426

427+
#if 1
428+
if (r->headers_in.cookies.nalloc == 0) {
429+
if (ngx_array_init(&r->headers_in.cookies, r->pool, 2,
430+
sizeof(ngx_table_elt_t *))
431+
!= NGX_OK)
432+
{
433+
return NGX_ERROR;
434+
}
435+
}
436+
#endif
437+
427438
if (ngx_http_set_header_helper(r, hv, value, &h) == NGX_ERROR) {
428439
return NGX_ERROR;
429440
}

0 commit comments

Comments
 (0)