From patchwork Mon Mar 16 16:07:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 1255698 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QPkcbYiT; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48h3fC1fWHz9sP7 for ; Tue, 17 Mar 2020 04:47:15 +1100 (AEDT) Received: from localhost ([::1]:44772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDtpW-0002S8-HN for incoming@patchwork.ozlabs.org; Mon, 16 Mar 2020 13:47:10 -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 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= 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 X-MC-Unique: ylJWVIKWMhiqWwL0Xr3j3g-1 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) 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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 ‘strncpy’, inlined from ‘pvrdma_ring_init’ at hw/rdma/vmw/pvrdma_dev_ring.c:33:5: /usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ specified bound 32 equals destination size [-Werror=stringop-truncation] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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 @@ */ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "hw/pci/pci.h" #include "cpu.h" @@ -30,8 +31,7 @@ int pvrdma_ring_init(PvrdmaRing *ring, const char *name, PCIDevice *dev, int i; int rc = 0; - strncpy(ring->name, name, MAX_RING_NAME_SZ); - ring->name[MAX_RING_NAME_SZ - 1] = 0; + pstrcpy(ring->name, MAX_RING_NAME_SZ, name); ring->dev = dev; ring->ring_state = ring_state; ring->max_elems = max_elems;