From nobody Tue May 14 00:00:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1696488481; cv=none; d=zohomail.com; s=zohoarc; b=XxWwaZ2Vyf7m12oIHry0i+T16+E+RqCTCfKnXp1qkCaf8I7D9c3osajQhtNJvajpo85skO/if69ZpRab5GLe16DaBEBqkkF2P0pzhdizkv53IcetV8kzy9xjiAXrFddt1o0V3xZJr8qA/nP7jTMCVjEViqq0pJ+E0WI3W/T3NRc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696488481; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:Message-Id:Reply-To:To; bh=zGHIZ/nFu0V+cvCgaiJjxfj7nZj/2FIabbcqcODY2Bg=; b=dGIXFRGWyZmibR9w3rjUi7pSFKUD8KfQTavaJghAC3R+JseXyRpkvBcQhYeFzbEdBScydS5O3uWWrHh5vMWvX50IfMCDVE9EDNjCXVZ62YI3broqb+XvueCqkEeFXAc6D/Mt6fhGBytJaG3H7ZQYk4SQS2yKrQFOktFYcImPqXo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696488481440355.42076850965054; Wed, 4 Oct 2023 23:48:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qoI9A-0002ia-TT; Thu, 05 Oct 2023 02:47:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qoI97-0002eV-Pa for qemu-devel@nongnu.org; Thu, 05 Oct 2023 02:47:43 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qoI93-0001gb-2s for qemu-devel@nongnu.org; Thu, 05 Oct 2023 02:47:39 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1bf6ea270b2so4299345ad.0 for ; Wed, 04 Oct 2023 23:47:36 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:d54:e521:8bac:7bed]) by smtp.gmail.com with UTF8SMTPSA id jw17-20020a170903279100b001b89466a5f4sm771565plb.105.2023.10.04.23.47.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Oct 2023 23:47:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696488454; x=1697093254; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=zGHIZ/nFu0V+cvCgaiJjxfj7nZj/2FIabbcqcODY2Bg=; b=23zJDARF8Wk+RVNfZTw2bbdB68CKl/TKt0bYNiiNQA9HjqSg0DbaA9Ypn4KUmgolum rcUD4cLih87tOISNUBCDLsFM+siQ3P/D5JINQOvYxw0kjXU3GKjAYYU7EjuYjqC/+o5q 4AdFf/lnb3vlU2xCWJtRAu2JkBI4c7P8BCsnKTQPI7XTKmwHc7/OxY5yuDxrDbpeo6n6 4+FBl4E1ppthyQgbQaQX6J2Mc8hs3m0G+VEsuuXdg3SdVWr0j0jcqiwDkaIzuwVJiIuq wyCPKXUEQjlqgtOefvys4S0gXYVQZTlZ3bfMfm2nktunRWUtNmOK93Ft0pbw3IqiQpVg kJ2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696488454; x=1697093254; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zGHIZ/nFu0V+cvCgaiJjxfj7nZj/2FIabbcqcODY2Bg=; b=cjgKwMx83cZxzFXnqEX4xK3s6JAG+VTXOg55CMU3vh0DaBlSKgCyIbedG8m9UoBFqC u8UFyiNzpC2TEx7sWyNHXccC2yBS1x1a/c57pTTTCskzZ3r239a2Hkz/W5EGmKBu2wDG xTsXzgkhyk88VWsjFeZtvd6E5VCCdG8zKbMfRtViglO2wXOlhWVCQtw7rZA1oC1HPKED KSimiH3ODog0lv2U3f86A8A4P/njGi1p8LJRcQglw49+5attNHJw+s4WvRDZ6peIA4iR K/qMZ7+L+1Na4SbKK89CWppVZGtKhKkR29rjqh9RXV6CSP20ZkQyFt2x8n+f3El0eyg6 bbUQ== X-Gm-Message-State: AOJu0YwOPHYYm+ATrI2EdI9CBEqnM6xorOg0LjzNPPl5nvIu5TAjZW/v vPkW7jv50YPki5vOnR9bEi9KWw== X-Google-Smtp-Source: AGHT+IFq9J3yy2mi4+946+ZctoFhX9fffqcquBAIoVyMXDj4uzgyt71XTgM4cBUCf1+LVpspFtCYKg== X-Received: by 2002:a17:902:db06:b0:1c4:2ca5:8b7c with SMTP id m6-20020a170902db0600b001c42ca58b7cmr4453693plx.61.1696488454679; Wed, 04 Oct 2023 23:47:34 -0700 (PDT) From: Akihiko Odaki To: Cc: Peter Maydell , Jason Wang , qemu-devel , Programmingkid , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Thomas Huth , John Snow , Cleber Rosa , Stefan Weil , Akihiko Odaki , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2] cutils: Fix get_relocated_path on Windows Date: Thu, 5 Oct 2023 15:47:25 +0900 Message-ID: <20231005064726.6945-1-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::632; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x632.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1696488483829100003 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 Signed-off-by: Akihiko Odaki Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- V1 -> V2: Compare against S_OK for clarity (Philippe Mathieu-Daud=C3=A9) util/cutils.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/util/cutils.c b/util/cutils.c index 25373198ad..770d6e023c 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -1155,17 +1155,21 @@ char *get_relocated_path(const char *dir) g_string_append(result, "/qemu-bundle"); if (access(result->str, R_OK) =3D=3D 0) { #ifdef G_OS_WIN32 - size_t size =3D mbsrtowcs(NULL, &dir, 0, &(mbstate_t){0}) + 1; + const char *src =3D dir; + size_t size =3D mbsrtowcs(NULL, &src, 0, &(mbstate_t){0}) + 1; PWSTR wdir =3D g_new(WCHAR, size); - mbsrtowcs(wdir, &dir, size, &(mbstate_t){0}); + mbsrtowcs(wdir, &src, size, &(mbstate_t){0}); =20 PCWSTR wdir_skipped_root; - PathCchSkipRoot(wdir, &wdir_skipped_root); + if (PathCchSkipRoot(wdir, &wdir_skipped_root) =3D=3D S_OK) { + size =3D wcsrtombs(NULL, &wdir_skipped_root, 0, &(mbstate_t){0= }); + char *cursor =3D 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); + } =20 - size =3D wcsrtombs(NULL, &wdir_skipped_root, 0, &(mbstate_t){0}); - char *cursor =3D 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); --=20 2.41.0