diff mbox series

main: fix get_optstring truncating output

Message ID 20200502101143.18160-1-michael-dev@fami-braun.de
State Accepted
Delegated to: Pablo Neira
Headers show
Series main: fix get_optstring truncating output | expand

Commit Message

michael-dev May 2, 2020, 10:11 a.m. UTC
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(-)

Comments

Pablo Neira Ayuso May 2, 2020, 4:49 p.m. UTC | #1
On Sat, May 02, 2020 at 12:11:43PM +0200, Michael Braun wrote:
> 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.

Applied, thanks.
diff mbox series

Patch

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;
 }