Klaus Demo nginx / 63c78f3
test conf file size, this fixes OpenBSD's "nginx -c /tmp/" bug Igor Sysoev 13 years ago
1 changed file(s) with 26 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
66 #include <ngx_config.h>
77 #include <ngx_core.h>
88
9 #define NGX_CONF_BUFFER 4096
910
1011 static ngx_int_t ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last);
1112 static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf);
4243 };
4344
4445
45 /* The ten fixed arguments */
46 /* The eight fixed arguments */
4647
4748 static ngx_uint_t argument_number[] = {
4849 NGX_CONF_NOARGS,
140141
141142 cf->conf_file->buffer = b;
142143
143 b->start = ngx_alloc(ngx_pagesize, cf->log);
144 b->start = ngx_alloc(NGX_CONF_BUFFER, cf->log);
144145 if (b->start == NULL) {
145146 return NGX_CONF_ERROR;
146147 }
147148
148149 b->pos = b->start;
149150 b->last = b->start;
150 b->end = b->last + ngx_pagesize;
151 b->end = b->last + NGX_CONF_BUFFER;
151152 b->temporary = 1;
152153
153154 cf->conf_file->file.fd = fd;
432433 ngx_conf_read_token(ngx_conf_t *cf)
433434 {
434435 u_char *start, ch, *src, *dst;
436 off_t file_size;
435437 size_t len;
436 ssize_t n;
438 ssize_t n, size;
437439 ngx_uint_t found, need_space, last_space, sharp_comment, variable;
438440 ngx_uint_t quoted, s_quoted, d_quoted, start_line;
439441 ngx_str_t *word;
451453 start = b->pos;
452454 start_line = cf->conf_file->line;
453455
456 file_size = ngx_file_size(&cf->conf_file->file.info);
457
454458 for ( ;; ) {
455459
456460 if (b->pos >= b->last) {
457461
458 if (cf->conf_file->file.offset
459 >= ngx_file_size(&cf->conf_file->file.info))
460 {
462 if (cf->conf_file->file.offset >= file_size) {
463
461464 if (cf->args->nelts > 0) {
462465
463466 if (cf->conf_file->file.fd == NGX_INVALID_FILE) {
478481
479482 len = b->pos - start;
480483
481 if (len == ngx_pagesize) {
484 if (len == NGX_CONF_BUFFER) {
482485 cf->conf_file->line = start_line;
483486
484487 if (d_quoted) {
504507 ngx_memcpy(b->start, start, len);
505508 }
506509
507 n = ngx_read_file(&cf->conf_file->file, b->start + len,
508 b->end - (b->start + len),
510 size = file_size - cf->conf_file->file.offset;
511
512 if (size > b->end - (b->start + len)) {
513 size = b->end - (b->start + len);
514 }
515
516 n = ngx_read_file(&cf->conf_file->file, b->start + len, size,
509517 cf->conf_file->file.offset);
510518
511519 if (n == NGX_ERROR) {
520 return NGX_ERROR;
521 }
522
523 if (n != size) {
524 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
525 ngx_read_file_n " returned "
526 "only %z bytes instead of %z",
527 n, size);
512528 return NGX_ERROR;
513529 }
514530