From: Michael Braun <michael-dev@fami-braun.de>
To: netfilter-devel@vger.kernel.org
Cc: Michael Braun <michael-dev@fami-braun.de>
Subject: [PATCH] main: fix get_optstring truncating output
Date: Sat, 2 May 2020 12:11:43 +0200 [thread overview]
Message-ID: <20200502101143.18160-1-michael-dev@fami-braun.de> (raw)
Without this patch, get_optstring returns optstring = +hvVcf:insNSI:d:aejuy.
After this patch, get_optstring returns optstring = +hvVcf:insNSI:d:aejuypTt
This is due to optstring containing up to two chars per option, thus it was too
short.
Signed-off-by: Michael Braun <michael-dev@fami-braun.de>
---
src/main.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/main.c b/src/main.c
index d213c601..d830c7a2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -118,7 +118,7 @@ static const struct nft_opt nft_options[] = {
static const char *get_optstring(void)
{
- static char optstring[NR_NFT_OPTIONS + 2];
+ static char optstring[2 * NR_NFT_OPTIONS + 2];
if (!optstring[0]) {
size_t i, j;
@@ -128,6 +128,8 @@ static const char *get_optstring(void)
j += snprintf(optstring + j, sizeof(optstring) - j, "%c%s",
nft_options[i].val,
nft_options[i].arg ? ":" : "");
+
+ assert(j < sizeof(optstring));
}
return optstring;
}
--
2.20.1
next reply other threads:[~2020-05-02 10:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-02 10:11 Michael Braun [this message]
2020-05-02 16:49 ` [PATCH] main: fix get_optstring truncating output Pablo Neira Ayuso
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=20200502101143.18160-1-michael-dev@fami-braun.de \
--to=michael-dev@fami-braun.de \
--cc=netfilter-devel@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).