DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v1] lib/eal: enforce alarm APIs parameters check
@ 2021-06-24  0:36 Jie Zhou
  2021-06-30 23:31 ` Dmitry Kozlyuk
  2021-07-07 20:25 ` [dpdk-dev] [PATCH v2] eal/windows: enforce alarm APIs parameter check Jie Zhou
  0 siblings, 2 replies; 9+ messages in thread
From: Jie Zhou @ 2021-06-24  0:36 UTC (permalink / raw)
  To: dev; +Cc: dmitry.kozliuk, roretzla, talshn, pallavi.kadam, navasile, dmitrym

From: Jie Zhou <jizh@microsoft.com>

lib/eal alarm APIs rte_eal_alarm_set and rte_eal_alarm_cancel
on Windows do not check parameters to fail fast for invalid
parameters, which captured by DPDK UT alarm_autotest.

Enforce Windows lib/eal alarm APIs parameters check and log
invalid parameter info.

Signed-off-by: Jie Zhou <jizh@microsoft.com>
Signed-off-by: Jie Zhou <jizh@linux.microsoft.com>

---
 lib/eal/windows/eal_alarm.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/lib/eal/windows/eal_alarm.c b/lib/eal/windows/eal_alarm.c
index f5bf88715a..7bb79ae869 100644
--- a/lib/eal/windows/eal_alarm.c
+++ b/lib/eal/windows/eal_alarm.c
@@ -4,6 +4,7 @@
 
 #include <stdatomic.h>
 #include <stdbool.h>
+#include <inttypes.h>
 
 #include <rte_alarm.h>
 #include <rte_spinlock.h>
@@ -91,6 +92,22 @@ rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback cb_fn, void *cb_arg)
 	LARGE_INTEGER deadline;
 	int ret;
 
+	/* Check if us is valid */
+	if (us < 1 || us >(UINT64_MAX - US_PER_S)) {
+		RTE_LOG(ERR, EAL, "Invalid us: %" PRIu64 "\n"
+			"Valid us range is 1 to (UINT64_MAX - US_PER_S)\n",
+			us);
+		ret = -EINVAL;
+		goto exit;
+	}
+
+	/* Check if callback is not NULL */
+	if (!cb_fn) {
+		RTE_LOG(ERR, EAL, "NULL callback\n");
+		ret = -EINVAL;
+		goto exit;
+	}
+
 	/* Calculate deadline ASAP, unit of measure = 100ns. */
 	GetSystemTimePreciseAsFileTime(&ft);
 	deadline.LowPart = ft.dwLowDateTime;
@@ -180,6 +197,12 @@ rte_eal_alarm_cancel(rte_eal_alarm_callback cb_fn, void *cb_arg)
 	bool executing;
 
 	removed = 0;
+
+	if (!cb_fn) {
+		RTE_LOG(ERR, EAL, "NULL callback\n");
+		return -EINVAL;
+	}
+
 	do {
 		executing = false;
 
-- 
2.31.0.vfs.0.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-07-22 20:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-24  0:36 [dpdk-dev] [PATCH v1] lib/eal: enforce alarm APIs parameters check Jie Zhou
2021-06-30 23:31 ` Dmitry Kozlyuk
2021-07-01 16:21   ` Tyler Retzlaff
2021-07-01 21:36     ` Dmitry Kozlyuk
2021-07-01 21:45       ` Tyler Retzlaff
2021-07-07 17:29         ` Jie Zhou
2021-07-07 20:25 ` [dpdk-dev] [PATCH v2] eal/windows: enforce alarm APIs parameter check Jie Zhou
2021-07-21 15:28   ` Dmitry Kozlyuk
2021-07-22 20:06     ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).