comparison src/http/ngx_http_request_body.c @ 725:86862ad988da

fix segfault when zero length file is PUT
author Igor Sysoev <igor@sysoev.ru>
date Sun, 01 Oct 2006 07:17:01 +0000
parents 7e24168b0853
children 790ed4eb762e
comparison
equal deleted inserted replaced
724:1e9977fd34aa 725:86862ad988da
32 { 32 {
33 size_t preread; 33 size_t preread;
34 ssize_t size; 34 ssize_t size;
35 ngx_buf_t *b; 35 ngx_buf_t *b;
36 ngx_chain_t *cl, **next; 36 ngx_chain_t *cl, **next;
37 ngx_temp_file_t *tf;
37 ngx_http_request_body_t *rb; 38 ngx_http_request_body_t *rb;
38 ngx_http_core_loc_conf_t *clcf; 39 ngx_http_core_loc_conf_t *clcf;
39 40
40 if (r->request_body || r->discard_body) { 41 if (r->request_body || r->discard_body) {
41 post_handler(r); 42 post_handler(r);
47 return NGX_HTTP_INTERNAL_SERVER_ERROR; 48 return NGX_HTTP_INTERNAL_SERVER_ERROR;
48 } 49 }
49 50
50 r->request_body = rb; 51 r->request_body = rb;
51 52
52 if (r->headers_in.content_length_n <= 0) { 53 if (r->headers_in.content_length_n < 0) {
54 post_handler(r);
55 return NGX_OK;
56 }
57
58 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
59
60 if (r->headers_in.content_length_n == 0) {
61
62 if (r->request_body_in_file_only) {
63 tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));
64 if (tf == NULL) {
65 return NGX_HTTP_INTERNAL_SERVER_ERROR;
66 }
67
68 tf->file.fd = NGX_INVALID_FILE;
69 tf->file.log = r->connection->log;
70 tf->path = clcf->client_body_temp_path;
71 tf->pool = r->pool;
72 tf->warn = "a client request body is buffered to a temporary file";
73 tf->log_level = r->request_body_file_log_level;
74 tf->persistent = r->request_body_in_persistent_file;
75
76 if (r->request_body_file_group_access) {
77 tf->mode = 0660;
78 }
79
80 rb->temp_file = tf;
81
82 if (ngx_create_temp_file(&tf->file, tf->path, tf->pool,
83 tf->persistent, tf->mode)
84 != NGX_OK)
85 {
86 return NGX_HTTP_INTERNAL_SERVER_ERROR;
87 }
88 }
89
53 post_handler(r); 90 post_handler(r);
54 return NGX_OK; 91 return NGX_OK;
55 } 92 }
56 93
57 rb->post_handler = post_handler; 94 rb->post_handler = post_handler;
136 } else { 173 } else {
137 b = NULL; 174 b = NULL;
138 rb->rest = r->headers_in.content_length_n; 175 rb->rest = r->headers_in.content_length_n;
139 next = &rb->bufs; 176 next = &rb->bufs;
140 } 177 }
141
142 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
143 178
144 size = clcf->client_body_buffer_size; 179 size = clcf->client_body_buffer_size;
145 size += size >> 2; 180 size += size >> 2;
146 181
147 if (rb->rest < size) { 182 if (rb->rest < size) {