From 323fbdbbd03e69ced13ecb836bec0b22501bd1b2 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Tue, 19 May 2026 15:02:32 +0200 Subject: [PATCH] hawkbit-client: add strptime() error check Check for strptime() parsing failures, issue a warning and return the default config `retry_wait` value. We should not run into such issues since the value is hawkBit-controlled, but better be safe than sorry. While at it, initialize the tm struct, so reading unfilled fields does not lead to undefined behavior. This is for good measure only since %T fills all fields currently used. Signed-off-by: Bastian Krause --- src/hawkbit-client.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/hawkbit-client.c b/src/hawkbit-client.c index a6d6aed9..7f8b526e 100644 --- a/src/hawkbit-client.c +++ b/src/hawkbit-client.c @@ -766,7 +766,7 @@ static long json_get_sleeptime(JsonNode *root) { g_autofree gchar *sleeptime_str = NULL; g_autoptr(GError) error = NULL; - struct tm time; + struct tm time = {0}; g_return_val_if_fail(root, 0L); @@ -788,7 +788,11 @@ static long json_get_sleeptime(JsonNode *root) return hawkbit_config->retry_wait; } - strptime(sleeptime_str, "%T", &time); + if (!strptime(sleeptime_str, "%T", &time)) { + g_warning("Invalid polling sleep time: %s. Using fallback: %ds", + sleeptime_str, hawkbit_config->retry_wait); + return hawkbit_config->retry_wait; + } return (time.tm_sec + (time.tm_min * 60) + (time.tm_hour * 60 * 60)); }