From c065e4b1af7f864d54669a8cf429740f9c8180a6 Mon Sep 17 00:00:00 2001 From: harshraj1695 Date: Wed, 18 Mar 2026 14:07:26 +0530 Subject: [PATCH] simple_forward: validate destination argument (-d) Previously, the -d argument was parsed without validating the input. This could lead to unintended behavior when non-numeric values were provided, silently defaulting to 0. This patch adds proper validation to ensure only valid numeric service IDs are accepted. Tested by running NF with valid and invalid -d values. --- examples/simple_forward/forward.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/simple_forward/forward.c b/examples/simple_forward/forward.c index 7b857e5ef..d86bae4f8 100644 --- a/examples/simple_forward/forward.c +++ b/examples/simple_forward/forward.c @@ -85,10 +85,19 @@ parse_app_args(int argc, char *argv[], const char *progname) { while ((c = getopt(argc, argv, "d:p:")) != -1) { switch (c) { - case 'd': - destination = strtoul(optarg, NULL, 10); + case 'd': { + char *end = NULL; + unsigned long val = strtoul(optarg, &end, 10); + + if (end == optarg || *end != '\0') { + RTE_LOG(INFO, APP, "Invalid destination ID: %s\n", optarg); + return -1; + } + + destination = (uint32_t)val; dst_flag = 1; break; + } case 'p': print_delay = strtoul(optarg, NULL, 10); break;