Skip to contentSkip to conversation

main: fix get_optstring truncating output

PATCH Applied Michael Braun 2 participants 2 messages May 2, 2020 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 main: fix get_optstring truncating output

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.

---
 src/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
src/main.c +3 -1
index d213c601..d830c7a2 100644
@@ -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;
 }
Signature · 1 line
2.20.1
maintainer Applied
#1 lore raw
Quoted 5 lines · Michael Braun

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.