Skip to content

Commit 294ebea

Browse files
authored
Merge pull request chobits#89 from chobits/for_pull_request
fixed bug that non CONNECT request triggers segfault without location
2 parents f98a424 + 5a4e210 commit 294ebea

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

ngx_http_proxy_connect_module.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,10 @@ ngx_http_proxy_connect_handler(ngx_http_request_t *r)
13641364

13651365
plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_connect_module);
13661366

1367+
if (r->method != NGX_HTTP_CONNECT || !plcf->accept_connect) {
1368+
return NGX_DECLINED;
1369+
}
1370+
13671371
allow = 0;
13681372

13691373
if (plcf->allow_port_all) {
@@ -2077,10 +2081,10 @@ ngx_http_proxy_connect_post_read_handler(ngx_http_request_t *r)
20772081
ngx_http_proxy_connect_ctx_t *ctx;
20782082
ngx_http_proxy_connect_loc_conf_t *pclcf;
20792083

2080-
pclcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_connect_module);
2081-
20822084
if (r->method == NGX_HTTP_CONNECT) {
20832085

2086+
pclcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_connect_module);
2087+
20842088
if (!pclcf->accept_connect) {
20852089
ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
20862090
"client sent connect method");

t/http_proxy_connect.t

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,41 @@ if ($test_enable_rewrite_phase) {
236236
}
237237
$t->stop();
238238

239+
###############################################################################
240+
241+
$t->write_file_expand('nginx.conf', <<'EOF');
242+
243+
%%TEST_GLOBALS%%
244+
245+
daemon off;
246+
247+
events {
248+
}
249+
250+
http {
251+
%%TEST_GLOBALS_HTTP%%
252+
253+
access_log off;
254+
255+
server {
256+
listen 127.0.0.1:8080;
257+
proxy_connect;
258+
proxy_connect_allow all;
259+
}
260+
}
261+
262+
EOF
263+
264+
265+
$t->run();
266+
267+
$t->write_file('test.html', 'test page');
268+
269+
like(http_get('/test.html'), qr/test page/, '200 for default root directive without location {}');
270+
like(http_get('/404'), qr/ 404 Not Found/, '404 for default root directive without location {}');
271+
272+
$t->stop();
273+
239274

240275
# --- stop DNS server ---
241276

0 commit comments

Comments
 (0)