All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, qemu-s390x@nongnu.org,
	qemu-block@nongnu.org, qemu-arm@nongnu.org,
	"Akihiko Odaki" <akihiko.odaki@daynix.com>,
	"Stefan Weil" <sw@weilnetz.de>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PULL 06/46] cutils: Fix get_relocated_path on Windows
Date: Thu, 19 Oct 2023 23:17:31 +0200	[thread overview]
Message-ID: <20231019211814.30576-7-philmd@linaro.org> (raw)
In-Reply-To: <20231019211814.30576-1-philmd@linaro.org>

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



  parent reply	other threads:[~2023-10-19 21:24 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-19 21:17 [PULL 00/46] Misc HW/UI patches for 2023-10-19 Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 01/46] mailmap: update email addresses for Luc Michel Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 02/46] MAINTAINERS: Split vt82c686 out of fuloong2e Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 03/46] MAINTAINERS: Add hw/input/lasips2.c to the HPPA machine section Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 04/46] MAINTAINERS: Add include/hw/intc/loongson_liointc.h to the Loongson-3 virt section Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 05/46] MAINTAINERS: Add include/hw/openrisc/ to the OpenRISC section Philippe Mathieu-Daudé
2023-10-19 21:17 ` Philippe Mathieu-Daudé [this message]
2023-10-19 21:17 ` [PULL 07/46] buildsys: Only display Objective-C information when Objective-C is used Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 08/46] memory: drop needless argument Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 09/46] memory: follow Error API guidelines Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 10/46] hw/sd/sdhci: Block Size Register bits [14:12] is lost Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 11/46] hw/mips/malta: Use sdram_type enum from 'hw/i2c/smbus_eeprom.h' Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 12/46] hw/mips: Merge 'hw/mips/cpudevs.h' with 'target/mips/cpu.h' Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 13/46] hw/misc/mips_itu: Declare itc_reconfigure() in 'hw/misc/mips_itu.h' Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 14/46] hw/misc/mips_itu: Make MIPSITUState target agnostic Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 15/46] hw/pci-host/sh_pcic: Declare CPU QOM types using DEFINE_TYPES() macro Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 16/46] hw/pci-host/sh_pcic: Correct PCI host / devfn#0 function names Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 17/46] hw/pci-host/sh_pcic: Replace magic value by proper definition Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 18/46] hw/sparc64/ebus: Access memory regions via pci_address_space_io() Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 19/46] hw/acpi/pcihp: Clean up global variable shadowing in acpi_pcihp_init() Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 20/46] hw/pci: Clean up global variable shadowing of address_space_io variable Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 21/46] hw/s390x: Clean up global variable shadowing in quiesce_powerdown_req() Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 22/46] hw/intc/apic: Use ERRP_GUARD() in apic_common_realize() Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 23/46] hw/ppc/spapr_vio: Realize SPAPR_VIO_BRIDGE device before accessing it Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 24/46] hw/ppc/pnv_xscom: Rename pnv_xscom_realize(Error **) -> pnv_xscom_init() Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 25/46] hw/ppc/pnv_xscom: Move sysbus_mmio_map() call within pnv_xscom_init() Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 26/46] hw/ppc/pnv_xscom: Do not use SysBus API to map local MMIO region Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 27/46] hw/ppc/pnv: " Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 28/46] hw/intc/spapr_xive: Move sysbus_init_mmio() calls around Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 29/46] hw/intc/spapr_xive: Do not use SysBus API to map local MMIO region Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 30/46] hw/audio/pcspk: Inline pcspk_init() Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 31/46] hw/i386/amd_iommu: Do not use SysBus API to map local MMIO region Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 32/46] hw/i386/intel_iommu: " Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 33/46] hw/misc/allwinner-dramc: Move sysbus_mmio_map call from init -> realize Philippe Mathieu-Daudé
2023-10-19 21:17 ` [PULL 34/46] hw/misc/allwinner-dramc: Do not use SysBus API to map local MMIO region Philippe Mathieu-Daudé
2023-10-19 21:18 ` [PULL 35/46] hw/pci-host/bonito: " Philippe Mathieu-Daudé
2023-10-19 21:18 ` [PULL 36/46] hw/acpi: Realize ACPI_GED sysbus device before accessing it Philippe Mathieu-Daudé
2023-10-19 21:18 ` [PULL 37/46] hw/arm/virt: Realize ARM_GICV2M " Philippe Mathieu-Daudé
2023-10-19 21:18 ` [PULL 38/46] hw/isa: Realize ISA bridge " Philippe Mathieu-Daudé
2023-10-19 21:18 ` [PULL 39/46] hw/s390x/css-bridge: Realize sysbus " Philippe Mathieu-Daudé
2023-10-19 21:18 ` [PULL 40/46] hw/virtio/virtio-pmem: Replace impossible check by assertion Philippe Mathieu-Daudé
2023-10-19 21:18 ` [PULL 41/46] hw/block/vhost-user-blk: Use DEVICE() / VIRTIO_DEVICE() macros Philippe Mathieu-Daudé
2023-10-19 21:18 ` [PULL 42/46] hw/display/virtio-gpu: Use VIRTIO_DEVICE() macro Philippe Mathieu-Daudé
2023-10-19 21:18 ` [PULL 43/46] hw/scsi/virtio-scsi: Use VIRTIO_SCSI_COMMON() macro Philippe Mathieu-Daudé
2023-10-19 21:18 ` [PULL 44/46] hw/dma: Declare link using static DEFINE_PROP_LINK() macro Philippe Mathieu-Daudé
2023-10-19 21:18 ` [PULL 45/46] hw/net: " Philippe Mathieu-Daudé
2023-10-19 21:18 ` [PULL 46/46] ui/input: Constify QemuInputHandler structure Philippe Mathieu-Daudé
2023-10-20 10:04 ` [PULL 00/46] Misc HW/UI patches for 2023-10-19 Philippe Mathieu-Daudé
2023-10-20 16:06 ` Stefan Hajnoczi

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=20231019211814.30576-7-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=akihiko.odaki@daynix.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=sw@weilnetz.de \
    /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.