Skip to contentSkip to conversation

nft: arp: fix STRING_OVERFLOW

PATCH In review Giuseppe Longo 3 participants 3 messages Oct 12, 2013 – Oct 17, 2013 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nft: arp: fix STRING_OVERFLOW

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

---
 iptables/nft-arp.c     |    4 ++--
 iptables/xtables-arp.c |    3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)
iptables/nft-arp.c +2 -2
index 08f8814..9792fda 100644
@@ -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);
 	}
 
iptables/xtables-arp.c +2 -1
index 411a699..18f285c 100644
@@ -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);
Signature · 1 line
1.7.8.6
#1 lore raw
Quoted 2 lines · Hi Giuseppe Longo

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

Can you remind in the commit message that this patch is a backport of the patch http://patchwork.ozlabs.org/patch/279672/ ? (I mean: name the original author)

Thanks,

Tomasz
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
Quoted 9 lines · Tomasz Bursztyka
Quoted 2 lines · Hi Giuseppe Longo

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

Can you remind in the commit message that this patch is a backport of the patch http://patchwork.ozlabs.org/patch/279672/ ? (I mean: name the original author)

I have applied this patch including this information.

As Tomasz said. giving credits is a good practise, please do so in the future, and address Tomasz requests otherwise I may discard your patches next time if you don't do so. Thanks.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html