Skip to content

Commit 6482e46

Browse files
committed
http: compression: Set the temporary file name in n_h_c_c_s_r()
When creating a new nxt_file_t structure in nxt_http_comp_compress_static_response() for the temporary compressed file be sure to set the *name* member. We don't generally need it, but I failed to notice that when calling nxt_file_close() if the close(2) fails then we log an error message containing the file name, which at best would have just printed junk. So set the file name for this particular error case... This issue was reported by coverity. Signed-off-by: Andrew Clayton <[email protected]>
1 parent 9f29628 commit 6482e46

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/nxt_http_compression.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,12 @@ nxt_http_comp_compress_app_response(nxt_task_t *task, nxt_http_request_t *r,
232232

233233

234234
nxt_int_t
235-
nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_file_t **f,
236-
nxt_file_info_t *fi,
237-
size_t static_buf_len,
238-
size_t *out_total)
235+
nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_http_request_t *r,
236+
nxt_file_t **f, nxt_file_info_t *fi,
237+
size_t static_buf_len, size_t *out_total)
239238
{
240-
char tmp_path[NXT_MAX_PATH_LEN];
241239
size_t in_size, out_size, rest;
242-
u_char *p;
240+
char *tmp_path, *p;
243241
uint8_t *in, *out;
244242
nxt_int_t ret;
245243
nxt_file_t tfile;
@@ -249,13 +247,14 @@ nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_file_t **f,
249247

250248
*out_total = 0;
251249

252-
if (nxt_slow_path(strlen(rt->tmp) + 1 + strlen(template) + 1
253-
> NXT_MAX_PATH_LEN))
254-
{
250+
tmp_path = nxt_mp_nget(r->mem_pool,
251+
strlen(rt->tmp) + 1 + strlen(template) + 1);
252+
if (nxt_slow_path(tmp_path == NULL)) {
255253
return NXT_ERROR;
256254
}
257255

258-
p = nxt_cpymem(tmp_path, rt->tmp, strlen(rt->tmp));
256+
p = tmp_path;
257+
p = nxt_cpymem(p, rt->tmp, strlen(rt->tmp));
259258
*p++ = '/';
260259
p = nxt_cpymem(p, template, strlen(template));
261260
*p = '\0';
@@ -266,6 +265,7 @@ nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_file_t **f,
266265
return NXT_ERROR;
267266
}
268267
unlink(tmp_path);
268+
tfile.name = (nxt_file_name_t *)tmp_path;
269269

270270
in_size = nxt_file_size(fi);
271271
out_size = nxt_http_comp_bound(in_size);

src/nxt_http_compression.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ extern const nxt_http_comp_operations_t nxt_http_comp_brotli_ops;
9393
extern nxt_int_t nxt_http_comp_compress_app_response(nxt_task_t *task,
9494
nxt_http_request_t *r, nxt_buf_t **b);
9595
extern nxt_int_t nxt_http_comp_compress_static_response(nxt_task_t *task,
96-
nxt_file_t **f, nxt_file_info_t *fi, size_t static_buf_len,
97-
size_t *out_total);
96+
nxt_http_request_t *r, nxt_file_t **f, nxt_file_info_t *fi,
97+
size_t static_buf_len, size_t *out_total);
9898
extern bool nxt_http_comp_wants_compression(void);
9999
extern bool nxt_http_comp_compressor_is_valid(const nxt_str_t *token);
100100
extern nxt_int_t nxt_http_comp_check_compression(nxt_task_t *task,

src/nxt_http_static.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ nxt_http_static_send(nxt_task_t *task, nxt_http_request_t *r,
593593
nxt_int_t ret;
594594

595595
ret = nxt_http_comp_compress_static_response(
596-
task, &f, &fi,
596+
task, r, &f, &fi,
597597
NXT_HTTP_STATIC_BUF_SIZE,
598598
&out_total);
599599
if (ret == NXT_ERROR) {

0 commit comments

Comments
 (0)