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

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