From nobody Thu May 2 07:22:38 2024 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=1584380016; cv=none; d=zohomail.com; s=zohoarc; b=k1DLF6Mc15hBNmtuGiC0rRT+FR1pxfJHEmHBVnZjT6Cwu6c3FH4/Ds5+vds77d7okPOyyiC5fRHvDjcpL3B9PAKyCG07ke5+J92/8UO1KAaq2QLqDDxQuuSTzjNxrAh5bp9kB+fUXTmKeT9i2kMCiMWB5XwmZP6uj6yKJnzP7qg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584380016; 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=c/usjdqYuVUkky4E7ILH7W1xV57FQXTwQaWgE352H60=; b=WR8CB12oHuPzaVxmNzxh1O0RJPNWik4UdcGL0/4u7JkcE3Kt4yFfQ8TvTwfVCOzfbi1cnI5aOm+LorPVukrOhWSfMtocFnpoitFkaKioq3F3k9aov8s0FJBxBILBXx7BhiodluMvPi3IQ2hWyKx2BRGry+kLdK7EH8pCgYMo1us= 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 1584380016923689.3023990680182; Mon, 16 Mar 2020 10:33:36 -0700 (PDT) Received: from localhost ([::1]:44380 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDtcN-0002Qd-SM for importer@patchew.org; Mon, 16 Mar 2020 13:33:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54017) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDsGp-0004Gr-VC for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:07:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDsGo-00010b-Ix for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:07:15 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:30011) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jDsGo-0000xH-El for qemu-devel@nongnu.org; Mon, 16 Mar 2020 12:07:14 -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-201-P1SWZ1KwMqa-zbcP3GRITQ-1; Mon, 16 Mar 2020 12:07:12 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5418D19389DB; Mon, 16 Mar 2020 16:07:11 +0000 (UTC) Received: from localhost (ovpn-117-61.ams2.redhat.com [10.36.117.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C7188FC16; Mon, 16 Mar 2020 16:07:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584374834; 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=c/usjdqYuVUkky4E7ILH7W1xV57FQXTwQaWgE352H60=; b=Z74fXayibjiETiC6mmFjCF6gh+GFmeN1ZC2+MjQjVwJR0dZb/sj8HHB4yBRYLvTyI/I4wa tN6T4WB+LFZgrkxBH/MapjhZdYPB7XtZbMKOCl7q9AuMJdgQvgSd+RCfE9sJnw3bq35/FG AxRxEuRJ9wfcLoxyOjLhRur8MZR2KAY= X-MC-Unique: P1SWZ1KwMqa-zbcP3GRITQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 1/2] migration: avoid suspicious strncpy() use Date: Mon, 16 Mar 2020 16:07:01 +0000 Message-Id: <20200316160702.478964-2-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.79 on 10.5.11.11 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] [fuzzy] X-Received-From: 216.205.24.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 migration/global_state.o In file included from /usr/include/string.h:495, from /home/stefanha/qemu/include/qemu/osdep.h:101, from migration/global_state.c:13: In function =E2=80=98strncpy=E2=80=99, inlined from =E2=80=98global_state_store_running=E2=80=99 at migratio= n/global_state.c:47:5: /usr/include/bits/string_fortified.h:106:10: error: =E2=80=98__builtin_st= rncpy=E2=80=99 specified bound 100 equals destination size [-Werror=3Dstrin= gop-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 --- migration/global_state.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migration/global_state.c b/migration/global_state.c index 25311479a4..cbe07f21a8 100644 --- a/migration/global_state.c +++ b/migration/global_state.c @@ -44,8 +44,8 @@ void global_state_store_running(void) { const char *state =3D RunState_str(RUN_STATE_RUNNING); assert(strlen(state) < sizeof(global_state.runstate)); - strncpy((char *)global_state.runstate, - state, sizeof(global_state.runstate)); + pstrcpy((char *)global_state.runstate, + sizeof(global_state.runstate), state); } =20 bool global_state_received(void) --=20 2.24.1 From nobody Thu May 2 07:22:38 2024 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