|
16 | 16 |
|
17 | 17 |
|
18 | 18 | static int ngx_http_lua_ngx_req_set_uri(lua_State *L); |
19 | | -static ngx_inline ngx_int_t ngx_http_lua_check_unsafe_uri(ngx_http_request_t *r, |
20 | | - u_char *str, size_t len); |
21 | 19 |
|
22 | 20 |
|
23 | 21 | void |
@@ -57,8 +55,8 @@ ngx_http_lua_ngx_req_set_uri(lua_State *L) |
57 | 55 | return luaL_error(L, "attempt to use zero-length uri"); |
58 | 56 | } |
59 | 57 |
|
60 | | - if (ngx_http_lua_check_unsafe_uri(r, p, len) != NGX_OK) { |
61 | | - return luaL_error(L, "attempt to use unsafe uri"); |
| 58 | + if (ngx_http_lua_check_unsafe_string(r, p, len, "uri") != NGX_OK) { |
| 59 | + return luaL_error(L, "attempt to set unsafe uri"); |
62 | 60 | } |
63 | 61 |
|
64 | 62 | if (n == 2) { |
@@ -114,56 +112,4 @@ ngx_http_lua_ngx_req_set_uri(lua_State *L) |
114 | 112 | } |
115 | 113 |
|
116 | 114 |
|
117 | | -static ngx_inline ngx_int_t |
118 | | -ngx_http_lua_check_unsafe_uri(ngx_http_request_t *r, u_char *str, size_t len) |
119 | | -{ |
120 | | - size_t i, buf_len; |
121 | | - u_char c; |
122 | | - u_char *buf, *src = str; |
123 | | - |
124 | | - /* %00-%1F, " ", %7F */ |
125 | | - |
126 | | - static uint32_t unsafe[] = { |
127 | | - 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ |
128 | | - |
129 | | - /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ |
130 | | - 0x00000001, /* 0000 0000 0000 0000 0000 0000 0000 0001 */ |
131 | | - |
132 | | - /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ |
133 | | - 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ |
134 | | - |
135 | | - /* ~}| {zyx wvut srqp onml kjih gfed cba` */ |
136 | | - 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */ |
137 | | - |
138 | | - 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ |
139 | | - 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ |
140 | | - 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ |
141 | | - 0x00000000 /* 0000 0000 0000 0000 0000 0000 0000 0000 */ |
142 | | - }; |
143 | | - |
144 | | - for (i = 0; i < len; i++, str++) { |
145 | | - c = *str; |
146 | | - if (unsafe[c >> 5] & (1 << (c & 0x1f))) { |
147 | | - buf_len = ngx_http_lua_escape_log(NULL, src, len); |
148 | | - buf = ngx_palloc(r->pool, buf_len); |
149 | | - if (buf == NULL) { |
150 | | - return NGX_ERROR; |
151 | | - } |
152 | | - |
153 | | - ngx_http_lua_escape_log(buf, src, len); |
154 | | - |
155 | | - ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
156 | | - "unsafe byte \"0x%uxd\" in uri \"%*s\"", |
157 | | - (unsigned) c, buf_len, buf); |
158 | | - |
159 | | - ngx_pfree(r->pool, buf); |
160 | | - |
161 | | - return NGX_ERROR; |
162 | | - } |
163 | | - } |
164 | | - |
165 | | - return NGX_OK; |
166 | | -} |
167 | | - |
168 | | - |
169 | 115 | /* vi:set ft=c ts=4 sw=4 et fdm=marker: */ |
0 commit comments