From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>, stable@dpdk.org
Subject: [PATCH 5/6] cmdline: guard zero-size destination buffers
Date: Thu, 7 May 2026 15:59:48 +0100 [thread overview]
Message-ID: <20260507145950.197753-6-bruce.richardson@intel.com> (raw)
In-Reply-To: <20260507145950.197753-1-bruce.richardson@intel.com>
Add missing zero-size destination checks in cmdline helper routines.
Always check for size == 0, before doing an assignment of '\0' to string
position of "size - 1".
Fixes: af75078fece3 ("first public release")
Cc: stable@dpdk.org
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
lib/cmdline/cmdline_parse_num.c | 2 +-
lib/cmdline/cmdline_parse_string.c | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/cmdline/cmdline_parse_num.c b/lib/cmdline/cmdline_parse_num.c
index f21796bedb..4cfc900391 100644
--- a/lib/cmdline/cmdline_parse_num.c
+++ b/lib/cmdline/cmdline_parse_num.c
@@ -323,7 +323,7 @@ cmdline_get_help_num(cmdline_parse_token_hdr_t *tk, char *dstbuf, unsigned int s
struct cmdline_token_num_data nd;
int ret;
- if (!tk)
+ if (!tk || !dstbuf || size == 0)
return -1;
memcpy(&nd, &((struct cmdline_token_num *)tk)->num_data, sizeof(nd));
diff --git a/lib/cmdline/cmdline_parse_string.c b/lib/cmdline/cmdline_parse_string.c
index 731947159f..33cf89f84f 100644
--- a/lib/cmdline/cmdline_parse_string.c
+++ b/lib/cmdline/cmdline_parse_string.c
@@ -171,6 +171,9 @@ int cmdline_complete_get_elt_string(cmdline_parse_token_hdr_t *tk, int idx,
if (!tk || !dstbuf || idx < 0)
return -1;
+ if (size == 0)
+ return -1;
+
tk2 = (struct cmdline_token_string *)tk;
sd = &tk2->string_data;
--
2.51.0
next prev parent reply other threads:[~2026-05-07 15:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-07 14:59 [PATCH 0/6] add hardening checks to cmdline and cfgfile libs Bruce Richardson
2026-05-07 14:59 ` [PATCH 1/6] cfgfile: add null checks to public APIs Bruce Richardson
2026-05-07 14:59 ` [PATCH 2/6] cfgfile: prevent issues with overflow on resize Bruce Richardson
2026-05-07 14:59 ` [PATCH 3/6] cmdline: harden parser result buffer handling Bruce Richardson
2026-05-07 14:59 ` [PATCH 4/6] cmdline: add explicit help function for bool type Bruce Richardson
2026-05-07 14:59 ` Bruce Richardson [this message]
2026-05-07 14:59 ` [PATCH 6/6] cmdline: add null checks for invalid input Bruce Richardson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260507145950.197753-6-bruce.richardson@intel.com \
--to=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=stable@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox