From: Michael Chang <mchang@suse.com>
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 [thread overview]
Message-ID: <20190409104659.4125-9-mchang@suse.com> (raw)
In-Reply-To: <20190409104659.4125-1-mchang@suse.com>
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 <mchang@suse.com>
---
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
next prev parent reply other threads:[~2019-04-09 10:47 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-09 10:46 [PATCH 0/8] fix gcc9 build with -Werror=address-of-packed-member Michael Chang
2019-04-09 10:46 ` [PATCH 1/8] cpio: fix gcc9 error address-of-packed-member Michael Chang
2019-04-09 10:46 ` [PATCH 2/8] jfs: " Michael Chang
2019-04-09 10:46 ` [PATCH 3/8] hfs: " Michael Chang
2019-04-09 10:46 ` [PATCH 4/8] hfsplus: " Michael Chang
2019-04-09 10:46 ` [PATCH 5/8] acpi: " Michael Chang
2019-04-09 10:46 ` [PATCH 6/8] usbtest: " Michael Chang
2019-04-09 10:46 ` [PATCH 7/8] chainloader: " Michael Chang
2019-04-09 10:46 ` Michael Chang [this message]
2019-04-09 10:57 ` [PATCH 0/8] fix gcc9 build with -Werror=address-of-packed-member Vladimir 'phcoder' Serbinenko
2019-04-09 11:39 ` Michael Chang
2019-04-09 12:15 ` Vladimir 'phcoder' Serbinenko
2019-04-10 4:41 ` Michael Chang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190409104659.4125-9-mchang@suse.com \
--to=mchang@suse.com \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.