From: Thomas Weißschuh Date: Tue, 9 Apr 2024 09:00:26 +0000 (+0200) Subject: logger: correctly format tv_usec X-Git-Tag: archive/raspbian/2.40.2-9+rpi1^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=83a1fbe2329a243879473421e6fa87bb81f8b56d;p=util-linux.git logger: correctly format tv_usec tv_usec is an unspecified signed integer type. The format string %u assumes an unsigned int, which is incorrect. Especially on 32bit big-endian, where it can lead to invalid values. Reported-by: John Paul Adrian Glaubitz Link: https://lore.kernel.org/util-linux/afef1b770ad80d50660bb2c53a0a8330b88d1049.camel@physik.fu-berlin.de/ Signed-off-by: Thomas Weißschuh Gbp-Pq: Topic upstream-master Gbp-Pq: Name logger-correctly-format-tv_usec.patch --- diff --git a/misc-utils/logger.c b/misc-utils/logger.c index e1d270d..e928286 100644 --- a/misc-utils/logger.c +++ b/misc-utils/logger.c @@ -798,12 +798,12 @@ static void syslog_rfc5424_header(struct logger_ctl *const ctl) if (localtime_r(&tv.tv_sec, &tm) != NULL) { char fmt[64]; const size_t i = strftime(fmt, sizeof(fmt), - "%Y-%m-%dT%H:%M:%S.%%06u%z ", &tm); + "%Y-%m-%dT%H:%M:%S.%%06jd%z ", &tm); /* patch TZ info to comply with RFC3339 (we left SP at end) */ fmt[i - 1] = fmt[i - 2]; fmt[i - 2] = fmt[i - 3]; fmt[i - 3] = ':'; - xasprintf(&time, fmt, tv.tv_usec); + xasprintf(&time, fmt, (intmax_t) tv.tv_usec); } else err(EXIT_FAILURE, _("localtime() failed")); } else