From 6457ce15be84cf3c304d1ba47b89bacc2f60bf6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 21 Nov 2022 20:03:08 +0100 Subject: [PATCH 1/2] manager: fix format strings for trigger metadata Fixup for c8bc7519c888a99134f88f8c82353246d3c0cc5d. --- src/core/timer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/timer.c b/src/core/timer.c index 8bd430b931..b6810c8599 100644 --- a/src/core/timer.c +++ b/src/core/timer.c @@ -948,11 +948,11 @@ static int activation_details_timer_append_env(ActivationDetails *details, char if (!dual_timestamp_is_set(&t->last_trigger)) return 0; - r = strv_extendf(strv, "TRIGGER_TIMER_REALTIME_USEC=%" USEC_FMT, t->last_trigger.realtime); + r = strv_extendf(strv, "TRIGGER_TIMER_REALTIME_USEC=" USEC_FMT, t->last_trigger.realtime); if (r < 0) return r; - r = strv_extendf(strv, "TRIGGER_TIMER_MONOTONIC_USEC=%" USEC_FMT, t->last_trigger.monotonic); + r = strv_extendf(strv, "TRIGGER_TIMER_MONOTONIC_USEC=" USEC_FMT, t->last_trigger.monotonic); if (r < 0) return r; @@ -974,7 +974,7 @@ static int activation_details_timer_append_pair(ActivationDetails *details, char if (r < 0) return r; - r = strv_extendf(strv, "%" USEC_FMT, t->last_trigger.realtime); + r = strv_extendf(strv, USEC_FMT, t->last_trigger.realtime); if (r < 0) return r; @@ -982,7 +982,7 @@ static int activation_details_timer_append_pair(ActivationDetails *details, char if (r < 0) return r; - r = strv_extendf(strv, "%" USEC_FMT, t->last_trigger.monotonic); + r = strv_extendf(strv, USEC_FMT, t->last_trigger.monotonic); if (r < 0) return r; From 400102ec91aa3404848a04f49a43d49e1a181708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 21 Nov 2022 20:06:55 +0100 Subject: [PATCH 2/2] basic/strv: check printf arguments to strv_extendf() The second argument to _printf_() specifies where the arguments start. We need to use 0 in two cases: when the args in a va_list and can't be checked, and with journald logging functions which accept multiple format strings with multiple argument sets, which the _printf_ checker does not understand. But strv_extendf() can be checked. --- src/basic/strv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic/strv.h b/src/basic/strv.h index 87a7038a54..f82c76589d 100644 --- a/src/basic/strv.h +++ b/src/basic/strv.h @@ -45,7 +45,7 @@ static inline int strv_extend(char ***l, const char *value) { return strv_extend_with_size(l, NULL, value); } -int strv_extendf(char ***l, const char *format, ...) _printf_(2,0); +int strv_extendf(char ***l, const char *format, ...) _printf_(2,3); int strv_extend_front(char ***l, const char *value); int strv_push_with_size(char ***l, size_t *n, char *value);