Blame SOURCES/0032-Work-around-stuff-Waddress-of-packed-member-finds.patch

00e791
From 2cbf56b82a5102777b37c4f7f47c8cf058cea027 Mon Sep 17 00:00:00 2001
00e791
From: Peter Jones <pjones@redhat.com>
00e791
Date: Mon, 13 May 2019 16:34:35 -0400
00e791
Subject: [PATCH 32/62] Work around stuff -Waddress-of-packed-member finds.
00e791
MIME-Version: 1.0
00e791
Content-Type: text/plain; charset=UTF-8
00e791
Content-Transfer-Encoding: 8bit
00e791
00e791
In MokManager we get a lot of these:
00e791
00e791
../src/MokManager.c:1063:19: error: taking address of packed member of ‘struct <anonymous>’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
00e791
 1063 |   if (CompareGuid(&(list[i].Type), &X509_GUID) == 0)
00e791
      |                   ^~~~~~~~~~~~~~~
00e791
00e791
The reason for this is that gnu-efi takes EFI_GUID * as its argument
00e791
instead of VOID *, and there's nothing telling the compiler that it
00e791
doesn't have alignment constraints on the input, so the compiler wants
00e791
it to have 16-byte alignment.
00e791
00e791
Just use CompareMem() for these, as that's all CompareGuid is calling
00e791
anyway.
00e791
00e791
Signed-off-by: Peter Jones <pjones@redhat.com>
00e791
Upstream-commit-id: 08c14376b59
00e791
---
00e791
 MokManager.c | 12 +++++++-----
00e791
 1 file changed, 7 insertions(+), 5 deletions(-)
00e791
00e791
diff --git a/MokManager.c b/MokManager.c
00e791
index df9b6fe6912..a1bd39a68e2 100644
00e791
--- a/MokManager.c
00e791
+++ b/MokManager.c
00e791
@@ -22,6 +22,8 @@
00e791
 #define CERT_STRING L"Select an X509 certificate to enroll:\n\n"
00e791
 #define HASH_STRING L"Select a file to trust:\n\n"
00e791
 
00e791
+#define CompareMemberGuid(x, y) CompareMem(x, y, sizeof(EFI_GUID))
00e791
+
00e791
 typedef struct {
00e791
 	UINT32 MokSize;
00e791
 	UINT8 *Mok;
00e791
@@ -1077,7 +1079,7 @@ static EFI_STATUS write_back_mok_list(MokListNode * list, INTN key_num,
00e791
 			continue;
00e791
 
00e791
 		DataSize += sizeof(EFI_SIGNATURE_LIST);
00e791
-		if (CompareGuid(&(list[i].Type), &X509_GUID) == 0)
00e791
+		if (CompareMemberGuid(&(list[i].Type), &X509_GUID) == 0)
00e791
 			DataSize += sizeof(EFI_GUID);
00e791
 		DataSize += list[i].MokSize;
00e791
 	}
00e791
@@ -1099,7 +1101,7 @@ static EFI_STATUS write_back_mok_list(MokListNode * list, INTN key_num,
00e791
 		CertList->SignatureType = list[i].Type;
00e791
 		CertList->SignatureHeaderSize = 0;
00e791
 
00e791
-		if (CompareGuid(&(list[i].Type), &X509_GUID) == 0) {
00e791
+		if (CompareMemberGuid(&(list[i].Type), &X509_GUID) == 0) {
00e791
 			CertList->SignatureListSize = list[i].MokSize +
00e791
 			    sizeof(EFI_SIGNATURE_LIST) + sizeof(EFI_GUID);
00e791
 			CertList->SignatureSize =
00e791
@@ -1140,7 +1142,7 @@ static void delete_cert(void *key, UINT32 key_size,
00e791
 	int i;
00e791
 
00e791
 	for (i = 0; i < mok_num; i++) {
00e791
-		if (CompareGuid(&(mok[i].Type), &X509_GUID) != 0)
00e791
+		if (CompareMemberGuid(&(mok[i].Type), &X509_GUID) != 0)
00e791
 			continue;
00e791
 
00e791
 		if (mok[i].MokSize == key_size &&
00e791
@@ -1191,7 +1193,7 @@ static void delete_hash_in_list(EFI_GUID Type, UINT8 * hash, UINT32 hash_size,
00e791
 	sig_size = hash_size + sizeof(EFI_GUID);
00e791
 
00e791
 	for (i = 0; i < mok_num; i++) {
00e791
-		if ((CompareGuid(&(mok[i].Type), &Type) != 0) ||
00e791
+		if ((CompareMemberGuid(&(mok[i].Type), &Type) != 0) ||
00e791
 		    (mok[i].MokSize < sig_size))
00e791
 			continue;
00e791
 
00e791
@@ -1355,7 +1357,7 @@ static EFI_STATUS delete_keys(void *MokDel, UINTN MokDelSize, BOOLEAN MokX)
00e791
 
00e791
 	/* Search and destroy */
00e791
 	for (i = 0; i < del_num; i++) {
00e791
-		if (CompareGuid(&(del_key[i].Type), &X509_GUID) == 0) {
00e791
+		if (CompareMemberGuid(&(del_key[i].Type), &X509_GUID) == 0) {
00e791
 			delete_cert(del_key[i].Mok, del_key[i].MokSize,
00e791
 				    mok, mok_num);
00e791
 		} else if (is_sha2_hash(del_key[i].Type)) {
00e791
-- 
00e791
2.26.2
00e791