From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [arptables PATCH 2/3] Eliminate compiler warning about size passed to strncmp()
Date: Thu, 21 Nov 2019 12:15:58 +0100 [thread overview]
Message-ID: <20191121111559.27066-3-phil@nwl.cc> (raw)
In-Reply-To: <20191121111559.27066-1-phil@nwl.cc>
Gcc complains about the size being equal to destination size, despite
the nul character being explicitly set in following line.
Reduce size by one to make gcc happy. While being at it, drop the
explicit nul character assignment - it is not needed as the buffer was
allocated by calloc().
Fixes: 8f586939999e0 ("fix potential buffer overflows reported by static analysis")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
arptables.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/arptables.c b/arptables.c
index 09c9ca25217d0..2b6618c2511ef 100644
--- a/arptables.c
+++ b/arptables.c
@@ -2065,8 +2065,7 @@ int do_command(int argc, char *argv[], char **table, arptc_handle_t *handle)
target->t = fw_calloc(1, size);
target->t->u.target_size = size;
- strncpy(target->t->u.user.name, jumpto, sizeof(target->t->u.user.name));
- target->t->u.user.name[sizeof(target->t->u.user.name)-1] = '\0';
+ strncpy(target->t->u.user.name, jumpto, sizeof(target->t->u.user.name) - 1);
target->t->u.user.revision = target->revision;
/*
target->init(target->t, &fw.nfcache);
--
2.24.0
next prev parent reply other threads:[~2019-11-21 11:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-21 11:15 [arptables PATCH 0/3] Some minor fixes Phil Sutter
2019-11-21 11:15 ` [arptables PATCH 1/3] Add .gitignore Phil Sutter
2019-11-21 13:45 ` Pablo Neira Ayuso
2019-11-21 11:15 ` Phil Sutter [this message]
2019-11-21 13:45 ` [arptables PATCH 2/3] Eliminate compiler warning about size passed to strncmp() Pablo Neira Ayuso
2019-11-21 11:15 ` [arptables PATCH 3/3] libarptc: Simplify alloc_handle by using calloc() Phil Sutter
2019-11-21 13:46 ` Pablo Neira Ayuso
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=20191121111559.27066-3-phil@nwl.cc \
--to=phil@nwl.cc \
--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).