From nobody Sun Feb 8 08:48:21 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; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1609784475; cv=none; d=zohomail.com; s=zohoarc; b=E4O5l3eB6WWWWB9zkrZfl3ukTsgqhTrJeXTKpFNLZ92Yjek4CfDPMUrx/gosmu0sbdlINHeJaLF+gFRGqHdkZAYegP15010tsVDTkCJhjkVuURhRm+3N/cO2xWqHdC59a0Zk3ePB88NiGVk8e2GYVybVx1tgn2qtsdDt6l+x/Rk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609784475; 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=xFvuYW/upgoOaKqIBMhqo3znGutsS6bH9zsfkkYjTZE=; b=AakDvDKVLCjYRJ587nx58X22rK0GBJmnvfjoV++wwsywaMuL3KkurhtbfzoS7vq8QZvc+pU+w3GeqDQfwboDoh0Wv6DHq7k3c/f7eU8i8m3ZO+23z9msGXk7UL84HgAVOcl8hxwa6eFuyDxDvBvYoDF4+umBSu7Kn588IsmEQ5k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass 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 1609784475891587.8514923071968; Mon, 4 Jan 2021 10:21:15 -0800 (PST) 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-239-AQ_LdD-LMcWbDSjiGEQOOg-1; Mon, 04 Jan 2021 13:21:12 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B2A06180A094; Mon, 4 Jan 2021 18:21:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 925F760C5F; Mon, 4 Jan 2021 18:21:06 +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 5D6A25002F; Mon, 4 Jan 2021 18:21:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 104IKw9E018224 for ; Mon, 4 Jan 2021 13:20:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8E6C65D751; Mon, 4 Jan 2021 18:20:58 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F3505D756 for ; Mon, 4 Jan 2021 18:20:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609784474; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=xFvuYW/upgoOaKqIBMhqo3znGutsS6bH9zsfkkYjTZE=; b=W72UHSOXbEQUUkRoRGP1/4WPabPQmX7Xz3EtATSUJkEAEfzztdwkMdDwzX4NzDslG1Cbql TPEJqg289KW98k+2v5bmfZ5Lz+i7GPpgjwDmJYSxg82tZpTqt4Qt8Y5gxDo00O9g2OOpvm urbgGYEH7eEl5qD9rVYnRW7zjhFo2mE= X-MC-Unique: AQ_LdD-LMcWbDSjiGEQOOg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 5/5] use more virStrcpy() and virStrcpyStatic() Date: Mon, 4 Jan 2021 19:20:45 +0100 Message-Id: <04b4cab2d7de6e09c9f4eefaf03b10daff71f96f.1609784319.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.79 on 10.5.11.12 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 X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" There are a few places where we open code virStrcpy() or virStrcpyStatic(). Call respective functions instead. Signed-off-by: Michal Privoznik --- src/libvirt-lxc.c | 5 ++--- src/remote/remote_driver.c | 12 ++++-------- src/security/security_selinux.c | 3 +-- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/libvirt-lxc.c b/src/libvirt-lxc.c index f6391214be..2a271b74f0 100644 --- a/src/libvirt-lxc.c +++ b/src/libvirt-lxc.c @@ -35,6 +35,7 @@ # include #endif #include "vircgroup.h" +#include "virstring.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 @@ -213,7 +214,7 @@ virDomainLxcEnterSecurityLabel(virSecurityModelPtr mode= l, goto error; } =20 - if (strlen((char *) ctx) >=3D VIR_SECURITY_LABEL_BUFLEN) { + if (virStrcpy(oldlabel->label, ctx, VIR_SECURITY_LABEL_BUFLEN)= < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("security label exceeds " "maximum length: %d"), @@ -221,8 +222,6 @@ virDomainLxcEnterSecurityLabel(virSecurityModelPtr mode= l, freecon(ctx); goto error; } - - strcpy(oldlabel->label, (char *) ctx); freecon(ctx); =20 if ((oldlabel->enforcing =3D security_getenforce()) < 0) { diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index b0af3ee88e..1b784e61c7 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -2328,12 +2328,11 @@ remoteDomainGetSecurityLabel(virDomainPtr domain, v= irSecurityLabelPtr seclabel) } =20 if (ret.label.label_val !=3D NULL) { - if (strlen(ret.label.label_val) >=3D sizeof(seclabel->label)) { + if (virStrcpyStatic(seclabel->label, ret.label.label_val) < 0) { virReportError(VIR_ERR_RPC, _("security label exceeds maximum:= %zu"), sizeof(seclabel->label) - 1); goto cleanup; } - strcpy(seclabel->label, ret.label.label_val); seclabel->enforcing =3D ret.enforcing; } =20 @@ -2372,13 +2371,12 @@ remoteDomainGetSecurityLabelList(virDomainPtr domai= n, virSecurityLabelPtr* secla for (i =3D 0; i < ret.labels.labels_len; i++) { remote_domain_get_security_label_ret *cur =3D &ret.labels.labels_v= al[i]; if (cur->label.label_val !=3D NULL) { - if (strlen(cur->label.label_val) >=3D sizeof((*seclabels)->lab= el)) { + if (virStrcpyStatic((*seclabels)[i].label, cur->label.label_va= l) < 0) { virReportError(VIR_ERR_RPC, _("security label exceeds maxi= mum: %zd"), sizeof((*seclabels)->label) - 1); VIR_FREE(*seclabels); goto cleanup; } - strcpy((*seclabels)[i].label, cur->label.label_val); (*seclabels)[i].enforcing =3D cur->enforcing; } } @@ -2444,21 +2442,19 @@ remoteNodeGetSecurityModel(virConnectPtr conn, virS= ecurityModelPtr secmodel) } =20 if (ret.model.model_val !=3D NULL) { - if (strlen(ret.model.model_val) >=3D sizeof(secmodel->model)) { + if (virStrcpyStatic(secmodel->model, ret.model.model_val) < 0) { virReportError(VIR_ERR_RPC, _("security model exceeds maximum:= %zu"), sizeof(secmodel->model) - 1); goto cleanup; } - strcpy(secmodel->model, ret.model.model_val); } =20 if (ret.doi.doi_val !=3D NULL) { - if (strlen(ret.doi.doi_val) >=3D sizeof(secmodel->doi)) { + if (virStrcpyStatic(secmodel->doi, ret.doi.doi_val) < 0) { virReportError(VIR_ERR_RPC, _("security doi exceeds maximum: %= zu"), sizeof(secmodel->doi) - 1); goto cleanup; } - strcpy(secmodel->doi, ret.doi.doi_val); } =20 rv =3D 0; diff --git a/src/security/security_selinux.c b/src/security/security_selinu= x.c index e9cd95916e..2fc6ef2616 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1209,7 +1209,7 @@ virSecuritySELinuxGetProcessLabel(virSecurityManagerP= tr mgr G_GNUC_UNUSED, return -1; } =20 - if (strlen((char *)ctx) >=3D VIR_SECURITY_LABEL_BUFLEN) { + if (virStrcpy(sec->label, ctx, VIR_SECURITY_LABEL_BUFLEN) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("security label exceeds " "maximum length: %d"), @@ -1218,7 +1218,6 @@ virSecuritySELinuxGetProcessLabel(virSecurityManagerP= tr mgr G_GNUC_UNUSED, return -1; } =20 - strcpy(sec->label, (char *)ctx); freecon(ctx); =20 VIR_DEBUG("label=3D%s", sec->label); --=20 2.26.2