fix segfault when zero length file is PUT
Igor Sysoev
15 years ago
33 | 33 | ssize_t size; |
34 | 34 | ngx_buf_t *b; |
35 | 35 | ngx_chain_t *cl, **next; |
36 | ngx_temp_file_t *tf; | |
36 | 37 | ngx_http_request_body_t *rb; |
37 | 38 | ngx_http_core_loc_conf_t *clcf; |
38 | 39 | |
48 | 49 | |
49 | 50 | r->request_body = rb; |
50 | 51 | |
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 | ||
52 | 89 | post_handler(r); |
53 | 90 | return NGX_OK; |
54 | 91 | } |
137 | 174 | rb->rest = r->headers_in.content_length_n; |
138 | 175 | next = &rb->bufs; |
139 | 176 | } |
140 | ||
141 | clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
142 | 177 | |
143 | 178 | size = clcf->client_body_buffer_size; |
144 | 179 | size += size >> 2; |