laurenceman / rpms / iptables

Forked from rpms/iptables 5 years ago
Clone

Blame SOURCES/libiptc-NULL-terminate-errorname.patch

9a3fa7
From 9dfd443c3828a3e9a3cf5cf2afb9f0324bacb19a Mon Sep 17 00:00:00 2001
9a3fa7
From: Phil Sutter <psutter@redhat.com>
9a3fa7
Date: Fri, 15 Mar 2019 17:51:28 +0100
9a3fa7
Subject: [PATCH] libiptc: NULL-terminate errorname
9a3fa7
9a3fa7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1525980
9a3fa7
Upstream Status: iptables commit a76ba54e28337
9a3fa7
9a3fa7
commit a76ba54e2833761c46fd57cbe2486cbc38686717
9a3fa7
Author: Phil Sutter <phil@nwl.cc>
9a3fa7
Date:   Mon Sep 24 19:25:22 2018 +0200
9a3fa7
9a3fa7
    libiptc: NULL-terminate errorname
9a3fa7
9a3fa7
    In struct chain_head, field 'name' is of size TABLE_MAXNAMELEN, hence
9a3fa7
    copying its content into 'error_name' field of struct xt_error_target
9a3fa7
    which is two bytes shorter may overflow. Make sure this doesn't happen
9a3fa7
    by using strncpy() and set the last byte to zero.
9a3fa7
9a3fa7
    Signed-off-by: Phil Sutter <phil@nwl.cc>
9a3fa7
    Signed-off-by: Florian Westphal <fw@strlen.de>
9a3fa7
9a3fa7
Signed-off-by: Phil Sutter <psutter@redhat.com>
9a3fa7
---
9a3fa7
 libiptc/libiptc.c | 3 ++-
9a3fa7
 1 file changed, 2 insertions(+), 1 deletion(-)
9a3fa7
9a3fa7
diff --git a/libiptc/libiptc.c b/libiptc/libiptc.c
9a3fa7
index f6a9862ea9f4d..d2427c16a5254 100644
9a3fa7
--- a/libiptc/libiptc.c
9a3fa7
+++ b/libiptc/libiptc.c
9a3fa7
@@ -1149,7 +1149,8 @@ static int iptcc_compile_chain(struct xtc_handle *h, STRUCT_REPLACE *repl, struc
9a3fa7
 		strcpy(head->name.target.u.user.name, ERROR_TARGET);
9a3fa7
 		head->name.target.u.target_size =
9a3fa7
 				ALIGN(sizeof(struct xt_error_target));
9a3fa7
-		strcpy(head->name.errorname, c->name);
9a3fa7
+		strncpy(head->name.errorname, c->name, XT_FUNCTION_MAXNAMELEN);
9a3fa7
+		head->name.errorname[XT_FUNCTION_MAXNAMELEN - 1] = '\0';
9a3fa7
 	} else {
9a3fa7
 		repl->hook_entry[c->hooknum-1] = c->head_offset;
9a3fa7
 		repl->underflow[c->hooknum-1] = c->foot_offset;
9a3fa7
-- 
9a3fa7
2.21.0
9a3fa7