Skip to content

Commit f6ff289

Browse files
committed
misc: avoided warnings with old gcc versions due to incorrect inline definition and renamed functions for clarity.
1 parent 3908769 commit f6ff289

11 files changed

+79
-81
lines changed

src/ngx_http_lua_control.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ ngx_http_lua_ngx_redirect(lua_State *L)
239239
"the headers");
240240
}
241241

242-
if (ngx_http_lua_check_header_safe(r, p, len) != NGX_OK) {
242+
if (ngx_http_lua_check_unsafe_header(r, p, len) != NGX_OK) {
243243
return luaL_error(L, "attempt to use unsafe uri");
244244
}
245245

src/ngx_http_lua_headers_in.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,8 @@ ngx_http_lua_set_input_header(ngx_http_request_t *r, ngx_str_t key,
658658

659659
dd("set header value: %.*s", (int) value.len, value.data);
660660

661-
if (ngx_http_lua_check_header_safe(r, key.data, key.len) != NGX_OK
662-
|| ngx_http_lua_check_header_safe(r, value.data, value.len) != NGX_OK)
661+
if (ngx_http_lua_check_unsafe_header(r, key.data, key.len) != NGX_OK
662+
|| ngx_http_lua_check_unsafe_header(r, value.data, value.len) != NGX_OK)
663663
{
664664
return NGX_ERROR;
665665
}

src/ngx_http_lua_headers_out.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ ngx_http_lua_set_output_header(ngx_http_request_t *r, ngx_http_lua_ctx_t *ctx,
491491

492492
dd("set header value: %.*s", (int) value.len, value.data);
493493

494-
if (ngx_http_lua_check_header_safe(r, key.data, key.len) != NGX_OK
495-
|| ngx_http_lua_check_header_safe(r, value.data, value.len) != NGX_OK)
494+
if (ngx_http_lua_check_unsafe_header(r, key.data, key.len) != NGX_OK
495+
|| ngx_http_lua_check_unsafe_header(r, value.data, value.len) != NGX_OK)
496496
{
497497
return NGX_ERROR;
498498
}

src/ngx_http_lua_uri.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
static int ngx_http_lua_ngx_req_set_uri(lua_State *L);
19-
static ngx_int_t ngx_http_lua_check_uri_safe(ngx_http_request_t *r,
19+
static ngx_inline ngx_int_t ngx_http_lua_check_unsafe_uri(ngx_http_request_t *r,
2020
u_char *str, size_t len);
2121

2222

@@ -57,7 +57,7 @@ ngx_http_lua_ngx_req_set_uri(lua_State *L)
5757
return luaL_error(L, "attempt to use zero-length uri");
5858
}
5959

60-
if (ngx_http_lua_check_uri_safe(r, p, len) != NGX_OK) {
60+
if (ngx_http_lua_check_unsafe_uri(r, p, len) != NGX_OK) {
6161
return luaL_error(L, "attempt to use unsafe uri");
6262
}
6363

@@ -115,7 +115,7 @@ ngx_http_lua_ngx_req_set_uri(lua_State *L)
115115

116116

117117
static ngx_inline ngx_int_t
118-
ngx_http_lua_check_uri_safe(ngx_http_request_t *r, u_char *str, size_t len)
118+
ngx_http_lua_check_unsafe_uri(ngx_http_request_t *r, u_char *str, size_t len)
119119
{
120120
size_t i, buf_len;
121121
u_char c;

src/ngx_http_lua_util.c

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4328,56 +4328,4 @@ ngx_http_lua_escape_log(u_char *dst, u_char *src, size_t size)
43284328
}
43294329

43304330

4331-
ngx_inline ngx_int_t
4332-
ngx_http_lua_check_header_safe(ngx_http_request_t *r, u_char *str, size_t len)
4333-
{
4334-
size_t i, buf_len;
4335-
u_char c;
4336-
u_char *buf, *src = str;
4337-
4338-
/* %00-%1F, %7F */
4339-
4340-
static uint32_t unsafe[] = {
4341-
0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
4342-
4343-
/* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
4344-
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
4345-
4346-
/* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
4347-
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
4348-
4349-
/* ~}| {zyx wvut srqp onml kjih gfed cba` */
4350-
0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
4351-
4352-
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
4353-
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
4354-
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
4355-
0x00000000 /* 0000 0000 0000 0000 0000 0000 0000 0000 */
4356-
};
4357-
4358-
for (i = 0; i < len; i++, str++) {
4359-
c = *str;
4360-
if (unsafe[c >> 5] & (1 << (c & 0x1f))) {
4361-
buf_len = ngx_http_lua_escape_log(NULL, src, len);
4362-
buf = ngx_palloc(r->pool, buf_len);
4363-
if (buf == NULL) {
4364-
return NGX_ERROR;
4365-
}
4366-
4367-
ngx_http_lua_escape_log(buf, src, len);
4368-
4369-
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
4370-
"unsafe byte \"0x%uxd\" in header \"%*s\"",
4371-
(unsigned) c, buf_len, buf);
4372-
4373-
ngx_pfree(r->pool, buf);
4374-
4375-
return NGX_ERROR;
4376-
}
4377-
}
4378-
4379-
return NGX_OK;
4380-
}
4381-
4382-
43834331
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */

src/ngx_http_lua_util.h

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ void ngx_http_lua_set_sa_restart(ngx_log_t *log);
242242
#endif
243243

244244
size_t ngx_http_lua_escape_log(u_char *dst, u_char *src, size_t size);
245-
ngx_int_t ngx_http_lua_check_header_safe(ngx_http_request_t *r, u_char *str,
246-
size_t len);
247245

248246

249247
static ngx_inline void
@@ -491,6 +489,58 @@ ngx_inet_get_port(struct sockaddr *sa)
491489
#endif
492490

493491

492+
static ngx_inline ngx_int_t
493+
ngx_http_lua_check_unsafe_header(ngx_http_request_t *r, u_char *str, size_t len)
494+
{
495+
size_t i, buf_len;
496+
u_char c;
497+
u_char *buf, *src = str;
498+
499+
/* %00-%1F, %7F */
500+
501+
static uint32_t unsafe[] = {
502+
0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
503+
504+
/* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
505+
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
506+
507+
/* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
508+
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
509+
510+
/* ~}| {zyx wvut srqp onml kjih gfed cba` */
511+
0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
512+
513+
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
514+
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
515+
0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
516+
0x00000000 /* 0000 0000 0000 0000 0000 0000 0000 0000 */
517+
};
518+
519+
for (i = 0; i < len; i++, str++) {
520+
c = *str;
521+
if (unsafe[c >> 5] & (1 << (c & 0x1f))) {
522+
buf_len = ngx_http_lua_escape_log(NULL, src, len);
523+
buf = ngx_palloc(r->pool, buf_len);
524+
if (buf == NULL) {
525+
return NGX_ERROR;
526+
}
527+
528+
ngx_http_lua_escape_log(buf, src, len);
529+
530+
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
531+
"unsafe byte \"0x%uxd\" in header \"%*s\"",
532+
(unsigned) c, buf_len, buf);
533+
534+
ngx_pfree(r->pool, buf);
535+
536+
return NGX_ERROR;
537+
}
538+
}
539+
540+
return NGX_OK;
541+
}
542+
543+
494544
extern ngx_uint_t ngx_http_lua_location_hash;
495545
extern ngx_uint_t ngx_http_lua_content_length_hash;
496546

t/016-resp-header.t

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,7 +1966,7 @@ Content-Type: application/json
19661966
19671967
19681968
1969-
=== TEST 87: value contains '\r'
1969+
=== TEST 87: unsafe header value (with '\r')
19701970
--- config
19711971
location = /t {
19721972
content_by_lua_block {
@@ -1987,7 +1987,7 @@ failed to set header
19871987
19881988
19891989
1990-
=== TEST 88: value contains '\n'
1990+
=== TEST 88: unsafe header value (with '\n')
19911991
--- config
19921992
location = /t {
19931993
content_by_lua_block {
@@ -2008,7 +2008,7 @@ failed to set header
20082008
20092009
20102010
2011-
=== TEST 89: header name contains '\r'
2011+
=== TEST 89: unsafe header name (with '\r')
20122012
--- config
20132013
location = /t {
20142014
content_by_lua_block {
@@ -2029,7 +2029,7 @@ failed to set header
20292029
20302030
20312031
2032-
=== TEST 90: truncates key after '\n'
2032+
=== TEST 90: unsafe header name (with '\n')
20332033
--- config
20342034
location = /t {
20352035
content_by_lua_block {
@@ -2050,7 +2050,7 @@ failed to set header
20502050
20512051
20522052
2053-
=== TEST 91: header name: '\r' as the first character
2053+
=== TEST 91: unsafe header name (with prefix '\r')
20542054
--- config
20552055
location = /t {
20562056
content_by_lua_block {
@@ -2071,7 +2071,7 @@ failed to set header
20712071
20722072
20732073
2074-
=== TEST 92: header name: '\n' as the first character
2074+
=== TEST 92: unsafe header name (with prefix '\n')
20752075
--- config
20762076
location = /t {
20772077
content_by_lua_block {
@@ -2092,7 +2092,7 @@ failed to set header
20922092
20932093
20942094
2095-
=== TEST 93: truncates multiple values if they contain '\r' or '\n'
2095+
=== TEST 93: multiple unsafe header values (with '\n' and '\r')
20962096
--- config
20972097
location = /t {
20982098
content_by_lua_block {

t/022-redirect.t

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ Location: http://agentzh.org/foo?a=b&c=d
323323

324324

325325

326-
=== TEST 18: uri contains '\r'
326+
=== TEST 18: unsafe uri (with '\r')
327327
--- config
328328
location = /t {
329329
content_by_lua_block {
@@ -344,7 +344,7 @@ attempt to use unsafe uri
344344

345345

346346

347-
=== TEST 19: uri contains '\n'
347+
=== TEST 19: unsafe uri (with '\n')
348348
--- config
349349
location = /t {
350350
content_by_lua_block {
@@ -365,7 +365,7 @@ attempt to use unsafe uri
365365

366366

367367

368-
=== TEST 20: uri prefix '\n'
368+
=== TEST 20: unsafe uri (with prefix '\n')
369369
--- config
370370
location = /t {
371371
content_by_lua_block {
@@ -385,7 +385,7 @@ attempt to use unsafe uri
385385

386386

387387

388-
=== TEST 21: uri prefix '\r'
388+
=== TEST 21: unsafe uri (with prefix '\r')
389389
--- config
390390
location = /t {
391391
content_by_lua_block {
@@ -405,7 +405,7 @@ attempt to use unsafe uri
405405

406406

407407

408-
=== TEST 22: uri with invalid characters escapes '"' and '\' characters
408+
=== TEST 22: unsafe uri logging escapes '"' and '\' characters
409409
--- config
410410
location = /t {
411411
content_by_lua_block {

t/028-req-header.t

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,7 +2033,7 @@ new
20332033
20342034
20352035
2036-
=== TEST 62: set input header with unsafe key
2036+
=== TEST 62: unsafe header name (with '\r')
20372037
--- config
20382038
location /req-header {
20392039
rewrite_by_lua_block {
@@ -2051,7 +2051,7 @@ failed to set header
20512051
20522052
20532053
2054-
=== TEST 63: set input header with unsafe value
2054+
=== TEST 63: unsafe header value (with '\n')
20552055
--- config
20562056
location /req-header {
20572057
rewrite_by_lua_block {
@@ -2069,7 +2069,7 @@ failed to set header
20692069
20702070
20712071
2072-
=== TEST 64: set input header with multiple unsafe values
2072+
=== TEST 64: multiple unsafe header values (with '\n' and '\t')
20732073
--- config
20742074
location /req-header {
20752075
rewrite_by_lua_block {
@@ -2089,7 +2089,7 @@ failed to set header
20892089
20902090
20912091
2092-
=== TEST 65: unsafe value errors escape '"' and '\' characters
2092+
=== TEST 65: unsafe names/values logging escapes '"' and '\' characters
20932093
--- config
20942094
location /req-header {
20952095
rewrite_by_lua_block {

t/030-uri-args.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ args: foo=%2C%24%40%7C%60&bar=-_.!~*'()
15571557
15581558
15591559
1560-
=== TEST 58: set_uri with unsafe uri (with \t)
1560+
=== TEST 58: set_uri with unsafe uri (with '\t')
15611561
--- config
15621562
location /t {
15631563
content_by_lua_block {
@@ -1575,7 +1575,7 @@ attempt to use unsafe uri
15751575

15761576

15771577

1578-
=== TEST 59: set_uri with unsafe uri (with " ")
1578+
=== TEST 59: set_uri with unsafe uri (with ' ')
15791579
--- config
15801580
location /t {
15811581
content_by_lua_block {

t/113-req-header-cookie.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ Cookie: boo=123; foo=bar
250250
251251
252252
253-
=== TEST 7: set multiple custom cookies (with unsafe values)
253+
=== TEST 7: set multiple custom cookies with unsafe values (with '\n' and 'r')
254254
--- config
255255
location /t {
256256
rewrite_by_lua_block {

0 commit comments

Comments
 (0)