From 847d1401a052f0db5d1eb9f0a7beef7c9a7589a2 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Fri, 27 Dec 2024 16:42:21 +0100 Subject: [PATCH] Fix GH-17208: bug64539-status-json-encoding.phpt fail on 32-bits The reason this breaks is because of a type mismatch. The following line uses fields of the timeval struct which are both 8 bytes on Alpine 32-bit, which results in a computed value of also 8 bytes: https://github.com/php/php-src/blob/b09ed9a0f25cda8c9eea9d140c01587cd50b4aa8/sapi/fpm/fpm/fpm_status.c#L611 However, it is passed to a format string which expects 4 bytes (`unsigned long` and thus the `%lu` format specifier is 4 bytes on Alpine 32-bit), resulting in argument corruption. Since the value is generally small, truncating to 4 bytes is sufficient to fix this. Closes GH-17286. --- NEWS | 2 ++ sapi/fpm/fpm/fpm_status.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 5468d134f335e..72dec4b340d7f 100644 --- a/NEWS +++ b/NEWS @@ -38,6 +38,8 @@ PHP NEWS . Fixed bug GH-13437 (FPM: ERROR: scoreboard: failed to lock (already locked)). (Jakub Zelenka) . Fixed bug GH-17112 (Macro redefinitions). (cmb, nielsdos) + . Fixed bug GH-17208 (bug64539-status-json-encoding.phpt fail on 32-bits). + (nielsdos) - GD: . Fixed bug GH-16255 (Unexpected nan value in ext/gd/libgd/gd_filter.c). diff --git a/sapi/fpm/fpm/fpm_status.c b/sapi/fpm/fpm/fpm_status.c index 80be5fb6f476e..f44274e9d9ee4 100644 --- a/sapi/fpm/fpm/fpm_status.c +++ b/sapi/fpm/fpm/fpm_status.c @@ -598,7 +598,7 @@ int fpm_status_handle_request(void) /* {{{ */ time_buffer, (unsigned long) (now_epoch - proc->start_epoch), proc->requests, - duration.tv_sec * 1000000UL + duration.tv_usec, + (unsigned long) (duration.tv_sec * 1000000UL + duration.tv_usec), proc->request_method[0] != '\0' ? proc->request_method : "-", proc->request_uri[0] != '\0' ? proc->request_uri : "-", query_string ? "?" : "",