$echo_timer_elapsed is corrupted on 32-bit platforms with 64-bit time_t
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start in src/ngx_http_echo_timer.c at ngx_http_echo_timer_elapsed_variable and review the ngx_snprintf call that formats $echo_timer_elapsed. Reproduce or inspect the armhf CI failure linked in the issue, then verify that the elapsed value is formatted correctly on 32-bit platforms with 64-bit time_t.
Written by the indexing model from the issue text.
Description
Hi,
$echo_timer_elapsed produces corrupted values on 32-bit platforms where time_t is 64-bit, such as armhf systems.
Example output:
elapsed 17592186044416.611 sec.
elapsed 93427976913289250.458 sec.
In some cases the result can also be negative:
-8549631993283870719.457
The problem is reproducible with echo-nginx-module 0.65 and nginx 1.30.4 on armhf. The relevant test failures can be seen in this CI log:
https://ci.debian.net/data/autopkgtest/testing/armhf/libn/libnginx-mod-http-echo/74055259/log.gz
The issue appears to be a varargs type mismatch in src/ngx_http_echo_timer.c:
v->len = ngx_snprintf(p, size, "%T.%03M",
ms / 1000, ms % 1000) - p;
The nginx-specific %T format specifier expects a time_t, while ms / 1000 has type ngx_msec_int_t. On a 32-bit platform with a 64-bit time_t, ngx_snprintf() therefore reads an argument with the wrong width,
resulting in undefined behaviour and corrupted output.
Explicitly converting both arguments to the types required by the format specifiers fixes the issue:
--- a/src/ngx_http_echo_timer.c
+++ b/src/ngx_http_echo_timer.c
@@ -76,7 +76,8 @@ ngx_http_echo_timer_elapsed_variable(ngx_http_request_t *r,
return NGX_ERROR;
}
- v->len = ngx_snprintf(p, size, "%T.%03M", ms / 1000, ms % 1000) - p;
+ v->len = ngx_snprintf(p, size, "%T.%03M", (time_t) (ms / 1000),
+ (ngx_msec_t) (ms % 1000)) - p;
v->data = p;
v->valid = 1;
Jan
- Dominant language
- C
- Stars
- 1.2k
- Forks
- 251
- Avg merge
- 1h 24m
- Merged PRs (30d)
- 2
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from openresty/echo-nginx-module
-
Difficulty 4/5 3-5 days Newbie friendliness 32/100
openresty/echo-nginx-module#117 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
openresty/echo-nginx-module#115 · 1 comment ·
-
Update nginx 1.25.5 Open
Difficulty 4/5 3-5 days Newbie friendliness 25/100
openresty/echo-nginx-module#114 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
openresty/echo-nginx-module#112 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
openresty/echo-nginx-module#111 ·
All issues in openresty/echo-nginx-module
Similar issues
-
level/task module/gcp type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
docs
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
P3 sonic-vpp
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
sonic-net/sonic-buildimage#29662 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
spack/spack-packages#6586 ·
-
category:port-update
Difficulty 2/5 1-3 hours Newbie friendliness 72/100