From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1hDoHi-00085S-MS for mharc-grub-devel@gnu.org; Tue, 09 Apr 2019 06:47:22 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51638) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hDoHc-0007yt-Ke for grub-devel@gnu.org; Tue, 09 Apr 2019 06:47:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hDoHa-0006n5-MJ for grub-devel@gnu.org; Tue, 09 Apr 2019 06:47:16 -0400 Received: from smtp2.provo.novell.com ([137.65.250.81]:51740) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hDoHZ-0006kr-0K for grub-devel@gnu.org; Tue, 09 Apr 2019 06:47:14 -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 7/8] chainloader: fix gcc9 error address-of-packed-member Date: Tue, 9 Apr 2019 18:46:58 +0800 Message-Id: <20190409104659.4125-8-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:17 -0000 Copy the packed member fp->path_name to the buffer path_name returned by grub_malloc, which is supposed to be suitably aligned for any data type and use path_name as argument to grub_utf8_to_utf16. After the function grub_utf8_to_utf16 returns, copy the content of path_name back to fp->path_name. The solved gcc9 error like this. [ 243s] ../../grub-core/loader/efi/chainloader.c: In function 'copy_file_path': [ 243s] ../../grub-core/loader/efi/chainloader.c:136:32: 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] [ 243s] 136 | size = grub_utf8_to_utf16 (fp->path_name, len * GRUB_MAX_UTF16_PER_UTF8, [ 243s] | ~~^~~~~~~~~~~ [ 243s] ../../grub-core/loader/efi/chainloader.c:138:12: 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] [ 243s] 138 | for (p = fp->path_name; p < fp->path_name + size; p++) [ 243s] | ^~ Signed-off-by: Michael Chang --- grub-core/loader/efi/chainloader.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c index f706b1ac3..cd92ea3f2 100644 --- a/grub-core/loader/efi/chainloader.c +++ b/grub-core/loader/efi/chainloader.c @@ -110,21 +110,27 @@ static void copy_file_path (grub_efi_file_path_device_path_t *fp, const char *str, grub_efi_uint16_t len) { - grub_efi_char16_t *p; + grub_efi_char16_t *p, *path_name; grub_efi_uint16_t size; fp->header.type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE; fp->header.subtype = GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE; - size = grub_utf8_to_utf16 (fp->path_name, len * GRUB_MAX_UTF16_PER_UTF8, + path_name = grub_malloc (len * GRUB_MAX_UTF16_PER_UTF8 * sizeof (*path_name)); + if (!path_name) + return; + + size = grub_utf8_to_utf16 (path_name, len * GRUB_MAX_UTF16_PER_UTF8, (const grub_uint8_t *) str, len, 0); - for (p = fp->path_name; p < fp->path_name + size; p++) + for (p = path_name; p < path_name + size; p++) if (*p == '/') *p = '\\'; + grub_memcpy (fp->path_name, path_name, size * sizeof (*fp->path_name)); /* File Path is NULL terminated */ fp->path_name[size++] = '\0'; fp->header.length = size * sizeof (grub_efi_char16_t) + sizeof (*fp); + grub_free (path_name); } static grub_efi_device_path_t * -- 2.16.4