]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxt_comment: silence truncation warning
authorFlorian Westphal <fw@strlen.de>
Fri, 30 Mar 2018 20:11:58 +0000 (22:11 +0200)
committerFlorian Westphal <fw@strlen.de>
Tue, 10 Apr 2018 07:33:39 +0000 (09:33 +0200)
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 <fw@strlen.de>
extensions/libxt_comment.c

index b635d16c5d785b9dc7503014d9cd9b4c2f55c34e..69795b6c6ed5941aaa94fd09ec4bdeaa673d9227 100644 (file)
@@ -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;