Blame SOURCES/0003-mok-consolidate-mirroring-code-in-a-helper-instead-o.patch

12f6e9
From 29c11483101b460869a5e0dba1f425073862127d Mon Sep 17 00:00:00 2001
12f6e9
From: Peter Jones <pjones@redhat.com>
12f6e9
Date: Thu, 31 Jan 2019 13:45:30 -0500
12f6e9
Subject: [PATCH 3/3] mok: consolidate mirroring code in a helper instead of
12f6e9
 using goto
12f6e9
12f6e9
There's no reason to complicate the logic with a goto here, instead just
12f6e9
pull the logic we're jumping to out to a helper function.
12f6e9
12f6e9
Signed-off-by: Peter Jones <pjones@redhat.com>
12f6e9
---
12f6e9
 mok.c  | 41 ++++++++++++++++++++++++++++-------------
12f6e9
 shim.h |  2 ++
12f6e9
 2 files changed, 30 insertions(+), 13 deletions(-)
12f6e9
12f6e9
diff --git a/mok.c b/mok.c
12f6e9
index 41925abbb49..2f495e6cf25 100644
12f6e9
--- a/mok.c
12f6e9
+++ b/mok.c
12f6e9
@@ -130,7 +130,8 @@ struct mok_state_variable mok_state_variables[] = {
12f6e9
 	{ NULL, }
12f6e9
 };
12f6e9
 
12f6e9
-static EFI_STATUS mirror_one_mok_variable(struct mok_state_variable *v)
12f6e9
+static EFI_STATUS nonnull(1)
12f6e9
+mirror_one_mok_variable(struct mok_state_variable *v)
12f6e9
 {
12f6e9
 	EFI_STATUS efi_status = EFI_SUCCESS;
12f6e9
 	void *FullData = NULL;
12f6e9
@@ -196,6 +197,29 @@ static EFI_STATUS mirror_one_mok_variable(struct mok_state_variable *v)
12f6e9
 	return efi_status;
12f6e9
 }
12f6e9
 
12f6e9
+/*
12f6e9
+ * Mirror a variable if it has an rtname, and preserve any
12f6e9
+ * EFI_SECURITY_VIOLATION status at the same time.
12f6e9
+ */
12f6e9
+static EFI_STATUS nonnull(1)
12f6e9
+maybe_mirror_one_mok_variable(struct mok_state_variable *v, EFI_STATUS ret)
12f6e9
+{
12f6e9
+	EFI_STATUS efi_status;
12f6e9
+	if (v->rtname) {
12f6e9
+		if (v->flags & MOK_MIRROR_DELETE_FIRST)
12f6e9
+			LibDeleteVariable(v->rtname, v->guid);
12f6e9
+
12f6e9
+		efi_status = mirror_one_mok_variable(v);
12f6e9
+		if (EFI_ERROR(efi_status)) {
12f6e9
+			if (ret != EFI_SECURITY_VIOLATION)
12f6e9
+				ret = efi_status;
12f6e9
+			perror(L"Could not create %s: %r\n", v->rtname,
12f6e9
+			       efi_status);
12f6e9
+		}
12f6e9
+	}
12f6e9
+	return ret;
12f6e9
+}
12f6e9
+
12f6e9
 /*
12f6e9
  * Verify our non-volatile MoK state.  This checks the variables above
12f6e9
  * accessable and have valid attributes.  If they don't, it removes
12f6e9
@@ -232,7 +256,7 @@ EFI_STATUS import_mok_state(EFI_HANDLE image_handle)
12f6e9
 					       *v->guid, &attrs);
12f6e9
 		if (efi_status == EFI_NOT_FOUND) {
12f6e9
 			if (addend)
12f6e9
-				goto mirror_addend;
12f6e9
+				ret = maybe_mirror_one_mok_variable(v, ret);
12f6e9
 			/*
12f6e9
 			 * after possibly adding, we can continue, no
12f6e9
 			 * further checks to be done.
12f6e9
@@ -312,16 +336,8 @@ EFI_STATUS import_mok_state(EFI_HANDLE image_handle)
12f6e9
 			}
12f6e9
 		}
12f6e9
 
12f6e9
-mirror_addend:
12f6e9
-		if (v->rtname && (present || addend)) {
12f6e9
-			if (v->flags & MOK_MIRROR_DELETE_FIRST)
12f6e9
-				LibDeleteVariable(v->rtname, v->guid);
12f6e9
-
12f6e9
-			efi_status = mirror_one_mok_variable(v);
12f6e9
-			if (EFI_ERROR(efi_status) &&
12f6e9
-			    ret != EFI_SECURITY_VIOLATION)
12f6e9
-				ret = efi_status;
12f6e9
-		}
12f6e9
+		if (present)
12f6e9
+			ret = maybe_mirror_one_mok_variable(v, ret);
12f6e9
 	}
12f6e9
 
12f6e9
 	/*
12f6e9
@@ -340,4 +356,4 @@ mirror_addend:
12f6e9
 	return ret;
12f6e9
 }
12f6e9
 
12f6e9
-// vim:fenc=utf-8:tw=75
12f6e9
+// vim:fenc=utf-8:tw=75:noet
12f6e9
diff --git a/shim.h b/shim.h
12f6e9
index 2b359d821e3..c26d5f06538 100644
12f6e9
--- a/shim.h
12f6e9
+++ b/shim.h
12f6e9
@@ -30,6 +30,8 @@
12f6e9
 
12f6e9
 #include <stddef.h>
12f6e9
 
12f6e9
+#define nonnull(...) __attribute__((__nonnull__(__VA_ARGS__)))
12f6e9
+
12f6e9
 #define min(a, b) ({(a) < (b) ? (a) : (b);})
12f6e9
 
12f6e9
 #ifdef __x86_64__
12f6e9
-- 
12f6e9
2.20.1
12f6e9