From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1hDoHl-00088R-Rk for mharc-grub-devel@gnu.org; Tue, 09 Apr 2019 06:47:25 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51698) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDoHj-00086J-KN for grub-devel@gnu.org; Tue, 09 Apr 2019 06:47:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hDoHi-0006tI-HP for grub-devel@gnu.org; Tue, 09 Apr 2019 06:47:23 -0400 Received: from smtp2.provo.novell.com ([137.65.250.81]:32819) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hDoHg-0006qR-K0 for grub-devel@gnu.org; Tue, 09 Apr 2019 06:47:22 -0400 Received: from mercury.suse.de (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Tue, 09 Apr 2019 04:47:08 -0600 From: Michael Chang To: grub-devel@gnu.org Subject: [PATCH 8/8] efi: fix gcc9 error address-of-packed-member Date: Tue, 9 Apr 2019 18:46:59 +0800 Message-Id: <20190409104659.4125-9-mchang@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190409104659.4125-1-mchang@suse.com> References: <20190409104659.4125-1-mchang@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 137.65.250.81 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Apr 2019 10:47:24 -0000 Copy the packed member to the buffer returned by grub_malloc, which is supposed to be suitably aligned for any data type, then use it as argument to grub_utf16_to_utf8. The solved gcc9 error like this. [ 255s] ../../grub-core/kern/efi/efi.c: In function 'grub_efi_get_filename': [ 255s] ../../grub-core/kern/efi/efi.c:410:60: error: taking address of packed member of 'struct grub_efi_file_path_device_path' may result in an unaligned pointer value [-Werror=address-of-packed-member] [ 255s] 410 | p = (char *) grub_utf16_to_utf8 ((unsigned char *) p, fp->path_name, len); [ 255s] | ~~^~~~~~~~~~~ [ 255s] ../../grub-core/kern/efi/efi.c: In function 'grub_efi_print_device_path': [ 255s] ../../grub-core/kern/efi/efi.c:900:33: error: taking address of packed member of 'struct grub_efi_file_path_device_path' may result in an unaligned pointer value [-Werror=address-of-packed-member] [ 255s] 900 | *grub_utf16_to_utf8 (buf, fp->path_name, [ 255s] | ~~^~~~~~~~~~~ Signed-off-by: Michael Chang --- grub-core/kern/efi/efi.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c index 708581fcb..62cd9829e 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c @@ -369,6 +369,7 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) { grub_efi_file_path_device_path_t *fp; grub_efi_uint16_t len; + grub_efi_char16_t *dup_name; *p++ = '/'; @@ -379,7 +380,16 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) while (len > 0 && fp->path_name[len - 1] == 0) len--; - p = (char *) grub_utf16_to_utf8 ((unsigned char *) p, fp->path_name, len); + dup_name = grub_malloc (len * sizeof (*dup_name)); + if (!dup_name) + { + grub_free (name); + return NULL; + } + p = (char *) grub_utf16_to_utf8 ((unsigned char *) p, + grub_memcpy (dup_name, fp->path_name, len * sizeof (*dup_name)), + len); + grub_free (dup_name); } dp = GRUB_EFI_NEXT_DEVICE_PATH (dp); @@ -809,9 +819,20 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp) fp = (grub_efi_file_path_device_path_t *) dp; buf = grub_malloc ((len - 4) * 2 + 1); if (buf) - *grub_utf16_to_utf8 (buf, fp->path_name, + { + grub_efi_char16_t *dup_name = grub_malloc (len - 4); + if (!dup_name) + { + grub_errno = GRUB_ERR_NONE; + grub_printf ("/File((null))"); + grub_free (buf); + break; + } + *grub_utf16_to_utf8 (buf, grub_memcpy (dup_name, fp->path_name, len - 4), (len - 4) / sizeof (grub_efi_char16_t)) - = '\0'; + = '\0'; + grub_free (dup_name); + } else grub_errno = GRUB_ERR_NONE; grub_printf ("/File(%s)", buf); -- 2.16.4