aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Weißschuh <thomas@t-8ch.de>2024-04-09 11:00:26 +0200
committerThomas Weißschuh <thomas@t-8ch.de>2024-04-09 11:10:16 +0200
commit6227b2b0585ee2ccf224cf70c7144296a814a4ab (patch)
tree1951e5533cfafe1d51fb878077c4d9fd20982f15
parent564750580b2a78c2f3f0e8d02bdef9503d6b110c (diff)
downloadutil-linux-6227b2b0585ee2ccf224cf70c7144296a814a4ab.tar.gz
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 <glaubitz@physik.fu-berlin.de> Link: https://lore.kernel.org/util-linux/afef1b770ad80d50660bb2c53a0a8330b88d1049.camel@physik.fu-berlin.de/ Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
-rw-r--r--misc-utils/logger.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index ec1fc8e347..f696287d7a 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -815,12 +815,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