From: Michael Braun Date: Sat, 2 May 2020 10:11:43 +0000 (+0200) Subject: main: fix get_optstring truncating output X-Git-Tag: v0.9.5~29 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e9985b227c38795a80937f430593ff0ca52b37c4;p=thirdparty%2Fnftables.git 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. Fixes: 906facf31d1d ("main: fix ASAN -fsanitize=address error in get_optstring()") Signed-off-by: Michael Braun Signed-off-by: Pablo Neira Ayuso --- 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; }