File shim-bnc863205-mokmanager-fix-hash-delete.patch of Package shim

From 23cdee7b62fc62cd988d74b2180014595da9e4c5 Mon Sep 17 00:00:00 2001
From: Gary Ching-Pang Lin <glin@suse.com>
Date: Thu, 13 Feb 2014 15:05:45 +0800
Subject: [PATCH 1/2] MokManager: calculate the variable size correctly

MokSize of the hash signature list includes the owner GUID,
so we should not add the 16bytes compensation.

Signed-off-by: Gary Ching-Pang Lin <glin@suse.com>
---
 MokManager.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Index: shim-0.7/MokManager.c
===================================================================
--- shim-0.7.orig/MokManager.c
+++ shim-0.7/MokManager.c
@@ -940,7 +940,9 @@ static EFI_STATUS write_back_mok_list (M
 		if (list[i].Mok == NULL)
 			continue;
 
-		DataSize += sizeof(EFI_SIGNATURE_LIST) + sizeof(EFI_GUID);
+		DataSize += sizeof(EFI_SIGNATURE_LIST);
+		if (CompareGuid(&(list[i].Type), &CertType) == 0)
+			DataSize += sizeof(EFI_GUID);
 		DataSize += list[i].MokSize;
 	}
 
@@ -1046,6 +1048,7 @@ static void delete_hash_in_list (UINT8 *
 {
 	EFI_GUID HashType = EFI_CERT_SHA256_GUID;
 	UINT32 sig_size;
+	UINT32 list_num;
 	int i, del_ind;
 	void *start, *end;
 	UINT32 remain;
@@ -1057,8 +1060,10 @@ static void delete_hash_in_list (UINT8 *
 		    (mok[i].MokSize < sig_size))
 			continue;
 
+		list_num = mok[i].MokSize / sig_size;
+
 		del_ind = match_hash(hash, hash_size, 0, mok[i].Mok,
-				     mok[i].MokSize);
+				     list_num);
 		while (del_ind >= 0) {
 			/* Remove the hash */
 			if (sig_size == mok[i].MokSize) {
@@ -1073,9 +1078,10 @@ static void delete_hash_in_list (UINT8 *
 
 			mem_move(start, end, remain);
 			mok[i].MokSize -= sig_size;
+			list_num--;
 
 			del_ind = match_hash(hash, hash_size, del_ind,
-					     mok[i].Mok, mok[i].MokSize);
+					     mok[i].Mok, list_num);
 		}
 	}
 }
openSUSE Build Service is sponsored by