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

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