]> git.ipfire.org Git - ipfire-2.x.git/blame - src/patches/efivar-37-compile-fixes-1.patch
Core Update 171: Ship nettle
[ipfire-2.x.git] / src / patches / efivar-37-compile-fixes-1.patch
CommitLineData
d04fb4ee
MT
1From b98ba8921010d03f46704a476c69861515deb1ca Mon Sep 17 00:00:00 2001
2From: Peter Jones <pjones@redhat.com>
3Date: Mon, 7 Jan 2019 10:30:59 -0500
4Subject: [PATCH] dp.h: make format_guid() handle misaligned guid pointers
5 safely.
6
7GCC 9 adds -Werror=address-of-packed-member, which causes us to see the
8build error reported at
9 https://bugzilla.opensuse.org/show_bug.cgi?id=1120862 .
10
11That bug report shows us the following:
12
13In file included from dp.c:26:
14dp.h: In function 'format_vendor_helper':
15dp.h:120:37: error: taking address of packed member of 'struct <anonymous>' may result in an unaligned pointer value [-Werror=address-of-packed-member]
16 120 | format_guid(buf, size, off, label, &dp->hw_vendor.vendor_guid);
17 | ^~~~~~~~~~~~~~~~~~~~~~~~~~
18dp.h:74:25: note: in definition of macro 'format_guid'
19 74 | _rc = efi_guid_to_str(guid, &_guidstr); \
20 | ^~~~
21cc1: all warnings being treated as errors
22
23This patch makes format_guid() use a local variable as a bounce buffer
24in the case that the guid we're passed is aligned as chaotic neutral.
25
26Note that this only fixes this instance and there may be others that bz
27didn't show because it exited too soon, and I don't have a gcc 9 build
28in front of me right now.
29
30Signed-off-by: Peter Jones <pjones@redhat.com>
31---
32 src/dp.h | 11 +++++++++--
33 1 file changed, 9 insertions(+), 2 deletions(-)
34
35diff --git a/src/dp.h b/src/dp.h
36index aa4e390..20cb608 100644
37--- a/src/dp.h
38+++ b/src/dp.h
39@@ -70,8 +70,15 @@
40 #define format_guid(buf, size, off, dp_type, guid) ({ \
41 int _rc; \
42 char *_guidstr = NULL; \
43- \
44- _rc = efi_guid_to_str(guid, &_guidstr); \
45+ efi_guid_t _guid; \
46+ const efi_guid_t * const _guid_p = \
47+ likely(__alignof__(guid) == sizeof(guid)) \
48+ ? guid \
49+ : &_guid; \
50+ \
51+ if (unlikely(__alignof__(guid) == sizeof(guid))) \
52+ memmove(&_guid, guid, sizeof(_guid)); \
53+ _rc = efi_guid_to_str(_guid_p, &_guidstr); \
54 if (_rc < 0) { \
55 efi_error("could not build %s GUID DP string", \
56 dp_type); \