netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Giuseppe Longo <giuseppelng@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: Giuseppe Longo <giuseppelng@gmail.com>
Subject: [PATCH] nft: arp: fix STRING_OVERFLOW
Date: Sat, 12 Oct 2013 11:21:52 +0200	[thread overview]
Message-ID: <1381569712-7835-1-git-send-email-giuseppelng@gmail.com> (raw)

This patch replace strcat with strncat and strcpy with strncpy
fixing possible string overflow.

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
---
 iptables/nft-arp.c     |    4 ++--
 iptables/xtables-arp.c |    3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/iptables/nft-arp.c b/iptables/nft-arp.c
index 08f8814..9792fda 100644
--- a/iptables/nft-arp.c
+++ b/iptables/nft-arp.c
@@ -459,7 +459,7 @@ nft_arp_print_firewall(struct nft_rule *r, unsigned int num,
 			sprintf(buf, "%s", addr_to_dotted(&(fw.arp.src)));
 		else
 			sprintf(buf, "%s", addr_to_anyname(&(fw.arp.src)));
-		strcat(buf, mask_to_dotted(&(fw.arp.smsk)));
+		strncat(buf, mask_to_dotted(&(fw.arp.smsk)), sizeof(buf) - strlen(buf) -1);
 		printf("-s %s ", buf);
 	}
 
@@ -483,7 +483,7 @@ after_devsrc:
 			sprintf(buf, "%s", addr_to_dotted(&(fw.arp.tgt)));
 		else
 			sprintf(buf, "%s", addr_to_anyname(&(fw.arp.tgt)));
-		strcat(buf, mask_to_dotted(&(fw.arp.tmsk)));
+		strncat(buf, mask_to_dotted(&(fw.arp.tmsk)),  sizeof(buf) - strlen(buf) -1);
 		printf("-d %s ", buf);
 	}
 
diff --git a/iptables/xtables-arp.c b/iptables/xtables-arp.c
index 411a699..18f285c 100644
--- a/iptables/xtables-arp.c
+++ b/iptables/xtables-arp.c
@@ -847,7 +847,8 @@ static struct xtables_target *command_jump(struct arpt_entry *fw,
 
 	target->t = xtables_calloc(1, size);
 	target->t->u.target_size = size;
-	strcpy(target->t->u.user.name, jumpto);
+	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';
 	target->t->u.user.revision = target->revision;
 
 	xs_init_target(target);
-- 
1.7.8.6


             reply	other threads:[~2013-10-12  9:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-12  9:21 Giuseppe Longo [this message]
2013-10-14  6:14 ` [PATCH] nft: arp: fix STRING_OVERFLOW Tomasz Bursztyka
2013-10-17  8:37   ` 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=1381569712-7835-1-git-send-email-giuseppelng@gmail.com \
    --to=giuseppelng@gmail.com \
    --cc=netfilter-devel@vger.kernel.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).