Klaus Demo nginx / 4c7f511
fix segfault when zero length file is PUT Igor Sysoev 15 years ago
1 changed file(s) with 38 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
3333 ssize_t size;
3434 ngx_buf_t *b;
3535 ngx_chain_t *cl, **next;
36 ngx_temp_file_t *tf;
3637 ngx_http_request_body_t *rb;
3738 ngx_http_core_loc_conf_t *clcf;
3839
4849
4950 r->request_body = rb;
5051
51 if (r->headers_in.content_length_n <= 0) {
52 if (r->headers_in.content_length_n < 0) {
53 post_handler(r);
54 return NGX_OK;
55 }
56
57 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
58
59 if (r->headers_in.content_length_n == 0) {
60
61 if (r->request_body_in_file_only) {
62 tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));
63 if (tf == NULL) {
64 return NGX_HTTP_INTERNAL_SERVER_ERROR;
65 }
66
67 tf->file.fd = NGX_INVALID_FILE;
68 tf->file.log = r->connection->log;
69 tf->path = clcf->client_body_temp_path;
70 tf->pool = r->pool;
71 tf->warn = "a client request body is buffered to a temporary file";
72 tf->log_level = r->request_body_file_log_level;
73 tf->persistent = r->request_body_in_persistent_file;
74
75 if (r->request_body_file_group_access) {
76 tf->mode = 0660;
77 }
78
79 rb->temp_file = tf;
80
81 if (ngx_create_temp_file(&tf->file, tf->path, tf->pool,
82 tf->persistent, tf->mode)
83 != NGX_OK)
84 {
85 return NGX_HTTP_INTERNAL_SERVER_ERROR;
86 }
87 }
88
5289 post_handler(r);
5390 return NGX_OK;
5491 }
137174 rb->rest = r->headers_in.content_length_n;
138175 next = &rb->bufs;
139176 }
140
141 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
142177
143178 size = clcf->client_body_buffer_size;
144179 size += size >> 2;