From nobody Wed Dec 17 09:19:39 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1614768360; cv=none; d=zohomail.com; s=zohoarc; b=YOg5waCG8xgO1+F0jOa4Sf/7XxkOBztLoPADKBVJGnefGbMlYKwpM1Wm24LLhLzdUXo2jcC6hOE6dPBmcrwDEUqPtQbatuAk0KR2/eNeS2XBRR3HCni7ZcWySOC/5163YCIdnNLIoE1GVP9///hPW5fCYH5uoF3R5jisAmHEjZs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614768360; 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=MgkPzXTLztIzvy1QLxJnp3+K3vdl2CCv5eHCMA98lCg=; b=ixGhPYe0UHNhPYqUA0oCa3wWLlgc0BxwhthVZFmZce5X43yvQc5OjnqECo87uFclsNCaiofKrABrUc7TOMBOfAFGs7VhribPdQdxZ45ubGGwl42W8QaEqvhlVFMy7E1/IjheUXD2QsbSD38xkuEX1Tj+R26Sey2HBiWItyyuQss= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1614768360110362.21566328167785; Wed, 3 Mar 2021 02:46:00 -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-542-RPt443vWP8-ym9JSX5-iOA-1; Wed, 03 Mar 2021 05:45:56 -0500 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 C0B51189C453; Wed, 3 Mar 2021 10:45:50 +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 8FF8419725; Wed, 3 Mar 2021 10:45: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 31C0E5807B; Wed, 3 Mar 2021 10:45:50 +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 123AjkBP027950 for ; Wed, 3 Mar 2021 05:45:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 74C6A5D74B; Wed, 3 Mar 2021 10:45:46 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id C98485D768 for ; Wed, 3 Mar 2021 10:45:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614768359; 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=MgkPzXTLztIzvy1QLxJnp3+K3vdl2CCv5eHCMA98lCg=; b=HzuLCtgCIEJsS3wMyvPyHNUSrH12ctcjhe2YIDelI4cAf1yCq5zuNLOt1RHoWJVosNgpHc J1sTzQ7SnSzguBDg2DUrOwRyepIEBplcNKuCGLdpOnoVZj8Dlzlnv5ufn6OIorZvGUddhy D888iMX+Dp9TY5ZjB0QdvFmGSVIJZk4= X-MC-Unique: RPt443vWP8-ym9JSX5-iOA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/5] virHostCPUGetStatsLinux: Avoid 'strcpy' Date: Wed, 3 Mar 2021 11:45:36 +0100 Message-Id: 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.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 X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Use an allocated buffer for 'cpu_header' so that g_strdup(_printf) can be used to fill it. Signed-off-by: Peter Krempa --- src/util/virhostcpu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 4f6c3390ce..2446948bc1 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -787,7 +787,7 @@ virHostCPUGetStatsLinux(FILE *procstat, char line[1024]; unsigned long long usr, ni, sys, idle, iowait; unsigned long long irq, softirq, steal, guest, guest_nice; - char cpu_header[4 + VIR_INT64_STR_BUFLEN]; + g_autofree char *cpu_header =3D NULL; if ((*nparams) =3D=3D 0) { /* Current number of cpu stats supported by linux */ @@ -803,9 +803,9 @@ virHostCPUGetStatsLinux(FILE *procstat, } if (cpuNum =3D=3D VIR_NODE_CPU_STATS_ALL_CPUS) { - strcpy(cpu_header, "cpu "); + cpu_header =3D g_strdup("cpu "); } else { - g_snprintf(cpu_header, sizeof(cpu_header), "cpu%d ", cpuNum); + cpu_header =3D g_strdup_printf("cpu%d ", cpuNum); } while (fgets(line, sizeof(line), procstat) !=3D NULL) { --=20 2.29.2