From 24110b5b8573c141e7fa409ecff9307ee6171a33 Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Fri, 30 Mar 2018 22:11:58 +0200 Subject: libxt_comment: silence truncation warning gcc warned here: libxt_comment.c:62 output may be truncated before the last format character [-Wformat-truncation=] snprintf(comment, XT_MAX_COMMENT_LEN, "\"%s\"" ... It tells us that the '"' might not fit anymore, so increase output buffer size to make room for "" escapes too. Signed-off-by: Florian Westphal --- extensions/libxt_comment.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/extensions/libxt_comment.c b/extensions/libxt_comment.c index b635d16c..69795b6c 100644 --- a/extensions/libxt_comment.c +++ b/extensions/libxt_comment.c @@ -52,17 +52,16 @@ static int comment_xlate(struct xt_xlate *xl, const struct xt_xlate_mt_params *params) { struct xt_comment_info *commentinfo = (void *)params->match->data; - char comment[XT_MAX_COMMENT_LEN]; + char comment[XT_MAX_COMMENT_LEN + sizeof("\\\"\\\"")]; commentinfo->comment[XT_MAX_COMMENT_LEN - 1] = '\0'; if (params->escape_quotes) - snprintf(comment, XT_MAX_COMMENT_LEN, "\\\"%s\\\"", + snprintf(comment, sizeof(comment), "\\\"%s\\\"", commentinfo->comment); else - snprintf(comment, XT_MAX_COMMENT_LEN, "\"%s\"", + snprintf(comment, sizeof(comment), "\"%s\"", commentinfo->comment); - comment[XT_MAX_COMMENT_LEN - 1] = '\0'; xt_xlate_add_comment(xl, comment); return 1; -- cgit v1.2.3