diff options
author | Aleksander Morgado <aleksandermj@chromium.org> | 2022-10-05 08:41:26 +0000 |
---|---|---|
committer | Aleksander Morgado <aleksandermj@chromium.org> | 2022-10-05 09:06:22 +0000 |
commit | bfba265009610e84af4f8e4b1b3f05ec3a2d56bc (patch) | |
tree | a2b2720b4ee3c52ac9cbf2d9d4715a1d753d714c /libmm-glib/mm-common-helpers.c | |
parent | 4628056a3e9ab908463ef826a8fe18366265c7f2 (diff) |
libmm-glib,common-helpers: don't assume new_from_unix_utc() always succeeds
The g_date_time_new_from_unix_utc() method in glib2 may fail if the
given timestamp is too far into the future. The value is supposed to
be seconds since unix time origin, but internally it will be converted
into usecs, so any value longer than G_MAXINT64 / USEC_PER_SECOND
isn't allowed.
This is currently used in the CLI, and we're anyway ignoring the error
returned in that case, but at least it won't crash if it ever happens.
Diffstat (limited to 'libmm-glib/mm-common-helpers.c')
-rw-r--r-- | libmm-glib/mm-common-helpers.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c index 085177b7..0dff0e8c 100644 --- a/libmm-glib/mm-common-helpers.c +++ b/libmm-glib/mm-common-helpers.c @@ -1752,11 +1752,18 @@ date_time_format_iso8601 (GDateTime *dt) } gchar * -mm_new_iso8601_time_from_unix_time (guint64 timestamp) +mm_new_iso8601_time_from_unix_time (guint64 timestamp, + GError **error) { g_autoptr(GDateTime) dt = NULL; dt = g_date_time_new_from_unix_utc ((gint64)timestamp); + if (!dt) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "Invalid unix time: %" G_GUINT64_FORMAT, + timestamp); + return NULL; + } return date_time_format_iso8601 (dt); } |