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

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