From nobody Sun Feb 8 12:18:52 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1537479330018776.099062273843; Thu, 20 Sep 2018 14:35:30 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 11D36821CC; Thu, 20 Sep 2018 21:35:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C28EA100034A; Thu, 20 Sep 2018 21:35:27 +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 6B927181A12E; Thu, 20 Sep 2018 21:35:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8KLYjrh004515 for ; Thu, 20 Sep 2018 17:34:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 98DD13091385; Thu, 20 Sep 2018 21:34:45 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-55.phx2.redhat.com [10.3.116.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54939309137F for ; Thu, 20 Sep 2018 21:34:45 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Thu, 20 Sep 2018 17:34:38 -0400 Message-Id: <20180920213438.6412-4-jferlan@redhat.com> In-Reply-To: <20180920213438.6412-1-jferlan@redhat.com> References: <20180920213438.6412-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/3] tests: Resolve possible overrun 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 20 Sep 2018 21:35:28 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Coverity noted that each of the fmemopen called used the strlen value in order to allocate space, but that neglected space for terminating null string. So just add 1 to the strlen. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety --- tests/vircgroupmock.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c index d512417789..6587fb3c7e 100644 --- a/tests/vircgroupmock.c +++ b/tests/vircgroupmock.c @@ -466,12 +466,13 @@ FILE *fopen(const char *path, const char *mode) if (STREQ(mode, "r")) { if (allinone) return fmemopen((void *)procmountsallinone, - strlen(procmountsallinone), mode); + strlen(procmountsallinone) + 1, mode); else if (logind) return fmemopen((void *)procmountslogind, - strlen(procmountslogind), mode); + strlen(procmountslogind) + 1, mode); else - return fmemopen((void *)procmounts, strlen(procmounts), mo= de); + return fmemopen((void *)procmounts, + strlen(procmounts) + 1, mode); } else { errno =3D EACCES; return NULL; @@ -481,12 +482,13 @@ FILE *fopen(const char *path, const char *mode) if (STREQ(mode, "r")) { if (allinone) return fmemopen((void *)proccgroupsallinone, - strlen(proccgroupsallinone), mode); + strlen(proccgroupsallinone) + 1, mode); else if (logind) return fmemopen((void *)proccgroupslogind, - strlen(proccgroupslogind), mode); + strlen(proccgroupslogind) + 1, mode); else - return fmemopen((void *)proccgroups, strlen(proccgroups), = mode); + return fmemopen((void *)proccgroups, + strlen(proccgroups) + 1, mode); } else { errno =3D EACCES; return NULL; @@ -496,12 +498,13 @@ FILE *fopen(const char *path, const char *mode) if (STREQ(mode, "r")) { if (allinone) return fmemopen((void *)procselfcgroupsallinone, - strlen(procselfcgroupsallinone), mode); + strlen(procselfcgroupsallinone) + 1, mode); else if (logind) return fmemopen((void *)procselfcgroupslogind, - strlen(procselfcgroupslogind), mode); + strlen(procselfcgroupslogind) + 1, mode); else - return fmemopen((void *)procselfcgroups, strlen(procselfcg= roups), mode); + return fmemopen((void *)procselfcgroups, + strlen(procselfcgroups) + 1, mode); } else { errno =3D EACCES; return NULL; --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list