qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Akihiko Odaki <akihiko.odaki@daynix.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Jason Wang" <jasowang@redhat.com>,
	qemu-devel <qemu-devel@nongnu.org>,
	Programmingkid <programmingkidx@gmail.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Daniel P . Berrangé" <berrange@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Thomas Huth" <thuth@redhat.com>, "John Snow" <jsnow@redhat.com>,
	"Cleber Rosa" <crosa@redhat.com>, "Stefan Weil" <sw@weilnetz.de>
Subject: Re: [PATCH] cutils: Fix get_relocated_path on Windows
Date: Thu, 21 Sep 2023 12:21:29 +0200	[thread overview]
Message-ID: <2d127900-9d75-affb-34fa-2c1b7bc3b44b@linaro.org> (raw)
In-Reply-To: <20221031005908.3393-1-akihiko.odaki@daynix.com>

On 31/10/22 01:59, Akihiko Odaki wrote:
> 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>
> ---
>   util/cutils.c | 18 +++++++++++-------
>   1 file changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/util/cutils.c b/util/cutils.c
> index cb43dda213..932c741d2b 100644
> --- a/util/cutils.c
> +++ b/util/cutils.c
> @@ -1088,17 +1088,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)) {

Maybe for clarity this is the error path:

   if (PathCchSkipRoot(wdir, &wdir_skipped_root) != S_OK) {

Otherwise,

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

> +            g_string_append(result, dir);
> +        } else {
> +            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});
> +        }
>   
> -        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);



      parent reply	other threads:[~2023-09-21 10:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-31  0:59 [PATCH] cutils: Fix get_relocated_path on Windows Akihiko Odaki
2023-09-21  8:10 ` Akihiko Odaki
2023-09-21 10:21 ` Philippe Mathieu-Daudé [this message]

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=2d127900-9d75-affb-34fa-2c1b7bc3b44b@linaro.org \
    --to=philmd@linaro.org \
    --cc=akihiko.odaki@daynix.com \
    --cc=alex.bennee@linaro.org \
    --cc=berrange@redhat.com \
    --cc=crosa@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=jasowang@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=programmingkidx@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sw@weilnetz.de \
    --cc=thuth@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).