From nobody Tue Mar 3 03:04:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1771253623; cv=none; d=zohomail.com; s=zohoarc; b=A7+DGmXioOzm/VhqHDmCGZn2txoP2wOKgzT6/ifegRc7klsh4/tYl2IAgdzMj0DXuLwEk/OniBxuZqNPCpy3JRhrnVTyt0a2NPLV/s3o2USm7+EEN1FHV1WBPLimqbGISjWy1iBwQ47mJl8xyI0SzbdifBR0lVLDLd6Hgp4AX64= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771253623; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=MioaGYhJUzM5qOUFN0NyFlb4my3hO16uNqCATbxY+ws=; b=NFnvt/M5352jmfzBwwhMi2rkFru+WzIV4i/aXz6+j4SNjQP0sFJsXXHoRyyfSN/VAzpUlNDBfo/grgyty1Pbdue3XsCjqtMcFywf7iC1k8/dR8dGee8rYrdaA98OUpLI2JwM9ywxik7sDU+5+lRLSnoWvqEjjbsZFRBta5WVUNs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 177125362341845.016042239287; Mon, 16 Feb 2026 06:53:43 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id A5AFA3F890; Mon, 16 Feb 2026 09:53:42 -0500 (EST) Received: from [172.19.199.9] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id DE4DD418FE; Mon, 16 Feb 2026 09:52:02 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 2C5E63F837; Mon, 16 Feb 2026 09:48:34 -0500 (EST) Received: from mail-dy1-f169.google.com (mail-dy1-f169.google.com [74.125.82.169]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 906BC3F33C for ; Mon, 16 Feb 2026 09:48:33 -0500 (EST) Received: by mail-dy1-f169.google.com with SMTP id 5a478bee46e88-2ba94dbf739so3287284eec.1 for ; Mon, 16 Feb 2026 06:48:33 -0800 (PST) Received: from localhost.localdomain ([2804:29b8:5090:5879:a8a6:8571:534b:ee51]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2bacb543d40sm12131208eec.2.2026.02.16.06.48.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 16 Feb 2026 06:48:31 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771253312; x=1771858112; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=MioaGYhJUzM5qOUFN0NyFlb4my3hO16uNqCATbxY+ws=; b=iPlY9K3oDYkZnwAYjHj3r68iP1dO6fa2SurTxPk669EBXFfyQUfxbe75Aa1KAoBnOU 8tKPcM5vOgQ4tzGU2f6kFZW1LT24mOI6Fppb/824v3j2abTfa/qZc1vfDfQt8YGfZHsQ ouUp3yus0caHP7MyYqseUv4TQBayzIlrBzyu3ek3BCiGEA+fzQ9b2O6xrAFOIvOz27VY XIfY/Rn/0UkbLDHFc0CFn0lGORvLDIyTcBIcOD5gAS/zj45TPv2XLi6U2g/qbRDkw/kB AAVUMEPgrfI5v/r7RlIV9xTEh+F0SwxQUEYzCYKE45/pswR2+Ea+VkkPAAGrv2XK9XrB /zaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771253312; x=1771858112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=MioaGYhJUzM5qOUFN0NyFlb4my3hO16uNqCATbxY+ws=; b=JTUdWaF3c1iO9BJN+6CCJjfuLm2zdpnGP4/w6pKrNFK3dEjdgx7SQQtmXC4MLgdmOR HaMZuw+z2tuvKDZoTHYYUAUdCv3SH+E+TXKIobcYuzrLh4YbU50FVEPVI8gMf/3HtDuT BeiPuZsUmjkNHZ7rXk5XR4SLVM9VGpXKk6d9sLo/LSSwtCTmlB+B02Lk7Rsz3M5djIUG ISN8BXu3XdjrgMZNvZAxEZt9QOndMTPyhlieXbmMIyztuLIGJMwN3pQm/hD/1anPY+Ki 9WaAs2imUyC2tQZerZc2hj585/sh5it6g2QoS0xqZF5b3r8SYgyD0EVuxOoGb+GoitFP k5hg== X-Gm-Message-State: AOJu0Yz6UAwfVkal+VaYdElGGfRpM3UiUxwnSyYeTgydv8VLyhgdb41L lpHkl7ZXbIA4ITm74izPID4bmtNfCUQl8vJNcy9/GWZnAY/Zc9AEHZFSpSKjKA== X-Gm-Gg: AZuq6aIOvtv+qScgr0ed/lwmaTtLDRZjHNyjQg7XVtFGJRwqESI+/oCgEznuUjl/war 6OkUAXNQn0aAA6/w8p/WBdKR5U/He84jVscB+F33dZNOBwO879lKwuuZkZ1WvyO/x+ULGchLS0+ 8BPh3+P+Covwnaqo/04IP7yxaOH9JcIyEyn/5reonb4AUAWgS/J+aCzXQ9KSfYKGALbM+w2VckW UpWV1+w5EgHASV8EPiyRepQVYhWyaOyldWnGCuryl075J2g+9DC1EzBIEwOvHOq3uwIqIPrcUN7 4oRqlZyvqEjdWV/jIAUsdCkDLb0hTAeSyMJp1BrPItJii7O48kWrbNt8PD0c5t0oN3PpJ51gvBc 4tQX/5Ew52qGlWVnhNOarOZU7FRiwUfz6Vh6aJhsS07QEjvemzE52kxFE2OEhg1PcoYQWTyPyxu vSnZ2FvNqEZobOTapiI/hXSt2pGiii/Xnu9zcZErrCKnOLqRaAPMPyJc8Pwcs= X-Received: by 2002:a05:7301:6506:b0:2ba:7b63:3f4f with SMTP id 5a478bee46e88-2babc3c889fmr3761266eec.15.1771253312117; Mon, 16 Feb 2026 06:48:32 -0800 (PST) From: Lucas Amaral To: devel@lists.libvirt.org Subject: [PATCH] virsh: return failure exit code when UUID fetch fails Date: Mon, 16 Feb 2026 11:48:17 -0300 Message-ID: <20260216144818.24599-1-lucaaamaral@gmail.com> X-Mailer: git-send-email 2.52.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-MailFrom: lucaaamaral@gmail.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation Message-ID-Hash: 5ACGDNDOGUYMI7LYRSLH55CMB6PL2IEV X-Message-ID-Hash: 5ACGDNDOGUYMI7LYRSLH55CMB6PL2IEV X-Mailman-Approved-At: Mon, 16 Feb 2026 14:51:58 +0000 CC: Lucas Amaral X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1771253627105154100 The domuuid, net-uuid, and pool-uuid commands call vshError() when GetUUIDString() fails, but unconditionally return true, which vshCommandRun() maps to EXIT_SUCCESS. This means scripts checking $? see success despite the error. Return false on failure so the exit code correctly reflects the error, consistent with other virsh commands. Signed-off-by: Lucas Amaral Reviewed-by: Michal Privoznik --- Found by code audit. The bug dates back to the original cmdDomuuid implementation in d47ddf5b67 (May 2006) and was replicated in cmdNetworkUuid and cmdPoolUuid when those were added later. In practice GetUUIDString() is unlikely to fail from virsh (the UUID is populated during the preceding lookup), so this is a defensive correctness fix rather than a user-visible regression. The restructuring uses the early-return-on-error pattern already used by the adjacent object lookup (e.g., virshCommandOptDomainBy a few lines above). Tested on CentOS Stream 9 =E2=80=94 full test suite passes (307 OK, 1 Expected Fail, 0 Fail). tools/virsh-domain.c | 7 ++++--- tools/virsh-network.c | 7 ++++--- tools/virsh-pool.c | 7 ++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index cb9dd069b6..a7f6a97dd7 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11041,11 +11041,12 @@ cmdDomuuid(vshControl *ctl, const vshCmd *cmd) VIRSH_BYNAME|VIRSH_BYID))) return false; =20 - if (virDomainGetUUIDString(dom, uuid) !=3D -1) - vshPrint(ctl, "%s\n", uuid); - else + if (virDomainGetUUIDString(dom, uuid) =3D=3D -1) { vshError(ctl, "%s", _("failed to get domain UUID")); + return false; + } =20 + vshPrint(ctl, "%s\n", uuid); return true; } =20 diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 2e9613e01b..a725be289f 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -1389,11 +1389,12 @@ cmdNetworkUuid(vshControl *ctl, const vshCmd *cmd) VIRSH_BYNAME))) return false; =20 - if (virNetworkGetUUIDString(network, uuid) !=3D -1) - vshPrint(ctl, "%s\n", uuid); - else + if (virNetworkGetUUIDString(network, uuid) =3D=3D -1) { vshError(ctl, "%s", _("failed to get network UUID")); + return false; + } =20 + vshPrint(ctl, "%s\n", uuid); return true; } =20 diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index 2010ef1356..e06a6cf7c8 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -1720,11 +1720,12 @@ cmdPoolUuid(vshControl *ctl, const vshCmd *cmd) if (!(pool =3D virshCommandOptPoolBy(ctl, cmd, "pool", NULL, VIRSH_BYN= AME))) return false; =20 - if (virStoragePoolGetUUIDString(pool, uuid) !=3D -1) - vshPrint(ctl, "%s\n", uuid); - else + if (virStoragePoolGetUUIDString(pool, uuid) =3D=3D -1) { vshError(ctl, "%s", _("failed to get pool UUID")); + return false; + } =20 + vshPrint(ctl, "%s\n", uuid); return true; } =20 --=20 2.52.0