Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2008-09-01 17:59:11 +0400
committerIgor Sysoev <igor@sysoev.ru>2008-09-01 17:59:11 +0400
commit63c78f3c34f75ec1b2e0df8daf28b7f356955b6d (patch)
tree5bac8ac0d06ca03fbfc4d45214fcdfca51d76b09 /src/core
parentf4423eb7b5f840f6ffe70e6a2b19e5e42a1bfd63 (diff)
test conf file size, this fixes OpenBSD's "nginx -c /tmp/" bug
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ngx_conf_file.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index b6c94a52f..c7e155c09 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -7,6 +7,7 @@
#include <ngx_config.h>
#include <ngx_core.h>
+#define NGX_CONF_BUFFER 4096
static ngx_int_t ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last);
static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf);
@@ -43,7 +44,7 @@ ngx_module_t ngx_conf_module = {
};
-/* The ten fixed arguments */
+/* The eight fixed arguments */
static ngx_uint_t argument_number[] = {
NGX_CONF_NOARGS,
@@ -141,14 +142,14 @@ ngx_conf_parse(ngx_conf_t *cf, ngx_str_t *filename)
cf->conf_file->buffer = b;
- b->start = ngx_alloc(ngx_pagesize, cf->log);
+ b->start = ngx_alloc(NGX_CONF_BUFFER, cf->log);
if (b->start == NULL) {
return NGX_CONF_ERROR;
}
b->pos = b->start;
b->last = b->start;
- b->end = b->last + ngx_pagesize;
+ b->end = b->last + NGX_CONF_BUFFER;
b->temporary = 1;
cf->conf_file->file.fd = fd;
@@ -433,8 +434,9 @@ static ngx_int_t
ngx_conf_read_token(ngx_conf_t *cf)
{
u_char *start, ch, *src, *dst;
+ off_t file_size;
size_t len;
- ssize_t n;
+ ssize_t n, size;
ngx_uint_t found, need_space, last_space, sharp_comment, variable;
ngx_uint_t quoted, s_quoted, d_quoted, start_line;
ngx_str_t *word;
@@ -452,13 +454,14 @@ ngx_conf_read_token(ngx_conf_t *cf)
start = b->pos;
start_line = cf->conf_file->line;
+ file_size = ngx_file_size(&cf->conf_file->file.info);
+
for ( ;; ) {
if (b->pos >= b->last) {
- if (cf->conf_file->file.offset
- >= ngx_file_size(&cf->conf_file->file.info))
- {
+ if (cf->conf_file->file.offset >= file_size) {
+
if (cf->args->nelts > 0) {
if (cf->conf_file->file.fd == NGX_INVALID_FILE) {
@@ -479,7 +482,7 @@ ngx_conf_read_token(ngx_conf_t *cf)
len = b->pos - start;
- if (len == ngx_pagesize) {
+ if (len == NGX_CONF_BUFFER) {
cf->conf_file->line = start_line;
if (d_quoted) {
@@ -505,14 +508,27 @@ ngx_conf_read_token(ngx_conf_t *cf)
ngx_memcpy(b->start, start, len);
}
- n = ngx_read_file(&cf->conf_file->file, b->start + len,
- b->end - (b->start + len),
+ size = file_size - cf->conf_file->file.offset;
+
+ if (size > b->end - (b->start + len)) {
+ size = b->end - (b->start + len);
+ }
+
+ n = ngx_read_file(&cf->conf_file->file, b->start + len, size,
cf->conf_file->file.offset);
if (n == NGX_ERROR) {
return NGX_ERROR;
}
+ if (n != size) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ ngx_read_file_n " returned "
+ "only %z bytes instead of %z",
+ n, size);
+ return NGX_ERROR;
+ }
+
b->pos = b->start + len;
b->last = b->pos + n;
start = b->start;