diff options
| author | Andrew Clayton <a.clayton@nginx.com> | 2025-08-11 19:08:07 +0100 |
|---|---|---|
| committer | Andrew Clayton <a.clayton@nginx.com> | 2025-08-20 13:55:59 +0100 |
| commit | 6482e46a6b35214967095169842e1d5403a01d4d (patch) | |
| tree | d010fd9b480b389293dc90367bf3f1e81098c630 /src | |
| parent | 9f29628f01636abf5a0eaf2a97898267f6b39fa7 (diff) | |
| download | unit-6482e46a6b35214967095169842e1d5403a01d4d.tar.gz unit-6482e46a6b35214967095169842e1d5403a01d4d.tar.bz2 | |
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 <a.clayton@nginx.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/nxt_http_compression.c | 20 | ||||
| -rw-r--r-- | src/nxt_http_compression.h | 4 | ||||
| -rw-r--r-- | src/nxt_http_static.c | 2 |
3 files changed, 13 insertions, 13 deletions
diff --git a/src/nxt_http_compression.c b/src/nxt_http_compression.c index 28e53a9d..4f4eec1a 100644 --- a/src/nxt_http_compression.c +++ b/src/nxt_http_compression.c @@ -232,14 +232,12 @@ nxt_http_comp_compress_app_response(nxt_task_t *task, nxt_http_request_t *r, nxt_int_t -nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_file_t **f, - nxt_file_info_t *fi, - size_t static_buf_len, - size_t *out_total) +nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_http_request_t *r, + nxt_file_t **f, nxt_file_info_t *fi, + size_t static_buf_len, size_t *out_total) { - char tmp_path[NXT_MAX_PATH_LEN]; size_t in_size, out_size, rest; - u_char *p; + char *tmp_path, *p; uint8_t *in, *out; nxt_int_t ret; nxt_file_t tfile; @@ -249,13 +247,14 @@ nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_file_t **f, *out_total = 0; - if (nxt_slow_path(strlen(rt->tmp) + 1 + strlen(template) + 1 - > NXT_MAX_PATH_LEN)) - { + tmp_path = nxt_mp_nget(r->mem_pool, + strlen(rt->tmp) + 1 + strlen(template) + 1); + if (nxt_slow_path(tmp_path == NULL)) { return NXT_ERROR; } - p = nxt_cpymem(tmp_path, rt->tmp, strlen(rt->tmp)); + p = tmp_path; + p = nxt_cpymem(p, rt->tmp, strlen(rt->tmp)); *p++ = '/'; p = nxt_cpymem(p, template, strlen(template)); *p = '\0'; @@ -266,6 +265,7 @@ nxt_http_comp_compress_static_response(nxt_task_t *task, nxt_file_t **f, return NXT_ERROR; } unlink(tmp_path); + tfile.name = (nxt_file_name_t *)tmp_path; in_size = nxt_file_size(fi); out_size = nxt_http_comp_bound(in_size); diff --git a/src/nxt_http_compression.h b/src/nxt_http_compression.h index f178e984..99af8a66 100644 --- a/src/nxt_http_compression.h +++ b/src/nxt_http_compression.h @@ -93,8 +93,8 @@ extern const nxt_http_comp_operations_t nxt_http_comp_brotli_ops; extern nxt_int_t nxt_http_comp_compress_app_response(nxt_task_t *task, nxt_http_request_t *r, nxt_buf_t **b); extern nxt_int_t nxt_http_comp_compress_static_response(nxt_task_t *task, - nxt_file_t **f, nxt_file_info_t *fi, size_t static_buf_len, - size_t *out_total); + nxt_http_request_t *r, nxt_file_t **f, nxt_file_info_t *fi, + size_t static_buf_len, size_t *out_total); extern bool nxt_http_comp_wants_compression(void); extern bool nxt_http_comp_compressor_is_valid(const nxt_str_t *token); extern nxt_int_t nxt_http_comp_check_compression(nxt_task_t *task, diff --git a/src/nxt_http_static.c b/src/nxt_http_static.c index 78b1f150..8436b417 100644 --- a/src/nxt_http_static.c +++ b/src/nxt_http_static.c @@ -593,7 +593,7 @@ nxt_http_static_send(nxt_task_t *task, nxt_http_request_t *r, nxt_int_t ret; ret = nxt_http_comp_compress_static_response( - task, &f, &fi, + task, r, &f, &fi, NXT_HTTP_STATIC_BUF_SIZE, &out_total); if (ret == NXT_ERROR) { |
