Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix:ngx.encode_args() not escaped "|" to "%7c". see: https://en.wi… #542

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions src/ngx_http_lua_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1841,6 +1841,26 @@ ngx_http_lua_escape_uri(u_char *dst, u_char *src, size_t size, ngx_uint_t type)
/* ~}| {zyx wvut srqp onml kjih gfed cba` */
0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */

0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */
};

/* not ALPHA, DIGIT, "-", ".", "_", "~" */

static uint32_t uri_component[] = {
0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */

/* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
0xfc009fff, /* 1111 1100 0000 0000 1001 1111 1111 1111 */

/* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
0x78000001, /* 0111 1000 0000 0000 0000 0000 0000 0001 */

/* ~}| {zyx wvut srqp onml kjih gfed cba` */
0xb8000001, /* 1011 1000 0000 0000 0000 0000 0000 0001 */

0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
Expand Down Expand Up @@ -1909,9 +1929,8 @@ ngx_http_lua_escape_uri(u_char *dst, u_char *src, size_t size, ngx_uint_t type)

/* mail_auth is the same as memcached */

static uint32_t *map[] =
{ uri, args, html, refresh, memcached, memcached };

static uint32_t *map[] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the indentation.

{ uri, args, uri_component, html, refresh, memcached, memcached };

escape = map[type];

Expand Down Expand Up @@ -2317,7 +2336,7 @@ ngx_http_lua_process_args_option(ngx_http_request_t *r, lua_State *L,
key = (u_char *) lua_tolstring(L, -2, &key_len);

key_escape = 2 * ngx_http_lua_escape_uri(NULL, key, key_len,
NGX_ESCAPE_URI);
NGX_ESCAPE_URI_COMPONENT);
total_escape += key_escape;

switch (lua_type(L, -1)) {
Expand All @@ -2326,7 +2345,7 @@ ngx_http_lua_process_args_option(ngx_http_request_t *r, lua_State *L,
value = (u_char *) lua_tolstring(L, -1, &value_len);

total_escape += 2 * ngx_http_lua_escape_uri(NULL, value, value_len,
NGX_ESCAPE_URI);
NGX_ESCAPE_URI_COMPONENT);

len += key_len + value_len + (sizeof("=") - 1);
n++;
Expand Down Expand Up @@ -2367,7 +2386,7 @@ ngx_http_lua_process_args_option(ngx_http_request_t *r, lua_State *L,
total_escape +=
2 * ngx_http_lua_escape_uri(NULL, value,
value_len,
NGX_ESCAPE_URI);
NGX_ESCAPE_URI_COMPONENT);

len += key_len + value_len + (sizeof("=") - 1);
}
Expand Down Expand Up @@ -2424,7 +2443,7 @@ ngx_http_lua_process_args_option(ngx_http_request_t *r, lua_State *L,

if (total_escape) {
p = (u_char *) ngx_http_lua_escape_uri(p, key, key_len,
NGX_ESCAPE_URI);
NGX_ESCAPE_URI_COMPONENT);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line exceeds 80 columns (so do the following changes from you). Please fix them. Thanks.


} else {
dd("shortcut: no escape required");
Expand All @@ -2438,7 +2457,7 @@ ngx_http_lua_process_args_option(ngx_http_request_t *r, lua_State *L,

if (total_escape) {
p = (u_char *) ngx_http_lua_escape_uri(p, value, value_len,
NGX_ESCAPE_URI);
NGX_ESCAPE_URI_COMPONENT);

} else {
p = ngx_copy(p, value, value_len);
Expand All @@ -2457,7 +2476,7 @@ ngx_http_lua_process_args_option(ngx_http_request_t *r, lua_State *L,
if (lua_toboolean(L, -1)) {
if (total_escape) {
p = (u_char *) ngx_http_lua_escape_uri(p, key, key_len,
NGX_ESCAPE_URI);
NGX_ESCAPE_URI_COMPONENT);

} else {
dd("shortcut: no escape required");
Expand Down Expand Up @@ -2485,7 +2504,7 @@ ngx_http_lua_process_args_option(ngx_http_request_t *r, lua_State *L,
if (total_escape) {
p = (u_char *) ngx_http_lua_escape_uri(p, key,
key_len,
NGX_ESCAPE_URI);
NGX_ESCAPE_URI_COMPONENT);

} else {
dd("shortcut: no escape required");
Expand All @@ -2504,7 +2523,7 @@ ngx_http_lua_process_args_option(ngx_http_request_t *r, lua_State *L,
p = (u_char *)
ngx_http_lua_escape_uri(p, key,
key_len,
NGX_ESCAPE_URI);
NGX_ESCAPE_URI_COMPONENT);

} else {
dd("shortcut: no escape required");
Expand All @@ -2520,7 +2539,7 @@ ngx_http_lua_process_args_option(ngx_http_request_t *r, lua_State *L,
p = (u_char *)
ngx_http_lua_escape_uri(p, value,
value_len,
NGX_ESCAPE_URI);
NGX_ESCAPE_URI_COMPONENT);

} else {
p = ngx_copy(p, value, value_len);
Expand Down