test conf file size, this fixes OpenBSD's "nginx -c /tmp/" bug
Igor Sysoev
13 years ago
6 | 6 | #include <ngx_config.h> |
7 | 7 | #include <ngx_core.h> |
8 | 8 | |
9 | #define NGX_CONF_BUFFER 4096 | |
9 | 10 | |
10 | 11 | static ngx_int_t ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last); |
11 | 12 | static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf); |
42 | 43 | }; |
43 | 44 | |
44 | 45 | |
45 | /* The ten fixed arguments */ | |
46 | /* The eight fixed arguments */ | |
46 | 47 | |
47 | 48 | static ngx_uint_t argument_number[] = { |
48 | 49 | NGX_CONF_NOARGS, |
140 | 141 | |
141 | 142 | cf->conf_file->buffer = b; |
142 | 143 | |
143 | b->start = ngx_alloc(ngx_pagesize, cf->log); | |
144 | b->start = ngx_alloc(NGX_CONF_BUFFER, cf->log); | |
144 | 145 | if (b->start == NULL) { |
145 | 146 | return NGX_CONF_ERROR; |
146 | 147 | } |
147 | 148 | |
148 | 149 | b->pos = b->start; |
149 | 150 | b->last = b->start; |
150 | b->end = b->last + ngx_pagesize; | |
151 | b->end = b->last + NGX_CONF_BUFFER; | |
151 | 152 | b->temporary = 1; |
152 | 153 | |
153 | 154 | cf->conf_file->file.fd = fd; |
432 | 433 | ngx_conf_read_token(ngx_conf_t *cf) |
433 | 434 | { |
434 | 435 | u_char *start, ch, *src, *dst; |
436 | off_t file_size; | |
435 | 437 | size_t len; |
436 | ssize_t n; | |
438 | ssize_t n, size; | |
437 | 439 | ngx_uint_t found, need_space, last_space, sharp_comment, variable; |
438 | 440 | ngx_uint_t quoted, s_quoted, d_quoted, start_line; |
439 | 441 | ngx_str_t *word; |
451 | 453 | start = b->pos; |
452 | 454 | start_line = cf->conf_file->line; |
453 | 455 | |
456 | file_size = ngx_file_size(&cf->conf_file->file.info); | |
457 | ||
454 | 458 | for ( ;; ) { |
455 | 459 | |
456 | 460 | if (b->pos >= b->last) { |
457 | 461 | |
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 | ||
461 | 464 | if (cf->args->nelts > 0) { |
462 | 465 | |
463 | 466 | if (cf->conf_file->file.fd == NGX_INVALID_FILE) { |
478 | 481 | |
479 | 482 | len = b->pos - start; |
480 | 483 | |
481 | if (len == ngx_pagesize) { | |
484 | if (len == NGX_CONF_BUFFER) { | |
482 | 485 | cf->conf_file->line = start_line; |
483 | 486 | |
484 | 487 | if (d_quoted) { |
504 | 507 | ngx_memcpy(b->start, start, len); |
505 | 508 | } |
506 | 509 | |
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, | |
509 | 517 | cf->conf_file->file.offset); |
510 | 518 | |
511 | 519 | 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); | |
512 | 528 | return NGX_ERROR; |
513 | 529 | } |
514 | 530 |