From nobody Mon Feb 9 12:26:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584380878; cv=none; d=zohomail.com; s=zohoarc; b=S7bLhqbrOFlrDgqApBeAJRD/a2NRIVG5P0t0Wnb7c7OAAbHbfBYDT7caWQ999Ty3FQKYCbhQIvHLNCWVBP2fF341BIjgo9l6qJTszQtrx2pe4DSikYAFZaUW/igy2SBqn3oTxHyeNivO8cb5lbhuCgXs4K5z9nTGjEKOsfYjKw4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584380878; h=Content-Type:Content-Transfer-Encoding:Cc: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=cTgI/nlz6J7xfzMurOKQXZJuFv1H/GjoGqD7EAU+5Dw=; b=R9HvH53oDR0bZvPu1fBPYXDrh7SUUs0rghEBHtS7QlPi/pR9BewMOqApo/4tr1mK6v9uc/6Tu/GP5L06K5UhbK0bhAup5cFYwbdogGbdaGKQEHX8O3m4DayeRjup3KN8ksSNKkOuXszP/t3t+XXR8eSARnSuPBQyXctc3/1BzZY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1584380878640397.75792774242734; Mon, 16 Mar 2020 10:47:58 -0700 (PDT) Received: from localhost ([::1]:44786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDtqH-0004Gn-L0 for importer@patchew.org; Mon, 16 Mar 2020 13:47:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54084) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDsGr-0004IV-Cc for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:07:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDsGq-0001DM-Al for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:07:17 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:44297) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jDsGq-0001Ae-4K for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:07:16 -0400 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-406-ylJWVIKWMhiqWwL0Xr3j3g-1; Mon, 16 Mar 2020 12:07:14 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2F9D8115EF54; Mon, 16 Mar 2020 16:07:13 +0000 (UTC) Received: from localhost (ovpn-117-61.ams2.redhat.com [10.36.117.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id B88A11001B07; Mon, 16 Mar 2020 16:07:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584374835; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cTgI/nlz6J7xfzMurOKQXZJuFv1H/GjoGqD7EAU+5Dw=; b=QPkcbYiTX15B5KbHTuWJeNz2eJ90xqqnyZIvqzux8wB7ISDK5MhJKWwio9bMuaYi25AHKG H1w5nrN6WXFuhKRgNuiuY9CTTzJANNRiAF7orCSWkPdPMlXkbdC2bH6w5w8lLtje64/25Y d1Q5NWxjvNw2Q18HWVzccVm3TrZD294= X-MC-Unique: ylJWVIKWMhiqWwL0Xr3j3g-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 2/2] hw/rdma: avoid suspicious strncpy() use Date: Mon, 16 Mar 2020 16:07:02 +0000 Message-Id: <20200316160702.478964-3-stefanha@redhat.com> In-Reply-To: <20200316160702.478964-1-stefanha@redhat.com> References: <20200316160702.478964-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 63.128.21.74 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Hajnoczi , Yuval Shaia , "Dr. David Alan Gilbert" , Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" gcc (GCC) 9.2.1 20190827 (Red Hat 9.2.1-1) with sanitizers enabled reports the following error: CC x86_64-softmmu/hw/rdma/vmw/pvrdma_dev_ring.o In file included from /usr/include/string.h:495, from include/qemu/osdep.h:101, from hw/rdma/vmw/pvrdma_dev_ring.c:16: In function =E2=80=98strncpy=E2=80=99, inlined from =E2=80=98pvrdma_ring_init=E2=80=99 at hw/rdma/vmw/pvrdma_d= ev_ring.c:33:5: /usr/include/bits/string_fortified.h:106:10: error: =E2=80=98__builtin_strn= cpy=E2=80=99 specified bound 32 equals destination size [-Werror=3Dstringop= -truncation] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__de= st)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~= ~~~~ Use pstrcpy() instead of strncpy(). It is guaranteed to NUL-terminate strings. Signed-off-by: Stefan Hajnoczi Reviewed-by: Juan Quintela Reviewed-by: Yuval Shaia --- hw/rdma/vmw/pvrdma_dev_ring.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/rdma/vmw/pvrdma_dev_ring.c b/hw/rdma/vmw/pvrdma_dev_ring.c index d7bc7f5ccc..74b8fa834c 100644 --- a/hw/rdma/vmw/pvrdma_dev_ring.c +++ b/hw/rdma/vmw/pvrdma_dev_ring.c @@ -14,6 +14,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "hw/pci/pci.h" #include "cpu.h" =20 @@ -30,8 +31,7 @@ int pvrdma_ring_init(PvrdmaRing *ring, const char *name, = PCIDevice *dev, int i; int rc =3D 0; =20 - strncpy(ring->name, name, MAX_RING_NAME_SZ); - ring->name[MAX_RING_NAME_SZ - 1] =3D 0; + pstrcpy(ring->name, MAX_RING_NAME_SZ, name); ring->dev =3D dev; ring->ring_state =3D ring_state; ring->max_elems =3D max_elems; --=20 2.24.1