Blame SOURCES/0040-MokManager-avoid-Werror-address-of-packed-member.patch

00e791
From d57e53f3bddc4bc7299b3d5efd5ba8c547e8dfa5 Mon Sep 17 00:00:00 2001
00e791
From: Jonas Witschel <diabonas@gmx.de>
00e791
Date: Thu, 5 Sep 2019 10:39:37 +0200
00e791
Subject: [PATCH 40/62] MokManager: avoid -Werror=address-of-packed-member
00e791
MIME-Version: 1.0
00e791
Content-Type: text/plain; charset=UTF-8
00e791
Content-Transfer-Encoding: 8bit
00e791
00e791
When compiling with GCC 9, there are a couple of errors of the form
00e791
00e791
MokManager.c: In function ‘write_back_mok_list’:
00e791
MokManager.c:1056:19: error: taking address of packed member of ‘struct <anonymous>’ may result in an unaligned pointer value [-Werror=address-of-packed-member]
00e791
 1056 |   if (CompareGuid(&(list[i].Type), &X509_GUID) == 0)
00e791
      |                   ^~~~~~~~~~~~~~~
00e791
00e791
Copying the member of the packed struct to a temporary variable and
00e791
pointing to that variable solves the problem.
00e791
00e791
Upstream-commit-id: 58532e12e9a
00e791
---
00e791
 MokManager.c | 22 +++++++++++++---------
00e791
 1 file changed, 13 insertions(+), 9 deletions(-)
00e791
00e791
diff --git a/MokManager.c b/MokManager.c
00e791
index 78da9fd95ee..fa73e2fd865 100644
00e791
--- a/MokManager.c
00e791
+++ b/MokManager.c
00e791
@@ -1064,6 +1064,7 @@ static EFI_STATUS write_back_mok_list(MokListNode * list, INTN key_num,
00e791
 	EFI_STATUS efi_status;
00e791
 	EFI_SIGNATURE_LIST *CertList;
00e791
 	EFI_SIGNATURE_DATA *CertData;
00e791
+	EFI_GUID type;
00e791
 	void *Data = NULL, *ptr;
00e791
 	INTN DataSize = 0;
00e791
 	int i;
00e791
@@ -1079,8 +1080,8 @@ static EFI_STATUS write_back_mok_list(MokListNode * list, INTN key_num,
00e791
 			continue;
00e791
 
00e791
 		DataSize += sizeof(EFI_SIGNATURE_LIST);
00e791
-		if (CompareMem(&(list[i].Type), &X509_GUID,
00e791
-			       sizeof(EFI_GUID)) == 0)
00e791
+		type = list[i].Type; /* avoid -Werror=address-of-packed-member */
00e791
+		if (CompareGuid(&type, &X509_GUID) == 0)
00e791
 			DataSize += sizeof(EFI_GUID);
00e791
 		DataSize += list[i].MokSize;
00e791
 	}
00e791
@@ -1102,8 +1103,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 (CompareMem(&(list[i].Type), &X509_GUID,
00e791
-			       sizeof(EFI_GUID)) == 0) {
00e791
+		if (CompareGuid(&(CertList->SignatureType), &X509_GUID) == 0) {
00e791
 			CertList->SignatureListSize = list[i].MokSize +
00e791
 			    sizeof(EFI_SIGNATURE_LIST) + sizeof(EFI_GUID);
00e791
 			CertList->SignatureSize =
00e791
@@ -1141,11 +1141,12 @@ static EFI_STATUS write_back_mok_list(MokListNode * list, INTN key_num,
00e791
 static void delete_cert(void *key, UINT32 key_size,
00e791
 			MokListNode * mok, INTN mok_num)
00e791
 {
00e791
+	EFI_GUID type;
00e791
 	int i;
00e791
 
00e791
 	for (i = 0; i < mok_num; i++) {
00e791
-		if (CompareMem(&(mok[i].Type), &X509_GUID,
00e791
-			       sizeof(EFI_GUID)) != 0)
00e791
+		type = mok[i].Type; /* avoid -Werror=address-of-packed-member */
00e791
+		if (CompareGuid(&type, &X509_GUID) != 0)
00e791
 			continue;
00e791
 
00e791
 		if (mok[i].MokSize == key_size &&
00e791
@@ -1187,6 +1188,7 @@ static void mem_move(void *dest, void *src, UINTN size)
00e791
 static void delete_hash_in_list(EFI_GUID Type, UINT8 * hash, UINT32 hash_size,
00e791
 				MokListNode * mok, INTN mok_num)
00e791
 {
00e791
+	EFI_GUID type;
00e791
 	UINT32 sig_size;
00e791
 	UINT32 list_num;
00e791
 	int i, del_ind;
00e791
@@ -1196,7 +1198,8 @@ 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 ((CompareMem(&(mok[i].Type), &Type, sizeof(EFI_GUID)) != 0) ||
00e791
+		type = mok[i].Type; /* avoid -Werror=address-of-packed-member */
00e791
+		if ((CompareGuid(&type, &Type) != 0) ||
00e791
 		    (mok[i].MokSize < sig_size))
00e791
 			continue;
00e791
 
00e791
@@ -1252,6 +1255,7 @@ static void delete_hash_list(EFI_GUID Type, void *hash_list, UINT32 list_size,
00e791
 static EFI_STATUS delete_keys(void *MokDel, UINTN MokDelSize, BOOLEAN MokX)
00e791
 {
00e791
 	EFI_STATUS efi_status;
00e791
+	EFI_GUID type;
00e791
 	CHAR16 *db_name;
00e791
 	CHAR16 *auth_name;
00e791
 	CHAR16 *err_strs[] = { NULL, NULL, NULL };
00e791
@@ -1360,8 +1364,8 @@ 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 (CompareMem(&(del_key[i].Type), &X509_GUID,
00e791
-			       sizeof(EFI_GUID)) == 0) {
00e791
+		type = del_key[i].Type; /* avoid -Werror=address-of-packed-member */
00e791
+		if (CompareGuid(&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