diff options
author | Thomas Haller <thaller@redhat.com> | 2020-10-21 12:51:48 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-06-10 15:45:59 +0200 |
commit | 500c63db3c0b102c01ad1e93b8ff74fb3e19b9d2 (patch) | |
tree | c452d93f6310706f55c3fac3461e88c4a1f934a3 | |
parent | 675c7df8c21c6260205d262462419835ee95b0c4 (diff) | |
download | NetworkManager-500c63db3c0b102c01ad1e93b8ff74fb3e19b9d2.tar.gz |
platform/tests: better handling "timeout_msec" argument in nmtst_main_context_iterate_until()
nmtst_main_context_iterate_until() is a macro, and we don't want to restrict the
valid integer type (or range) of the "timeout_msec" argument.
In particular, if the user calculates a timeout with "timestamp_msec -
now_msec", the resulting "timeout_msec" might be a negative gint64.
We should handle that gracefully, and not let it be cast to a huge
unsigned int.
(cherry picked from commit 6cb688840461c0093337e66184bcd1a5106a8c3f)
(cherry picked from commit 4d572bea7e5dad287d436e0ac48ab3c4c7bed7f3)
(cherry picked from commit 95b74a3bdee81e0c713f7a6d162642625742dd63)
-rw-r--r-- | shared/nm-utils/nm-test-utils.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h index 96e361358f..d10ba98dcb 100644 --- a/shared/nm-utils/nm-test-utils.h +++ b/shared/nm-utils/nm-test-utils.h @@ -1117,8 +1117,12 @@ _nmtst_main_loop_quit_on_notify (GObject *object, GParamSpec *pspec, gpointer us nm_auto_destroy_and_unref_gsource GSource *_source = NULL; \ GMainContext *_context = (context); \ gboolean _had_timeout = FALSE; \ + typeof(timeout_msec) _timeout_msec0 = (timeout_msec); \ + gint64 _timeout_msec = _timeout_msec0; \ \ - _source = g_timeout_source_new (timeout_msec); \ + g_assert_cmpint(_timeout_msec0, ==, _timeout_msec); \ + \ + _source = g_timeout_source_new (NM_CLAMP (_timeout_msec, 0, (gint64) G_MAXUINT)); \ g_source_set_callback (_source, nmtst_g_source_set_boolean_true, &_had_timeout, NULL); \ g_source_attach (_source, _context); \ \ |