Skip to content

Commit 323fbdb

Browse files
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 <bst@pengutronix.de>
1 parent 9693c55 commit 323fbdb

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/hawkbit-client.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ static long json_get_sleeptime(JsonNode *root)
766766
{
767767
g_autofree gchar *sleeptime_str = NULL;
768768
g_autoptr(GError) error = NULL;
769-
struct tm time;
769+
struct tm time = {0};
770770

771771
g_return_val_if_fail(root, 0L);
772772

@@ -788,7 +788,11 @@ static long json_get_sleeptime(JsonNode *root)
788788
return hawkbit_config->retry_wait;
789789
}
790790

791-
strptime(sleeptime_str, "%T", &time);
791+
if (!strptime(sleeptime_str, "%T", &time)) {
792+
g_warning("Invalid polling sleep time: %s. Using fallback: %ds",
793+
sleeptime_str, hawkbit_config->retry_wait);
794+
return hawkbit_config->retry_wait;
795+
}
792796
return (time.tm_sec + (time.tm_min * 60) + (time.tm_hour * 60 * 60));
793797
}
794798

0 commit comments

Comments
 (0)