comparison src/http/modules/ngx_http_fastcgi_module.c @ 7689:da8d758aabeb

FastCGI: fixed zero size buf alerts on extra data (ticket #2018). After 05e42236e95b (1.19.1) responses with extra data might result in zero size buffers being generated and "zero size buf" alerts in writer (if f->rest happened to be 0 when processing additional stdout data).
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 27 Jul 2020 16:02:15 +0300
parents 05e42236e95b
children b87b7092cedb
comparison
equal deleted inserted replaced
7688:2f9214713666 7689:da8d758aabeb
2304 2304
2305 if (f->pos == f->last) { 2305 if (f->pos == f->last) {
2306 break; 2306 break;
2307 } 2307 }
2308 2308
2309 if (f->rest == -2) {
2310 f->rest = r->upstream->headers_in.content_length_n;
2311 }
2312
2313 if (f->rest == 0) {
2314 ngx_log_error(NGX_LOG_WARN, p->log, 0,
2315 "upstream sent more data than specified in "
2316 "\"Content-Length\" header");
2317 p->upstream_done = 1;
2318 break;
2319 }
2320
2309 cl = ngx_chain_get_free_buf(p->pool, &p->free); 2321 cl = ngx_chain_get_free_buf(p->pool, &p->free);
2310 if (cl == NULL) { 2322 if (cl == NULL) {
2311 return NGX_ERROR; 2323 return NGX_ERROR;
2312 } 2324 }
2313 2325
2347 f->length -= f->last - f->pos; 2359 f->length -= f->last - f->pos;
2348 f->pos = f->last; 2360 f->pos = f->last;
2349 b->last = f->last; 2361 b->last = f->last;
2350 } 2362 }
2351 2363
2352 if (f->rest == -2) { 2364 if (f->rest > 0) {
2353 f->rest = r->upstream->headers_in.content_length_n;
2354 }
2355
2356 if (f->rest >= 0) {
2357 2365
2358 if (b->last - b->pos > f->rest) { 2366 if (b->last - b->pos > f->rest) {
2359 ngx_log_error(NGX_LOG_WARN, p->log, 0, 2367 ngx_log_error(NGX_LOG_WARN, p->log, 0,
2360 "upstream sent more data than specified in " 2368 "upstream sent more data than specified in "
2361 "\"Content-Length\" header"); 2369 "\"Content-Length\" header");
2562 2570
2563 if (f->pos == f->last) { 2571 if (f->pos == f->last) {
2564 break; 2572 break;
2565 } 2573 }
2566 2574
2575 if (f->rest == 0) {
2576 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
2577 "upstream sent more data than specified in "
2578 "\"Content-Length\" header");
2579 u->length = 0;
2580 break;
2581 }
2582
2567 cl = ngx_chain_get_free_buf(r->pool, &u->free_bufs); 2583 cl = ngx_chain_get_free_buf(r->pool, &u->free_bufs);
2568 if (cl == NULL) { 2584 if (cl == NULL) {
2569 return NGX_ERROR; 2585 return NGX_ERROR;
2570 } 2586 }
2571 2587
2592 f->length -= f->last - f->pos; 2608 f->length -= f->last - f->pos;
2593 f->pos = f->last; 2609 f->pos = f->last;
2594 b->last = f->last; 2610 b->last = f->last;
2595 } 2611 }
2596 2612
2597 if (f->rest >= 0) { 2613 if (f->rest > 0) {
2598 2614
2599 if (b->last - b->pos > f->rest) { 2615 if (b->last - b->pos > f->rest) {
2600 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, 2616 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
2601 "upstream sent more data than specified in " 2617 "upstream sent more data than specified in "
2602 "\"Content-Length\" header"); 2618 "\"Content-Length\" header");