From 0b715ccb93a78368b4cb2ac36476729a0d745402 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Wed, 5 Nov 2025 13:05:54 -0500 Subject: [PATCH] Fix: libcrmcommon: Don't assert in time_to_hr. This just allows time_to_hr and pcmk__time_hr_now to return NULL, which can then be handled higher up in the call stack. This is just to address an automatically filed fuzzer bug report - it can't figure out how to deal with the fact that a function it's fuzzing can assert. Fixes https://issues.oss-fuzz.com/issues/456526118 --- lib/common/iso8601.c | 9 ++++++++- lib/common/tests/iso8601/pcmk__time_format_hr_test.c | 2 ++ lib/lrmd/lrmd_alerts.c | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 0b419e69c86..849e472f4bd 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1925,7 +1925,9 @@ time_to_hr(const crm_time_t *dt) { pcmk__time_hr_t *hr_dt = NULL; - pcmk__assert(dt != NULL); + if (dt == NULL) { + return NULL; + } hr_dt = pcmk__assert_alloc(1, sizeof(pcmk__time_hr_t)); hr_dt->years = dt->years; @@ -1957,7 +1959,12 @@ pcmk__time_hr_now(time_t *epoch) *epoch = tv.tv_sec; } crm_time_set_timet(&dt, &(tv.tv_sec)); + hr = time_to_hr(&dt); + if (hr == NULL) { + return NULL; + } + hr->useconds = tv.tv_nsec / QB_TIME_NS_IN_USEC; return hr; } diff --git a/lib/common/tests/iso8601/pcmk__time_format_hr_test.c b/lib/common/tests/iso8601/pcmk__time_format_hr_test.c index 3b9ad79d362..7d7fc58112a 100644 --- a/lib/common/tests/iso8601/pcmk__time_format_hr_test.c +++ b/lib/common/tests/iso8601/pcmk__time_format_hr_test.c @@ -45,6 +45,8 @@ assert_hr_format(const char *format, const char *expected, pcmk__time_hr_t *hr = TEST_TIME; char *result = NULL; + assert_non_null(hr); + hr->useconds = usec; result = pcmk__time_format_hr(format, hr); pcmk__time_hr_free(hr); diff --git a/lib/lrmd/lrmd_alerts.c b/lib/lrmd/lrmd_alerts.c index 79798425445..8e7cd443d55 100644 --- a/lib/lrmd/lrmd_alerts.c +++ b/lib/lrmd/lrmd_alerts.c @@ -155,6 +155,7 @@ exec_alert_list(lrmd_t *lrmd, const GList *alert_list, if (now == NULL) { now = pcmk__time_hr_now(&epoch); + pcmk__assert(now != NULL); } crm_info("Sending %s alert via %s to %s", kind_s, entry->id, entry->recipient);