Blame SOURCES/0023-extensions-ebt_string-take-action-if-snprintf-discar.patch

05e71a
From 2a33cbf1d286443259093cfb77219fdc60cfb7df Mon Sep 17 00:00:00 2001
05e71a
From: Duncan Roe <duncan_roe@optusnet.com.au>
05e71a
Date: Fri, 15 Jun 2018 11:31:56 +1000
05e71a
Subject: [PATCH] extensions: ebt_string: take action if snprintf discards data
05e71a
05e71a
56993546c805 ("extensions: fix build failure on fc28") eliminated a gcc
05e71a
warning that strncpy could make a string w/out a NUL terminator.
05e71a
snprintf guarantees NUL-termination (so fixes that possibility).  But,
05e71a
snprintf may discard data to make room for the NUL.  This patch errors
05e71a
straight away in that eventuality.
05e71a
05e71a
Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
05e71a
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
05e71a
Signed-off-by: Phil Sutter <psutter@redhat.com>
05e71a
---
05e71a
 extensions/ebt_string.c | 4 +++-
05e71a
 1 file changed, 3 insertions(+), 1 deletion(-)
05e71a
05e71a
diff --git a/extensions/ebt_string.c b/extensions/ebt_string.c
05e71a
index 3deff1ba83264..7d24f8002f4d7 100644
05e71a
--- a/extensions/ebt_string.c
05e71a
+++ b/extensions/ebt_string.c
05e71a
@@ -168,7 +168,9 @@ static int parse(int c, char **argv, int argc, const struct ebt_u_entry *entry,
05e71a
 		ebt_check_option2(flags, OPT_STRING_ALGO);
05e71a
 		if (ebt_check_inverse2(optarg))
05e71a
 			ebt_print_error2("Unexpected `!' after --string-algo");
05e71a
-		snprintf(info->algo, sizeof(info->algo), "%s", optarg);
05e71a
+		if (snprintf(info->algo, sizeof(info->algo), "%s", optarg) >=
05e71a
+				sizeof(info->algo))
05e71a
+			ebt_print_error2("\"%s\" is truncated", info->algo);
05e71a
 		break;
05e71a
 	case STRING_ICASE:
05e71a
 		ebt_check_option2(flags, OPT_STRING_ICASE);
05e71a
-- 
05e71a
2.21.0
05e71a