Blame libkcapi-1.1.1-kcapi-hasher_Fix_off-by-one_error.patch

8d36778
From 94c8277dd8fbd2193cb3804c304e965c9238951d Mon Sep 17 00:00:00 2001
8d36778
From: Ondrej Mosnacek <omosnace@redhat.com>
8d36778
Date: Wed, 11 Jul 2018 14:41:14 +0200
8d36778
Subject: [PATCH] kcapi-hasher: Fix off-by-one error
8d36778
8d36778
There was an off-by-one error in process_checkfile() that caused the
8d36778
hasher to misparse checkfiles that contain only the hash (for
8d36778
self-check).
8d36778
---
8d36778
 apps/kcapi-hasher.c | 5 ++++-
8d36778
 1 file changed, 4 insertions(+), 1 deletion(-)
8d36778
8d36778
diff --git a/apps/kcapi-hasher.c b/apps/kcapi-hasher.c
8d36778
index ae88211..00f0373 100644
8d36778
--- a/apps/kcapi-hasher.c
8d36778
+++ b/apps/kcapi-hasher.c
8d36778
@@ -514,8 +514,11 @@ static int process_checkfile(const struct hash_params *params,
8d36778
 		uint32_t i;
8d36778
 		uint32_t bsd_style = 0; // >0 if --tag formatted style
8d36778
 
8d36778
+		if (linelen == 0)
8d36778
+			break;
8d36778
+
8d36778
 		/* remove trailing CR and reduce buffer length */
8d36778
-		for (i = linelen; i > 0; i--) {
8d36778
+		for (i = linelen - 1; i > 0; i--) {
8d36778
 			if (!isprint(buf[i])) {
8d36778
 				buf[i] = '\0';
8d36778
 				linelen--;