From nobody Sun Apr 28 03:19:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616000532; cv=none; d=zohomail.com; s=zohoarc; b=j228PaaHj9U7xjW/5oJSRKHoPpN5w7eHDxiMDkLjU/eicvbwArT5zTO26QAe5wcM3W1BPUEjQBfeHYmTRFUMPqkgXQKO50Yv9zInZKtiK6CVqr1M6AGblhsf10iGQQapndxp0rVZxg5bg/8BBIBSYIrt3qJe9WzH35VULk8lykA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616000532; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=3VYNcdUVnF6gLn4jc4oG+LGoUE8Z7vXooA60r9gL/yM=; b=lmJZCZbk36+MXSFHnlR7Gfc9nMeu+H1Vi8k6aQvTjAOoZ8AyKQSLI+b8B8/Ig7nU8ACQoGCVPvgt1HtgBg/ech8v956qHQBZFucIYmYO/AODBgqOcqCp8qzoCCxlZn9JGe0thG6z7TENsCjhxrAxEtgxOyb3NH+ChpTNbgQAMmg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1616000532288318.2989950898674; Wed, 17 Mar 2021 10:02:12 -0700 (PDT) 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-460-2Yoi3RjoNMOfYe24YZlqJw-1; Wed, 17 Mar 2021 13:02:07 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id CD8995703A; Wed, 17 Mar 2021 17:02:01 +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 8FB5A5D6A1; Wed, 17 Mar 2021 17:02:00 +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 8FE464BB7C; Wed, 17 Mar 2021 17:01:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 12HH1u5v001249 for ; Wed, 17 Mar 2021 13:01:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id B2A4218A69; Wed, 17 Mar 2021 17:01:56 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.196.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F4B51893C for ; Wed, 17 Mar 2021 17:01:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616000530; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=3VYNcdUVnF6gLn4jc4oG+LGoUE8Z7vXooA60r9gL/yM=; b=JrIhiM7cpNBuweLGWebZoN4GNTw8wQUbvqqaTcwWzCwsDoTo0QyCZsBGoHMbfWdH8CUqL7 YuccOEnUVarusioS2eeo4jxFK/Z6o7rqayF2U20NuThpe+IfGUEb97xZfCIYZ/Tn9Hj4/I GNX4L7YNGoDDE10kJifMezniZzSKyC0= X-MC-Unique: 2Yoi3RjoNMOfYe24YZlqJw-1 From: Kristina Hanicova To: libvir-list@redhat.com Subject: [PATCH] virxml: Fix possible memory leak in virXMLNodeContentString() Date: Wed, 17 Mar 2021 18:01:45 +0100 Message-Id: <10f9b1b29c7d67fe103c335ee876c41d9d9f09e0.1615999363.git.khanicov@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Previously, if xml node passed to the virXMLNodeContentString() was not of type XML_ELEMENT_NODE, @ret could have caused a memory leak because xmlNodeGetContent() works for other types of nodes as well. Signed-off-by: Kristina Hanicova Reviewed-by: Michal Privoznik --- src/util/virxml.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/virxml.c b/src/util/virxml.c index 060b7530fc..4a6fe09468 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -536,7 +536,7 @@ virXMLPropStringLimit(xmlNodePtr node, char * virXMLNodeContentString(xmlNodePtr node) { - char *ret =3D (char *)xmlNodeGetContent(node); + char *ret =3D NULL; =20 if (node->type !=3D XML_ELEMENT_NODE) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -545,6 +545,8 @@ virXMLNodeContentString(xmlNodePtr node) return NULL; } =20 + ret =3D (char *)xmlNodeGetContent(node); + if (!ret) { virReportError(VIR_ERR_INTERNAL_ERROR, _("node '%s' has unexpected NULL content. This coul= d be caused by malformed input, or a memory allocation failure"), --=20 2.29.2