From 90b6491fa8a9c9adf5d6c4da6ee40cfabfb7d4ea Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 13 Oct 2022 11:03:41 +0200 Subject: [PATCH] glib-aux: don't assert for integer range in nm_utils_monotonic_timestamp_from_boottime() The boottime argument might come from the system, and we should not assert that it's reasonably small. It might be infinity. In that case, keep it at infinity. --- src/libnm-glib-aux/nm-time-utils.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libnm-glib-aux/nm-time-utils.c b/src/libnm-glib-aux/nm-time-utils.c index f30e6a1994..873ee9cb33 100644 --- a/src/libnm-glib-aux/nm-time-utils.c +++ b/src/libnm-glib-aux/nm-time-utils.c @@ -301,8 +301,13 @@ nm_utils_monotonic_timestamp_from_boottime(guint64 boottime, gint64 timestamp_ns nm_assert(offset <= 0 && offset > G_MININT64); - /* check for overflow (note that offset is non-positive). */ - g_return_val_if_fail(boottime < G_MAXINT64, G_MAXINT64); + if (boottime >= (guint64) G_MAXINT64) { + /* This indicates infinity. We keep it at such. */ + return G_MAXINT64; + } + + /* Note that overflow cannot happen, because bootime is non-negative, and + * offset is non-positive. */ return (gint64) boottime + offset; }