From nobody Tue Feb 10 08:28:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1622425740; cv=none; d=zohomail.com; s=zohoarc; b=J7Z8yDjy+Mc6RJ8R6UEu8+y4NOVbnq2a0ZkKPUc9cdHhhK4rvIL5A43PdTaFLbsXlvreh7L6AImMmSlI9iX7BOEWrEycH91oDUJ2WaDar8k1Xv0kb5DcThwO5z4Wr4hN82dTXIaIcegvIAP5ljCMBrqIz31Hk5MMYELpWlBHfWs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622425740; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1EBZjwFX9o6a0CDy0lclNb1pM3OXVIhjNebXzFIyYp4=; b=Gdjr9lZXCE6kixPiElwZQsgxLRWDRQtZ0hTCP9P5FZmIVqk7K/72wiKlOXnjVfVT8F2H/td7fb3KB1Ab0uEzrOJ6ES8ITNl9LBgeVWyISWgzApBycJn+DqUdNM+ztcoG85lU7egIQMWSpFf0r1utVjhieTORNGFImeYNH9FOuVg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1622425740292125.92492688804123; Sun, 30 May 2021 18:49:00 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-581-F0ghxXivOcaKhFCq8IFWOg-1; Sun, 30 May 2021 21:48:56 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E5DB7107ACE8; Mon, 31 May 2021 01:48:50 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2B73E2BCCA; Mon, 31 May 2021 01:48:50 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 77E731800FFC; Mon, 31 May 2021 01:48:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14V1mfis007342 for ; Sun, 30 May 2021 21:48:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id A3FE5200D8CC; Mon, 31 May 2021 01:48:41 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9F582200B69D for ; Mon, 31 May 2021 01:48:41 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8876780D0E4 for ; Mon, 31 May 2021 01:48:41 +0000 (UTC) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-151-RwHpU91XNQqi5axaezK3uw-1; Sun, 30 May 2021 21:48:38 -0400 Received: by mail-pf1-f174.google.com with SMTP id d78so7838037pfd.10 for ; Sun, 30 May 2021 18:48:38 -0700 (PDT) Received: from localhost ([103.138.53.238]) by smtp.gmail.com with ESMTPSA id t1sm4384742pfe.61.2021.05.30.18.48.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 May 2021 18:48:36 -0700 (PDT) X-MC-Unique: F0ghxXivOcaKhFCq8IFWOg-1 X-MC-Unique: RwHpU91XNQqi5axaezK3uw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1EBZjwFX9o6a0CDy0lclNb1pM3OXVIhjNebXzFIyYp4=; b=qEPkXjIXuKMGubHOHcbKsnssnFIyezLmnHfMkGDsCGwfG1fFTSOhGyW1UTH8iruSrW KznS8kQ3598Pl/7FyMXup6N6/ksIEjCwXFfCq8hju7Roay1VFB7zsMbW7VGGm4/Y5Jbs T6IBNoRrMyESh5+oqS9Vw8fK1Y6GtKM8ZPazGoooBQ6QJ1Mzk7TBYp6pnS8GPCDGqsMc OrIXNTacsbqsqubEp5LbVC7vzk7d9WVjxjS/1ATax4TBjZr4hfsmgD5AD5uTP+ykv9SZ YGWTb2TYmf4t5XmMrjKcpqNJjSQNPpzGTfORtbA+pvtxmMpesGC11jNe0RDtDpKn++Yt USYQ== X-Gm-Message-State: AOAM530Z3KpZ6hxtqL60vvOEnVoa2sEkKO2BnUXl4vX3ipyQXPKXUYfi Gbj7s3vdfD5tbuwjvnmybbWmJlg04BBjANAm59c= X-Google-Smtp-Source: ABdhPJwj9T+oHkSuBZM3HNHnlfTc3tH8TUnolxUiPo92eu5euqLPWwrNU+Uvq0JGku5GRnrbo+8gBQ== X-Received: by 2002:a63:1316:: with SMTP id i22mr2794126pgl.150.1622425717255; Sun, 30 May 2021 18:48:37 -0700 (PDT) From: Luke Yue To: libvir-list@redhat.com Subject: [PATCH 1/3] virfile: Use g_build_filename() when building paths Date: Mon, 31 May 2021 09:48:22 +0800 Message-Id: <20210531014824.923662-2-lukedyue@gmail.com> In-Reply-To: <20210531014824.923662-1-lukedyue@gmail.com> References: <20210531014824.923662-1-lukedyue@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The g_build_filename() would decide which separator to use instead of hardcoding in g_strdup_printf(). Related issue: https://gitlab.com/libvirt/libvirt/-/issues/12 Signed-off-by: Luke Yue Reviewed-by: Martin Kletzander --- src/util/virfile.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 03a7725dd3..dc2834fd1c 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -733,7 +733,7 @@ static int virFileLoopDeviceOpenSearch(char **dev_name) !g_ascii_isdigit(de->d_name[4])) continue; =20 - looppath =3D g_strdup_printf("/dev/%s", de->d_name); + looppath =3D g_build_filename("/dev", de->d_name, NULL); =20 VIR_DEBUG("Checking up on device %s", looppath); if ((fd =3D open(looppath, O_RDWR)) < 0) { @@ -860,7 +860,7 @@ virFileNBDDeviceIsBusy(const char *dev_name) { g_autofree char *path =3D NULL; =20 - path =3D g_strdup_printf(SYSFS_BLOCK_DIR "/%s/pid", dev_name); + path =3D g_build_filename(SYSFS_BLOCK_DIR, dev_name, "pid", NULL); =20 if (!virFileExists(path)) { if (errno =3D=3D ENOENT) @@ -893,7 +893,7 @@ virFileNBDDeviceFindUnused(void) return NULL; =20 if (rv =3D=3D 0) - return g_strdup_printf("/dev/%s", de->d_name); + return g_build_filename("/dev", de->d_name, NULL); } } if (direrr < 0) @@ -1028,7 +1028,7 @@ int virFileDeleteTree(const char *dir) g_autofree char *filepath =3D NULL; GStatBuf sb; =20 - filepath =3D g_strdup_printf("%s/%s", dir, de->d_name); + filepath =3D g_build_filename(dir, de->d_name, NULL); =20 if (g_lstat(filepath, &sb) < 0) { virReportSystemError(errno, _("Cannot access '%s'"), @@ -1568,7 +1568,7 @@ virFileRelLinkPointsTo(const char *directory, checkLink); return -1; } - candidate =3D g_strdup_printf("%s/%s", directory, checkLink); + candidate =3D g_build_filename(directory, checkLink, NULL); return virFileLinkPointsTo(candidate, checkDest); } =20 @@ -1705,7 +1705,7 @@ virFindFileInPath(const char *file) return NULL; =20 for (pathiter =3D paths; *pathiter; pathiter++) { - g_autofree char *fullpath =3D g_strdup_printf("%s/%s", *pathiter, = file); + g_autofree char *fullpath =3D g_build_filename(*pathiter, file, NU= LL); if (virFileIsExecutable(fullpath)) return g_steal_pointer(&fullpath); } @@ -1754,6 +1754,7 @@ virFileFindResourceFull(const char *filename, char *ret =3D NULL; const char *envval =3D envname ? getenv(envname) : NULL; const char *path; + g_autofree char *fullFilename =3D NULL; =20 if (!prefix) prefix =3D ""; @@ -1767,7 +1768,8 @@ virFileFindResourceFull(const char *filename, else path =3D installdir; =20 - ret =3D g_strdup_printf("%s/%s%s%s", path, prefix, filename, suffix); + fullFilename =3D g_strdup_printf("%s%s%s", prefix, filename, suffix); + ret =3D g_build_filename(path, fullFilename, NULL); =20 VIR_DEBUG("Resolved '%s' to '%s'", filename, ret); return ret; @@ -2986,7 +2988,7 @@ int virFileChownFiles(const char *name, while ((direrr =3D virDirRead(dir, &ent, name)) > 0) { g_autofree char *path =3D NULL; =20 - path =3D g_strdup_printf("%s/%s", name, ent->d_name); + path =3D g_build_filename(name, ent->d_name, NULL); =20 if (!virFileIsRegular(path)) continue; @@ -3048,9 +3050,10 @@ virFileBuildPath(const char *dir, const char *name, = const char *ext) char *path; =20 if (ext =3D=3D NULL) { - path =3D g_strdup_printf("%s/%s", dir, name); + path =3D g_build_filename(dir, name, NULL); } else { - path =3D g_strdup_printf("%s/%s%s", dir, name, ext); + g_autofree char *extName =3D g_strdup_printf("%s%s", name, ext); + path =3D g_build_filename(dir, extName, NULL); } =20 return path; @@ -3158,7 +3161,7 @@ virFileAbsPath(const char *path, char **abspath) } else { g_autofree char *buf =3D g_get_current_dir(); =20 - *abspath =3D g_strdup_printf("%s/%s", buf, path); + *abspath =3D g_build_filename(buf, path, NULL); } =20 return 0; --=20 2.31.1