[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 06/46] cutils: Fix get_relocated_path on Windows
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 06/46] cutils: Fix get_relocated_path on Windows |
Date: |
Thu, 19 Oct 2023 23:17:31 +0200 |
From: Akihiko Odaki <akihiko.odaki@daynix.com>
get_relocated_path() did not have error handling for PathCchSkipRoot()
because a path given to get_relocated_path() was expected to be a valid
path containing a drive letter or UNC server/share path elements on
Windows, but sometimes it turned out otherwise.
The paths passed to get_relocated_path() are defined by macros generated
by Meson. Meson in turn uses a prefix given by the configure script to
generate them. For Windows, the script passes /qemu as a prefix to
Meson by default.
As documented in docs/about/build-platforms.rst, typically MSYS2 is used
for the build system, but it is also possible to use Linux as well. When
MSYS2 is used, its Bash variant recognizes /qemu as a MSYS2 path, and
converts it to a Windows path, adding the MSYS2 prefix including a drive
letter or UNC server/share path elements. Such a conversion does not
happen on a shell on Linux however, and /qemu will be passed as is in
the case.
Implement a proper error handling of PathCchSkipRoot() in
get_relocated_path() so that it can handle a path without a drive letter
or UNC server/share path elements.
Reported-by: Stefan Weil <sw@weilnetz.de>
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-ID: <20231005064726.6945-1-akihiko.odaki@daynix.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
util/cutils.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/util/cutils.c b/util/cutils.c
index 64f817b477..42364039a5 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -1163,17 +1163,21 @@ char *get_relocated_path(const char *dir)
g_string_append(result, "/qemu-bundle");
if (access(result->str, R_OK) == 0) {
#ifdef G_OS_WIN32
- size_t size = mbsrtowcs(NULL, &dir, 0, &(mbstate_t){0}) + 1;
+ const char *src = dir;
+ size_t size = mbsrtowcs(NULL, &src, 0, &(mbstate_t){0}) + 1;
PWSTR wdir = g_new(WCHAR, size);
- mbsrtowcs(wdir, &dir, size, &(mbstate_t){0});
+ mbsrtowcs(wdir, &src, size, &(mbstate_t){0});
PCWSTR wdir_skipped_root;
- PathCchSkipRoot(wdir, &wdir_skipped_root);
+ if (PathCchSkipRoot(wdir, &wdir_skipped_root) == S_OK) {
+ size = wcsrtombs(NULL, &wdir_skipped_root, 0, &(mbstate_t){0});
+ char *cursor = result->str + result->len;
+ g_string_set_size(result, result->len + size);
+ wcsrtombs(cursor, &wdir_skipped_root, size + 1, &(mbstate_t){0});
+ } else {
+ g_string_append(result, dir);
+ }
- size = wcsrtombs(NULL, &wdir_skipped_root, 0, &(mbstate_t){0});
- char *cursor = result->str + result->len;
- g_string_set_size(result, result->len + size);
- wcsrtombs(cursor, &wdir_skipped_root, size + 1, &(mbstate_t){0});
g_free(wdir);
#else
g_string_append(result, dir);
--
2.41.0
- [PULL 00/46] Misc HW/UI patches for 2023-10-19, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 02/46] MAINTAINERS: Split vt82c686 out of fuloong2e, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 01/46] mailmap: update email addresses for Luc Michel, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 03/46] MAINTAINERS: Add hw/input/lasips2.c to the HPPA machine section, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 04/46] MAINTAINERS: Add include/hw/intc/loongson_liointc.h to the Loongson-3 virt section, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 05/46] MAINTAINERS: Add include/hw/openrisc/ to the OpenRISC section, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 06/46] cutils: Fix get_relocated_path on Windows,
Philippe Mathieu-Daudé <=
- [PULL 07/46] buildsys: Only display Objective-C information when Objective-C is used, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 08/46] memory: drop needless argument, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 09/46] memory: follow Error API guidelines, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 10/46] hw/sd/sdhci: Block Size Register bits [14:12] is lost, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 11/46] hw/mips/malta: Use sdram_type enum from 'hw/i2c/smbus_eeprom.h', Philippe Mathieu-Daudé, 2023/10/19
- [PULL 12/46] hw/mips: Merge 'hw/mips/cpudevs.h' with 'target/mips/cpu.h', Philippe Mathieu-Daudé, 2023/10/19
- [PULL 13/46] hw/misc/mips_itu: Declare itc_reconfigure() in 'hw/misc/mips_itu.h', Philippe Mathieu-Daudé, 2023/10/19
- [PULL 14/46] hw/misc/mips_itu: Make MIPSITUState target agnostic, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 15/46] hw/pci-host/sh_pcic: Declare CPU QOM types using DEFINE_TYPES() macro, Philippe Mathieu-Daudé, 2023/10/19
- [PULL 16/46] hw/pci-host/sh_pcic: Correct PCI host / devfn#0 function names, Philippe Mathieu-Daudé, 2023/10/19