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

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