netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org, Etienne <champetier.etienne@gmail.com>
Subject: [iptables PATCH 1/5] libxtables: Fix for warning in xtables_ipmask_to_numeric
Date: Tue, 15 Mar 2022 14:26:15 +0100	[thread overview]
Message-ID: <20220315132619.20256-2-phil@nwl.cc> (raw)
In-Reply-To: <20220315132619.20256-1-phil@nwl.cc>

Gcc complains:

| xtables.c: In function 'xtables_ipmask_to_numeric':
| xtables.c:1491:34: warning: '__builtin___sprintf_chk' may write a terminating nul past the end of the destination [-Wformat-overflow=]
|  1491 |                 sprintf(buf, "/%s", xtables_ipaddr_to_numeric(mask));
|       |                                  ^

Indeed, xtables_ipaddr_to_numeric() returns a pointer to a 20 byte
buffer and xtables_ipmask_to_numeric() writes its content into a buffer
of same size at offset 1. Yet length of returned string is deterministic
as it is an IPv4 address. So shrink it to the minimum of 16 bytes which
eliminates the warning as well.

Fixes: a96166c24eaac ("libxtables: add xtables_ip[6]mask_to_cidr")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 libxtables/xtables.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libxtables/xtables.c b/libxtables/xtables.c
index 094cbd87ec1ed..5f47f627df440 100644
--- a/libxtables/xtables.c
+++ b/libxtables/xtables.c
@@ -1418,7 +1418,7 @@ void xtables_param_act(unsigned int status, const char *p1, ...)
 
 const char *xtables_ipaddr_to_numeric(const struct in_addr *addrp)
 {
-	static char buf[20];
+	static char buf[16];
 	const unsigned char *bytep = (const void *)&addrp->s_addr;
 
 	sprintf(buf, "%u.%u.%u.%u", bytep[0], bytep[1], bytep[2], bytep[3]);
-- 
2.34.1


  reply	other threads:[~2022-03-15 13:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-15 13:26 [iptables PATCH 0/5] Fixes for static builds Phil Sutter
2022-03-15 13:26 ` Phil Sutter [this message]
2022-03-15 13:26 ` [iptables PATCH 2/5] Simplify static build extension loading Phil Sutter
2022-03-15 13:26 ` [iptables PATCH 3/5] xtables: Call init_extensions{,a,b}() for static builds Phil Sutter
2022-03-15 13:50   ` Etienne Champetier
2022-03-15 13:54     ` Phil Sutter
2022-03-15 13:26 ` [iptables PATCH 4/5] nft: Review static extension loading Phil Sutter
2022-03-15 13:26 ` [iptables PATCH 5/5] tests: shell: Fix 0004-return-codes_0 for static builds Phil Sutter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220315132619.20256-2-phil@nwl.cc \
    --to=phil@nwl.cc \
    --cc=champetier.etienne@gmail.com \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).