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