libkcapi/libkcapi-1.1.1-kcapi-hasher_Fix_off-by-one_error.patch
Ondrej Mosnacek 8d36778e3a Fix off-by-one error in checkfile parsing
Add patch from upstream that fixes a bug that caused FIPS self-check of
hmaccalc binaries on Fedora.
2018-07-11 14:52:19 +02:00

30 lines
955 B
Diff

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