Skip to content

Commit 78b0d54

Browse files
committed
bugfix: we might (incorrectly) return 500 in our output filters. bugfix: we should return NGX_ERROR in case of memory allocation errors.
1 parent 20feb73 commit 78b0d54

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

src/ngx_http_srcache_fetch.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ ngx_http_srcache_access_handler(ngx_http_request_t *r)
7373
sizeof(ngx_http_srcache_filter_module));
7474

7575
if (ctx == NULL) {
76-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
76+
return NGX_ERROR;
7777
}
7878

7979
ngx_http_set_ctx(r, ctx, ngx_http_srcache_filter_module);
@@ -101,7 +101,7 @@ ngx_http_srcache_access_handler(ngx_http_request_t *r)
101101
ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_srcache_filter_module));
102102

103103
if (ctx == NULL) {
104-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
104+
return NGX_ERROR;
105105
}
106106

107107
ngx_http_set_ctx(r, ctx, ngx_http_srcache_filter_module);
@@ -202,7 +202,7 @@ ngx_http_srcache_access_handler(ngx_http_request_t *r)
202202
ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_srcache_filter_module));
203203

204204
if (ctx == NULL) {
205-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
205+
return NGX_ERROR;
206206
}
207207

208208
ngx_http_set_ctx(r, ctx, ngx_http_srcache_filter_module);
@@ -362,7 +362,7 @@ ngx_http_srcache_fetch_subrequest(ngx_http_request_t *r,
362362

363363
parsed_sr = ngx_palloc(r->pool, sizeof(ngx_http_srcache_parsed_request_t));
364364
if (parsed_sr == NULL) {
365-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
365+
return NGX_ERROR;
366366
}
367367

368368
parsed_sr->method = conf->fetch->method;
@@ -374,25 +374,26 @@ ngx_http_srcache_fetch_subrequest(ngx_http_request_t *r,
374374
if (ngx_http_complex_value(r, &conf->fetch->location,
375375
&parsed_sr->location) != NGX_OK)
376376
{
377-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
377+
return NGX_ERROR;
378378
}
379379

380380
if (parsed_sr->location.len == 0) {
381-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
381+
return NGX_ERROR;
382382
}
383383

384384
if (ngx_http_complex_value(r, &conf->fetch->args, &parsed_sr->args)
385385
!= NGX_OK)
386386
{
387-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
387+
return NGX_ERROR;
388388
}
389389

390390
args.data = NULL;
391391
args.len = 0;
392392

393393
if (ngx_http_parse_unsafe_uri(r, &parsed_sr->location, &args, &flags)
394-
!= NGX_OK) {
395-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
394+
!= NGX_OK)
395+
{
396+
return NGX_ERROR;
396397
}
397398

398399
if (args.len > 0 && parsed_sr->args.len == 0) {
@@ -401,14 +402,14 @@ ngx_http_srcache_fetch_subrequest(ngx_http_request_t *r,
401402

402403
sr_ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_srcache_ctx_t));
403404
if (sr_ctx == NULL) {
404-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
405+
return NGX_ERROR;
405406
}
406407

407408
sr_ctx->in_fetch_subrequest = 1;
408409

409410
psr = ngx_palloc(r->pool, sizeof(ngx_http_post_subrequest_t));
410411
if (psr == NULL) {
411-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
412+
return NGX_ERROR;
412413
}
413414

414415
psr->handler = ngx_http_srcache_fetch_post_subrequest;

src/ngx_http_srcache_store.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ ngx_http_srcache_header_filter(ngx_http_request_t *r)
233233
"ngx_srcache not working in subrequests (yet)");
234234

235235
/* not allowd in subrquests */
236-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
236+
return NGX_ERROR;
237237
}
238238

239239
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
@@ -494,7 +494,7 @@ ngx_http_srcache_store_subrequest(ngx_http_request_t *r,
494494

495495
parsed_sr = ngx_palloc(r->pool, sizeof(ngx_http_srcache_parsed_request_t));
496496
if (parsed_sr == NULL) {
497-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
497+
return NGX_ERROR;
498498
}
499499

500500
parsed_sr->method = conf->store->method;
@@ -526,17 +526,17 @@ ngx_http_srcache_store_subrequest(ngx_http_request_t *r,
526526
if (ngx_http_complex_value(r, &conf->store->location,
527527
&parsed_sr->location) != NGX_OK)
528528
{
529-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
529+
return NGX_ERROR;
530530
}
531531

532532
if (parsed_sr->location.len == 0) {
533-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
533+
return NGX_ERROR;
534534
}
535535

536536
if (ngx_http_complex_value(r, &conf->store->args, &parsed_sr->args)
537537
!= NGX_OK)
538538
{
539-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
539+
return NGX_ERROR;
540540
}
541541

542542
args.data = NULL;
@@ -545,7 +545,7 @@ ngx_http_srcache_store_subrequest(ngx_http_request_t *r,
545545
if (ngx_http_parse_unsafe_uri(r, &parsed_sr->location, &args, &flags)
546546
!= NGX_OK)
547547
{
548-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
548+
return NGX_ERROR;
549549
}
550550

551551
if (args.len > 0 && parsed_sr->args.len == 0) {
@@ -563,14 +563,14 @@ ngx_http_srcache_store_subrequest(ngx_http_request_t *r,
563563
sr_ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_srcache_ctx_t));
564564

565565
if (sr_ctx == NULL) {
566-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
566+
return NGX_ERROR;
567567
}
568568

569569
sr_ctx->in_store_subrequest = 1;
570570

571571
psr = ngx_palloc(r->pool, sizeof(ngx_http_post_subrequest_t));
572572
if (psr == NULL) {
573-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
573+
return NGX_ERROR;
574574
}
575575

576576
psr->handler = ngx_http_srcache_store_post_subrequest;

src/ngx_http_srcache_util.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ ngx_http_srcache_adjust_subrequest(ngx_http_request_t *sr,
280280
* sizeof(ngx_http_variable_value_t));
281281

282282
if (sr->variables == NULL) {
283-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
283+
return NGX_ERROR;
284284
}
285285

286286
body = parsed_sr->request_body;
@@ -291,7 +291,7 @@ ngx_http_srcache_adjust_subrequest(ngx_http_request_t *sr,
291291
parsed_sr->content_length_n);
292292

293293
if (rc != NGX_OK) {
294-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
294+
return NGX_ERROR;
295295
}
296296
}
297297

0 commit comments

Comments
 (0)