From nobody Sat Nov 23 17:34:14 2024 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=fail; 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=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1723160394; cv=none; d=zohomail.com; s=zohoarc; b=AjDnbxc2qJGm6WIfDkAOkWkhJ0qY7C+Ok2Q8bWusp3HF0+nbhU71THP+jk28URskroJhtu8EG958f1qxtjGhc8/bgh3CZ3rv7lvtyvMUYF6xMtNK0LE6vErjQo9ARym6cs+100rd4lKD4h9fTjC16jw4l3U5SESzTKWY1VsP8Mg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723160394; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=ihwWSk4NCV5MUVhDNFNKechDlxbV23x0wATjLOFUZ04=; b=h0BoyX2/iyFThR+pq7U+tZ20zFxz6wM41bP2Evr3M/t1Qd3vnhmNIG7WR/VjTeBUWA8qMi0vyQqqqhc9fIrUl787qzVIS+dj7YGmM2N0BWf7covrPEHOGpM/ixYocoXYOMOhLoAkZzb7AgdNUDL9ZdGoSak4o+12dDt0vLE5d5U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1723160394156185.12098405556526; Thu, 8 Aug 2024 16:39:54 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 24BF914A6; Thu, 8 Aug 2024 19:39:53 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 3162E13BB; Thu, 8 Aug 2024 19:38:29 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C50F912BD; Thu, 8 Aug 2024 19:38:23 -0400 (EDT) Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 1BAD412BD for ; Thu, 8 Aug 2024 19:38:19 -0400 (EDT) Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2f189a2a7f8so15434681fa.2 for ; Thu, 08 Aug 2024 16:38:19 -0700 (PDT) Received: from localhost ([69.51.98.127]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-39b38bcf37fsm44165755ab.62.2024.08.08.16.38.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 16:38:17 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1723160298; x=1723765098; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mddwPjqHrLFHS2KFN7Yr08edmPUU+prUBiuMEKgL8ZQ=; b=OkDfJ/E7iR1TIrU7mOrQ0KREcyEeFbsi7WDIT8MdkILEjg252dFXC5NCb1bSi37W/V pl9sZY0gUDXE0JjE+W5Ho7as/oXW4o0u7ODV5gLRbDr0OEsLx/PDBP1Tg9iuSt1EH6nA g34q96eQddjx0q3qsZU/7dtjpi6ecmxjk4/nVxjRomhaH5qFwSfQWuqLGRyrb6TZ7Rql UXhlrYZxjKayCw/MN/VAuVjQnAHZWF30HcFMyudzh0r8YsWeALZQdCIzoWd8eOtqk6ru jDBYf1S7/k+l2bVfuLwTKCXfAioEpSq2MJN1OQufHuYTQQrCvNIWZE2fQEDU25AiatfB PUYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723160298; x=1723765098; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mddwPjqHrLFHS2KFN7Yr08edmPUU+prUBiuMEKgL8ZQ=; b=URxXGRrdhAsPTSFcRHxA0aWOAxAE2MahZj0p0f5uf4XQCjvUL613epOaTLtRzTdyvn 6cAgFT/JKS15UqOHClLI/pA4hrBSxjifGos5qPctlrFV0POK4kVNsOR4EMpiYxTVKjBL WEg3YJbxjnoiax9Hbj2dZsaaTngQ2r7EG6M6OOqct4yzor7qILe0y8tc+i/IzVvTP5tn SVoxzbsN5SxklofoNPogWFazMfTOMj7JnwWCllqTpXmA0BWnfDkYUiJ+69ArfNCGnFCc ODW917TnAbUAvkMCpygwqTGYldLhkRHmqD6GiURDBHcEmPaJeaPvsavrFAMY66eVJsay pg6A== X-Gm-Message-State: AOJu0YyOrafQzZQIFgDsgSaZRotu5UCFzQPMb+sBHj93ay/wVH5TNcMm +D2FRuL6VpqnYrqFyg4A3mLj9l80cTQMVfPxKmYAFgOf755DQxf9iHp0OB5GvqdIG/W1nojmnuB s X-Google-Smtp-Source: AGHT+IEUwGoHPANhEDnVx0ZHfbHRr0zPC4rqHZM0NZLoS+wXKSpC8UDf1qOfi1o6zoF/VBpZiuMYPQ== X-Received: by 2002:a2e:9596:0:b0:2ee:974c:596f with SMTP id 38308e7fff4ca-2f19de4927bmr22386321fa.28.1723160297549; Thu, 08 Aug 2024 16:38:17 -0700 (PDT) To: devel@lists.libvirt.org Subject: [PATCH 01/20] lib: virDomainSaveParams: Ensure absolute save path Date: Thu, 8 Aug 2024 17:37:54 -0600 Message-Id: <20240808233813.22905-2-jfehlig@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240808233813.22905-1-jfehlig@suse.com> References: <20240808233813.22905-1-jfehlig@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: P7CZUBUNW5PWUXAXXKEPTFKNCRHHKVGN X-Message-ID-Hash: P7CZUBUNW5PWUXAXXKEPTFKNCRHHKVGN X-MailFrom: jfehlig@suse.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: farosas@suse.de X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Jim Fehlig via Devel Reply-To: Jim Fehlig X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1723160394510116600 Content-Type: text/plain; charset="utf-8" When invoking virDomainSaveParams with a relative path, the image is saved to the daemon's CWD, which in most cases is '/'. Ensure a relative path is converted to absolute before invoking the driver 'domainSaveParams' function. Signed-off-by: Jim Fehlig --- src/libvirt-domain.c | 46 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 7c6b93963c..5aedae1b49 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -1020,6 +1020,11 @@ virDomainSaveParams(virDomainPtr domain, unsigned int flags) { virConnectPtr conn; + virTypedParameterPtr params_copy =3D NULL; + int nparams_copy =3D 0; + const char *to =3D NULL; + g_autofree char *absolute_to =3D NULL; + int ret =3D -1; =20 VIR_DOMAIN_DEBUG(domain, "params=3D%p, nparams=3D%d, flags=3D0x%x", params, nparams, flags); @@ -1030,23 +1035,46 @@ virDomainSaveParams(virDomainPtr domain, virCheckDomainReturn(domain, -1); conn =3D domain->conn; =20 - virCheckReadOnlyGoto(conn->flags, error); + virCheckReadOnlyGoto(conn->flags, done); =20 VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_SAVE_RUNNING, VIR_DOMAIN_SAVE_PAUSED, - error); + done); + + /* We must absolutize the file path as the save is done out of process= */ + virTypedParamsCopy(¶ms_copy, params, nparams); + nparams_copy =3D nparams; + if (virTypedParamsGetString(params_copy, nparams_copy, + VIR_DOMAIN_SAVE_PARAM_FILE, &to) < 0) + goto done; + + if (to) { + if (!(absolute_to =3D g_canonicalize_filename(to, NULL))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("could not build absolute output file path")); + goto done; + } + + if (virTypedParamsReplaceString(¶ms_copy, &nparams_copy, + VIR_DOMAIN_SAVE_PARAM_FILE, + absolute_to) < 0) + goto done; + } =20 if (conn->driver->domainSaveParams) { - if (conn->driver->domainSaveParams(domain, params, nparams, flags)= < 0) - goto error; - return 0; + if (conn->driver->domainSaveParams(domain, params_copy, nparams_co= py, flags) < 0) + goto done; + ret =3D 0; + } else { + virReportUnsupportedError(); } =20 - virReportUnsupportedError(); + done: + if (ret < 0) + virDispatchError(domain->conn); + virTypedParamsFree(params_copy, nparams_copy); =20 - error: - virDispatchError(domain->conn); - return -1; + return ret; } =20 =20 --=20 2.35.3