Both Linux and FreeBSD, check parameters to rte_eal_alarm_set, but Windows missed this. And the test was "fixed" instead.
This reverts commit a089d320338d708f5b7126dab5fd6861c82e6347. Windows EAL should have been fixed rather than papering over the bug. Signed-off-by: Stephen Hemminger <step...@networkplumber.org> --- app/test/test_alarm.c | 4 ---- lib/eal/windows/eal_alarm.c | 7 +++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/test/test_alarm.c b/app/test/test_alarm.c index 70e97a3109..b4034339b8 100644 --- a/app/test/test_alarm.c +++ b/app/test/test_alarm.c @@ -10,7 +10,6 @@ #include "test.h" -#ifndef RTE_EXEC_ENV_WINDOWS static volatile int flag; static void @@ -19,7 +18,6 @@ test_alarm_callback(void *cb_arg) flag = 1; printf("Callback setting flag - OK. [cb_arg = %p]\n", cb_arg); } -#endif static int test_alarm(void) @@ -29,7 +27,6 @@ test_alarm(void) return 0; #endif -#ifndef RTE_EXEC_ENV_WINDOWS /* check if it will fail to set alarm with wrong us value */ printf("check if it will fail to set alarm with wrong ms values\n"); if (rte_eal_alarm_set(0, test_alarm_callback, @@ -42,7 +39,6 @@ test_alarm(void) printf("should not be successful with (UINT64_MAX-1) us value\n"); return -1; } -#endif /* check if it will fail to set alarm with null callback parameter */ printf("check if it will fail to set alarm with null callback parameter\n"); diff --git a/lib/eal/windows/eal_alarm.c b/lib/eal/windows/eal_alarm.c index 052af4b21b..09a02a1cbf 100644 --- a/lib/eal/windows/eal_alarm.c +++ b/lib/eal/windows/eal_alarm.c @@ -92,6 +92,13 @@ rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb_fn, void *cb_arg) LARGE_INTEGER deadline; int ret; + /* Check parameters, including that us won't cause a uint64_t overflow */ + if (us < 1 || us > (UINT64_MAX - US_PER_S)) { + EAL_LOG(ERR, "Invalid alarm interval"); + ret = -EINVAL; + goto exit; + } + if (cb_fn == NULL) { EAL_LOG(ERR, "NULL callback"); ret = -EINVAL; -- 2.43.0