Blame SOURCES/0002-dp.h-make-format_guid-handle-misaligned-guid-pointer.patch

b15ea1
From b98ba8921010d03f46704a476c69861515deb1ca Mon Sep 17 00:00:00 2001
b15ea1
From: Peter Jones <pjones@redhat.com>
b15ea1
Date: Mon, 7 Jan 2019 10:30:59 -0500
b15ea1
Subject: [PATCH 02/86] dp.h: make format_guid() handle misaligned guid
b15ea1
 pointers safely.
b15ea1
b15ea1
GCC 9 adds -Werror=address-of-packed-member, which causes us to see the
b15ea1
build error reported at
b15ea1
 https://bugzilla.opensuse.org/show_bug.cgi?id=1120862 .
b15ea1
b15ea1
That bug report shows us the following:
b15ea1
b15ea1
In file included from dp.c:26:
b15ea1
dp.h: In function 'format_vendor_helper':
b15ea1
dp.h:120:37: error: taking address of packed member of 'struct <anonymous>' may result in an unaligned pointer value [-Werror=address-of-packed-member]
b15ea1
  120 |  format_guid(buf, size, off, label, &dp->hw_vendor.vendor_guid);
b15ea1
      |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~
b15ea1
dp.h:74:25: note: in definition of macro 'format_guid'
b15ea1
   74 |   _rc = efi_guid_to_str(guid, &_guidstr);   \
b15ea1
      |                         ^~~~
b15ea1
cc1: all warnings being treated as errors
b15ea1
b15ea1
This patch makes format_guid() use a local variable as a bounce buffer
b15ea1
in the case that the guid we're passed is aligned as chaotic neutral.
b15ea1
b15ea1
Note that this only fixes this instance and there may be others that bz
b15ea1
didn't show because it exited too soon, and I don't have a gcc 9 build
b15ea1
in front of me right now.
b15ea1
b15ea1
Signed-off-by: Peter Jones <pjones@redhat.com>
b15ea1
---
b15ea1
 src/dp.h | 11 +++++++++--
b15ea1
 1 file changed, 9 insertions(+), 2 deletions(-)
b15ea1
b15ea1
diff --git a/src/dp.h b/src/dp.h
b15ea1
index aa4e3902992..20cb608d05f 100644
b15ea1
--- a/src/dp.h
b15ea1
+++ b/src/dp.h
b15ea1
@@ -70,8 +70,15 @@
b15ea1
 #define format_guid(buf, size, off, dp_type, guid) ({			\
b15ea1
 		int _rc;						\
b15ea1
 		char *_guidstr = NULL;					\
b15ea1
-									\
b15ea1
-		_rc = efi_guid_to_str(guid, &_guidstr);			\
b15ea1
+		efi_guid_t _guid;					\
b15ea1
+		const efi_guid_t * const _guid_p =			\
b15ea1
+			likely(__alignof__(guid) == sizeof(guid))	\
b15ea1
+				? guid					\
b15ea1
+				: &_guid;				\
b15ea1
+								        \
b15ea1
+		if (unlikely(__alignof__(guid) == sizeof(guid)))	\
b15ea1
+			memmove(&_guid, guid, sizeof(_guid));		\
b15ea1
+		_rc = efi_guid_to_str(_guid_p, &_guidstr);		\
b15ea1
 		if (_rc < 0) {						\
b15ea1
 			efi_error("could not build %s GUID DP string",	\
b15ea1
 				  dp_type);				\
b15ea1
-- 
b15ea1
2.24.1
b15ea1