Blob Blame History Raw
From 2a33cbf1d286443259093cfb77219fdc60cfb7df Mon Sep 17 00:00:00 2001
From: Duncan Roe <duncan_roe@optusnet.com.au>
Date: Fri, 15 Jun 2018 11:31:56 +1000
Subject: [PATCH] extensions: ebt_string: take action if snprintf discards data

56993546c805 ("extensions: fix build failure on fc28") eliminated a gcc
warning that strncpy could make a string w/out a NUL terminator.
snprintf guarantees NUL-termination (so fixes that possibility).  But,
snprintf may discard data to make room for the NUL.  This patch errors
straight away in that eventuality.

Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Phil Sutter <psutter@redhat.com>
---
 extensions/ebt_string.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/extensions/ebt_string.c b/extensions/ebt_string.c
index 3deff1ba83264..7d24f8002f4d7 100644
--- a/extensions/ebt_string.c
+++ b/extensions/ebt_string.c
@@ -168,7 +168,9 @@ static int parse(int c, char **argv, int argc, const struct ebt_u_entry *entry,
 		ebt_check_option2(flags, OPT_STRING_ALGO);
 		if (ebt_check_inverse2(optarg))
 			ebt_print_error2("Unexpected `!' after --string-algo");
-		snprintf(info->algo, sizeof(info->algo), "%s", optarg);
+		if (snprintf(info->algo, sizeof(info->algo), "%s", optarg) >=
+				sizeof(info->algo))
+			ebt_print_error2("\"%s\" is truncated", info->algo);
 		break;
 	case STRING_ICASE:
 		ebt_check_option2(flags, OPT_STRING_ICASE);
-- 
2.21.0