From nobody Mon Apr 29 16:07:54 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 1511384647743823.400725942859; Wed, 22 Nov 2017 13:04:07 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BAC4683F44; Wed, 22 Nov 2017 21:04:05 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 385E26267C; Wed, 22 Nov 2017 21:04:04 +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 8D8804BB79; Wed, 22 Nov 2017 21:04:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vAML3xFL005541 for ; Wed, 22 Nov 2017 16:03:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6A2355D975; Wed, 22 Nov 2017 21:03:59 +0000 (UTC) Received: from wheatley.localdomain (ovpn-204-77.brq.redhat.com [10.40.204.77]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0D0CC5D973 for ; Wed, 22 Nov 2017 21:03:53 +0000 (UTC) Received: from wheatley.cock.kentus.net (wheatley [127.0.0.1]) by wheatley.localdomain (Postfix) with ESMTP id A381F7E007B for ; Wed, 22 Nov 2017 22:03:51 +0100 (CET) From: Martin Kletzander To: libvir-list@redhat.com Date: Wed, 22 Nov 2017 22:03:50 +0100 Message-Id: <2c81dee1fb447aa3fa3e1298a2ad638fed4e9010.1511384630.git.mkletzan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] util: Fix leak in virStringTrimOptionalNewline 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 22 Nov 2017 21:04:06 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Do not access any data if strlen() =3D=3D 0. Signed-off-by: Martin Kletzander --- src/util/virstring.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/util/virstring.c b/src/util/virstring.c index eac4774b533e..b2ebce27ff49 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -1394,9 +1394,13 @@ virStringEncodeBase64(const uint8_t *buf, size_t buf= len) */ void virStringTrimOptionalNewline(char *str) { - char *tmp =3D str + strlen(str) - 1; - if (*tmp =3D=3D '\n') - *tmp =3D '\0'; + size_t len =3D strlen(str); + + if (!len) + return; + + if (str[len - 1] =3D=3D '\n') + str[len - 1] =3D '\0'; } =20 =20 --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list