bugfix: bogus nginx.conf parse failure "Lua code block missing the "}" character" might happen when there are many Lua code blocks inlined. thanks Andreas Lubbe for the report and test case in #611.

This commit is contained in:
Yichun Zhang (agentzh) 2015-11-25 20:19:25 +08:00
Родитель 2b93087210
Коммит 94f68befa3
2 изменённых файлов: 128 добавлений и 5 удалений

Просмотреть файл

@ -1555,12 +1555,50 @@ ngx_http_lua_conf_read_lua_token(ngx_conf_t *cf,
rc = ngx_http_lua_lex(b->pos, b->last - b->pos, ovec);
if (rc < 0) { /* no match */
cf->conf_file->line = start_line;
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"Lua code block missing the \"}\" "
"character");
/* alas. the lexer does not yet support streaming processing. need
* more work below */
return NGX_ERROR;
if (cf->conf_file->file.offset >= file_size) {
cf->conf_file->line = ctx->start_line;
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"unexpected end of file, expecting "
"terminating characters for lua code "
"block");
return NGX_ERROR;
}
len = b->last - b->pos;
ngx_memcpy(b->start, b->pos, len);
size = (ssize_t) (file_size - cf->conf_file->file.offset);
if (size > b->end - (b->start + len)) {
size = b->end - (b->start + len);
}
n = ngx_read_file(&cf->conf_file->file, b->start + len, size,
cf->conf_file->file.offset);
if (n == NGX_ERROR) {
return NGX_ERROR;
}
if (n != size) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
ngx_read_file_n " returned "
"only %z bytes instead of %z",
n, size);
return NGX_ERROR;
}
b->pos = b->start + len;
b->last = b->pos + n;
start = b->start;
continue;
}
if (rc == FOUND_LEFT_LBRACKET_STR || rc == FOUND_LEFT_LBRACKET_CMT) {

Просмотреть файл

@ -488,3 +488,88 @@ GET /t
Hey, it is '!
--- no_error_log
[error]
=== TEST 21: lexer no match due to incomplete data chunks in a fixed size buffer
--- config
location /test1 {
content_by_lua_block {
ngx.say("1: this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error")
}
}
location /test2 {
content_by_lua_block {
ngx.say("2: this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error")
}
}
location /test3 {
content_by_lua_block {
ngx.say("3: this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error",
"this is just some random filler to cause an error")
}
}
--- request
GET /test3
--- response_body eval
"3: " . ("this is just some random filler to cause an error" x 20) . "\n"
--- no_error_log
[error]