Skip to content

Commit

Permalink
Merge pull request alibaba#347 from yaoweibin/tengine-1.5.2
Browse files Browse the repository at this point in the history
Tengine 1.5.2
  • Loading branch information
Chuanwen Chen committed Nov 22, 2013
2 parents ddf159e + 31636e8 commit 6410df2
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 27 deletions.
5 changes: 4 additions & 1 deletion CHANGES.cn
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Tengine-1.5.2 [2013-11-21]

Tengine-1.5.2 [2013-11-22]
* Security: 修复CVE-2013-4547安全漏洞
* Bugfix: 修复limit_req模块中nodelay无效的问题 [cfsego]
* Bugfix: 修复trim模块在替换javascript异常的问题 [taoyuanyuan]

Tengine-1.5.1 [2013-08-29]
* Feature: 增加retry_cached_connection指令,可以关闭对后端长连接的无条件重试 [yaoweibin]
Expand Down
10 changes: 9 additions & 1 deletion CHANGES.te
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
Changes with Tengine 1.5.2 21 Nov 2013

Changes with Tengine 1.5.2 22 Nov 2013

*) Security: a character following an unescaped space in a request line
was handled incorrectly (CVE-2013-4547); the bug had appeared in
0.8.41.
Thanks to Ivan Fratric of the Google Security Team.

*) Bugfix: fix a bug of 'nodelay' might be ignored in limit_req module.
(cfsego)

*) Bugfix: fix a bug in trim module when processing javascript comment.
(taoyuanyuan)

Changes with Tengine 1.5.1 29 Aug 2013

*) Feature: added the directive 'retry_cached_connection' which could
Expand Down
2 changes: 2 additions & 0 deletions src/http/modules/ngx_http_footer_filter_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ ngx_http_footer_header_filter(ngx_http_request_t *r)
|| (r->method & NGX_HTTP_HEAD)
|| r != r->main
|| r->headers_out.status == NGX_HTTP_NO_CONTENT
|| (r->headers_out.content_encoding
&& r->headers_out.content_encoding->value.len)
|| ngx_http_test_content_type(r, &lcf->types) == NULL)
{
return ngx_http_next_header_filter(r);
Expand Down
2 changes: 1 addition & 1 deletion src/http/modules/ngx_http_limit_req_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ ngx_http_limit_req(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)

shm_zone = NULL;
burst = 0;
nodelay = 1;
nodelay = 0;
ngx_str_null(&forbid_action);

for (i = 1; i < cf->args->nelts; i++) {
Expand Down
69 changes: 49 additions & 20 deletions src/http/modules/ngx_http_trim_filter_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define NGX_HTTP_TRIM_SAVE_SLASH -1
#define NGX_HTTP_TRIM_SAVE_JSCSS -2
#define NGX_HTTP_TRIM_SAVE_HACKCSS -3
#define NGX_HTTP_TRIM_SAVE_JAVASCRIPT -4


typedef struct {
Expand Down Expand Up @@ -42,8 +43,7 @@ typedef struct {


typedef enum {
trim_state_start = 0,
trim_state_text,
trim_state_text = 0,
trim_state_text_whitespace, /* \r \t ' ' */
trim_state_tag, /* < */
trim_state_tag_text,
Expand Down Expand Up @@ -91,6 +91,7 @@ typedef enum {
trim_state_tag_script_js_whitespace,
trim_state_tag_script_js_comment_begin,
trim_state_tag_script_js_single_comment,
trim_state_tag_script_js_single_comment_end,
trim_state_tag_script_js_multi_comment,
trim_state_tag_script_js_multi_comment_end,
trim_state_comment_begin, /* <!-- */
Expand Down Expand Up @@ -312,6 +313,10 @@ ngx_http_trim_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
} else if (ctx->saved == NGX_HTTP_TRIM_SAVE_HACKCSS) {
cl->buf->pos = ngx_http_trim_saved_css_hack.data;
cl->buf->last = cl->buf->pos + ngx_http_trim_saved_css_hack.len;

} else if (ctx->saved == NGX_HTTP_TRIM_SAVE_JAVASCRIPT) {
cl->buf->pos = ngx_http_trim_script.data;
cl->buf->last = cl->buf->pos + ngx_http_trim_script.len - 1;
}

*ll = cl;
Expand Down Expand Up @@ -382,23 +387,6 @@ ngx_http_trim_parse(ngx_http_request_t *r, ngx_buf_t *buf,

switch (ctx->state) {

case trim_state_start:
switch (ch) {
case '\r':
case '\n':
case '\t':
case ' ':
continue;
case '<':
ctx->state = trim_state_tag;
ctx->saved_comment = 1;
continue;
default:
ctx->state = trim_state_text;
break;
}
break;

case trim_state_text:
switch (ch) {
case '\r':
Expand Down Expand Up @@ -881,6 +869,10 @@ ngx_http_trim_parse(ngx_http_request_t *r, ngx_buf_t *buf,

case trim_state_tag_script_js_single_comment:
switch (ch) {
case '<':
ctx->looked = 1;
ctx->state = trim_state_tag_script_js_single_comment_end;
continue;
case '\n':
ctx->state = trim_state_tag_script_js_text;
if (trim_js_prefix[ctx->prev >> 5] & (1 << (ctx->prev & 0x1f))
Expand All @@ -896,6 +888,41 @@ ngx_http_trim_parse(ngx_http_request_t *r, ngx_buf_t *buf,
}
break;

case trim_state_tag_script_js_single_comment_end:
look = ngx_http_trim_script.data[ctx->looked++];
if (ch == look) {
if (ctx->looked == ngx_http_trim_script.len) {
ctx->state = trim_state_text;
ctx->looked = 0;

if ((size_t) (read - buf->pos)
>= ngx_http_trim_script.len - 1)
{
write = ngx_cpymem(write, ngx_http_trim_script.data,
ngx_http_trim_script.len - 1);

} else {
ctx->saved = NGX_HTTP_TRIM_SAVE_JAVASCRIPT;
}

break;
}

continue;
}

switch (ch) {
case '<':
ctx->looked = 1;
break;
default:
ctx->state = trim_state_tag_script_js_single_comment;
ctx->looked = 0;
break;
}

continue;

case trim_state_tag_script_js_multi_comment:
switch (ch) {
case '*':
Expand Down Expand Up @@ -1192,7 +1219,9 @@ ngx_http_trim_parse(ngx_http_request_t *r, ngx_buf_t *buf,
case '/':
ctx->state = trim_state_tag_style_css_text;

if ((size_t) (read - buf->pos) >= ngx_http_trim_saved_jscss.len) {
if ((size_t) (read - buf->pos)
>= ngx_http_trim_saved_jscss.len)
{
write = ngx_cpymem(write, ngx_http_trim_saved_jscss.data,
ngx_http_trim_saved_jscss.len);

Expand Down
11 changes: 11 additions & 0 deletions src/http/ngx_http_request_body.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,17 @@ ngx_http_do_read_non_buffered_client_request_body(ngx_http_request_t *r)
n);

if (n == NGX_AGAIN) {

if (rb->postpone_size
>= (off_t) clcf->client_body_postpone_size)
{

if (rb->buffered) {
rb->flush = 1;
goto read_ok;
}
}

break;
}

Expand Down
24 changes: 20 additions & 4 deletions tests/test-nginx/cases/trim.t
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ style="text-align: center;">hello world, it is good to see you </body> '
--- request
GET /t/trim.html
--- response_body eval
'<!DOCTYPE html>
<html> <body>hello world!<body> <html> '
'
<!DOCTYPE html> <html> <body>hello world!<body> <html> '

=== TEST 6: return zero size
--- config
Expand All @@ -156,8 +156,6 @@ style="text-align: center;">hello world, it is good to see you </body> '
location /trim.html { trim off;}
--- user_files
>>> trim.html


<!DOCTYPE html>
< <PRE>hello world ! </pre>
<2 <pre>hello world ! </pre>
Expand Down Expand Up @@ -391,3 +389,21 @@ html >/**/ body p {
}
/**/
</style> '

=== TEST 17: comment of javascript
--- config
trim on;
trim_jscss on;
location /t/ { proxy_buffering off; proxy_pass http://127.0.0.1:$TEST_NGINX_TRIM_PORT/;}
location /trim.html { trim off;}
--- user_files
>>> trim.html
<!DOCTYPE html>
<script type="text/javascript">// <![CDATA[
return true;
// ]]></script></head><body id="loginform"><div id="page_content">
--- request
GET /t/trim.html
--- response_body eval
'<!DOCTYPE html>
<script type="text/javascript">return true;</script></head><body id="loginform"><div id="page_content"> '

0 comments on commit 6410df2

Please sign in to comment.