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

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