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