annotate src/core/ngx_times.h @ 6874:7cc2d3a96ea3

Fixed trailer construction with limit on FreeBSD and macOS. The ngx_chain_coalesce_file() function may produce more bytes to send then requested in the limit passed, as it aligns the last file position to send to memory page boundary. As a result, (limit - send) may become negative. This resulted in big positive number when converted to size_t while calling ngx_output_chain_to_iovec(). Another part of the problem is in ngx_chain_coalesce_file(): it changes cl to the next chain link even if the current buffer is only partially sent due to limit. Therefore, if a file buffer was not expected to be fully sent due to limit, and was followed by a memory buffer, nginx called sendfile() with a part of the file buffer, and the memory buffer in trailer. If there were enough room in the socket buffer, this resulted in a part of the file buffer being skipped, and corresponding part of the memory buffer sent instead. The bug was introduced in 8e903522c17a (1.7.8). Configurations affected are ones using limits, that is, limit_rate and/or sendfile_max_chunk, and memory buffers after file ones (may happen when using subrequests or with proxying with disk buffering). Fix is to explicitly check if (send < limit) before constructing trailer with ngx_output_chain_to_iovec(). Additionally, ngx_chain_coalesce_file() was modified to preserve unfinished file buffers in cl.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 20 Jan 2017 21:12:48 +0300
parents 777202558122
children 76e7e20cda05
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
441
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 409
diff changeset
1
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 409
diff changeset
2 /*
444
42d11f017717 nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents: 441
diff changeset
3 * Copyright (C) Igor Sysoev
4412
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 3873
diff changeset
4 * Copyright (C) Nginx, Inc.
441
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 409
diff changeset
5 */
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 409
diff changeset
6
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 409
diff changeset
7
178
a8ff48d26cca nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #ifndef _NGX_TIMES_H_INCLUDED_
a8ff48d26cca nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #define _NGX_TIMES_H_INCLUDED_
a8ff48d26cca nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
a8ff48d26cca nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
a8ff48d26cca nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12 #include <ngx_config.h>
a8ff48d26cca nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
13 #include <ngx_core.h>
a8ff48d26cca nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14
a8ff48d26cca nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
15
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 557
diff changeset
16 typedef struct {
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 557
diff changeset
17 time_t sec;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 557
diff changeset
18 ngx_uint_t msec;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 557
diff changeset
19 ngx_int_t gmtoff;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 557
diff changeset
20 } ngx_time_t;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 557
diff changeset
21
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 557
diff changeset
22
499
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 477
diff changeset
23 void ngx_time_init(void);
3475
ab353d7dc182 *) introduce ngx_time_sigsafe_update() to update the error log time only
Igor Sysoev <igor@sysoev.ru>
parents: 3474
diff changeset
24 void ngx_time_update(void);
ab353d7dc182 *) introduce ngx_time_sigsafe_update() to update the error log time only
Igor Sysoev <igor@sysoev.ru>
parents: 3474
diff changeset
25 void ngx_time_sigsafe_update(void);
455
295d97d70c69 nginx-0.1.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
26 u_char *ngx_http_time(u_char *buf, time_t t);
295d97d70c69 nginx-0.1.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
27 u_char *ngx_http_cookie_time(u_char *buf, time_t t);
182
3c49eaf3f522 nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents: 178
diff changeset
28 void ngx_gmtime(time_t t, ngx_tm_t *tp);
178
a8ff48d26cca nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29
2162
429269167fab ngx_next_time()
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
30 time_t ngx_next_time(time_t when);
429269167fab ngx_next_time()
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
31 #define ngx_next_time_n "mktime()"
429269167fab ngx_next_time()
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
32
370
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents: 323
diff changeset
33
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 557
diff changeset
34 extern volatile ngx_time_t *ngx_cached_time;
370
54f76b0b8dca nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents: 323
diff changeset
35
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 557
diff changeset
36 #define ngx_time() ngx_cached_time->sec
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 557
diff changeset
37 #define ngx_timeofday() (ngx_time_t *) ngx_cached_time
178
a8ff48d26cca nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 557
diff changeset
39 extern volatile ngx_str_t ngx_cached_err_log_time;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 557
diff changeset
40 extern volatile ngx_str_t ngx_cached_http_time;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 557
diff changeset
41 extern volatile ngx_str_t ngx_cached_http_log_time;
3873
eae4a59ae59a $time_iso8601 log variable
Igor Sysoev <igor@sysoev.ru>
parents: 3475
diff changeset
42 extern volatile ngx_str_t ngx_cached_http_log_iso8601;
5702
777202558122 Added syslog support for error_log and access_log directives.
Vladimir Homutov <vl@nginx.com>
parents: 4412
diff changeset
43 extern volatile ngx_str_t ngx_cached_syslog_time;
245
e6c005b66b3a nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
44
e6c005b66b3a nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
45 /*
557
ecd9c160f25b nginx-0.3.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
46 * milliseconds elapsed since epoch and truncated to ngx_msec_t,
ecd9c160f25b nginx-0.3.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
47 * used in event timers
245
e6c005b66b3a nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
48 */
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 557
diff changeset
49 extern volatile ngx_msec_t ngx_current_msec;
245
e6c005b66b3a nginx-0.0.1-2004-01-30-00:45:01 import
Igor Sysoev <igor@sysoev.ru>
parents: 218
diff changeset
50
178
a8ff48d26cca nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
51
a8ff48d26cca nginx-0.0.1-2003-11-11-00:09:22 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
52 #endif /* _NGX_TIMES_H_INCLUDED_ */