From nobody Tue Apr 30 07:39:21 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 152276513420536.13628947310235; Tue, 3 Apr 2018 07:18:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E8659C058EBC; Tue, 3 Apr 2018 14:18:52 +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 944E67E4D3; Tue, 3 Apr 2018 14:18:52 +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 2ADFF180613A; Tue, 3 Apr 2018 14:18:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w33EIoxq020827 for ; Tue, 3 Apr 2018 10:18:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4DDFF215CDCD; Tue, 3 Apr 2018 14:18:50 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id CBC41215CDC6; Tue, 3 Apr 2018 14:18:49 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 3 Apr 2018 16:18:45 +0200 Message-Id: <728d88cf2fd41d54fc922d81cee38944072e3e06.1522765125.git.pkrempa@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH] tests: utils: Fix out-of-bounds access to memory in virTestCompareToFile 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.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 03 Apr 2018 14:18:53 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Similarly to 3506f1ecfde, the contents of 'cmpcontent' may be an empty string so the following code would access memory out of the array. Signed-off-by: Peter Krempa --- tests/testutils.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testutils.c b/tests/testutils.c index 4bd1b63755..7c095caac9 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -797,10 +797,11 @@ virTestCompareToFile(const char *strcontent, if (filecontent) { size_t filecontentLen =3D strlen(filecontent); + size_t cmpcontentLen =3D strlen(cmpcontent); if (filecontentLen > 0 && filecontent[filecontentLen - 1] =3D=3D '\n' && - cmpcontent[strlen(cmpcontent) - 1] !=3D '\n') { + (cmpcontentLen =3D=3D 0 || cmpcontent[cmpcontentLen - 1] !=3D = '\n')) { if (virAsprintf(&fixedcontent, "%s\n", cmpcontent) < 0) goto failure; cmpcontent =3D fixedcontent; --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list