From nobody Tue Dec 16 04:37:02 2025 Delivered-To: importer@patchew.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=1622020588; cv=none; d=zohomail.com; s=zohoarc; b=YJ1FcUYkaRYdoipLwOjLBNll5Rk+/S1SJcFA2I1YLi+lRtQFJx3MM1SALnMC23Ujj5degxnndVOLActZpDH+aZSH45xO6NjIjQE3txsp3SMkV0Du/4NP4OIwlTVLR+RU6882h19jMkXazgl9s6FAnAmt72C633Gtxs1uX1/ELBc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622020588; 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=omTh+2VqrlWG+mA8A8bpUVVby68xoQ90QJPFIO0Jcus=; b=oFA3FA3VIW76aOKbYUA2e0UotDE8ji0KZq8O0eUEnlHFF/CXnn+OkA3xQ7Dn8WFQ69j0SHoxA0REjDcs87H7vzpOHN++/ik6XqQzy+DQ0sNzg4SArdOOlLzPCcd9A5LEd7a6H07BGKh/7EByrYr+ADtZp/jruYCUU0p+LWGdlW8= 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 162202058880363.54748888529514; Wed, 26 May 2021 02:16:28 -0700 (PDT) Received: from localhost ([::1]:43944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llpeM-0006Gu-Rg for importer@patchew.org; Wed, 26 May 2021 05:16:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llpbR-00022x-Mf for qemu-devel@nongnu.org; Wed, 26 May 2021 05:13:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53166) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llpbL-0001Gu-M2 for qemu-devel@nongnu.org; Wed, 26 May 2021 05:13:23 -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-140-reEX55CANoKMdtYsXMjNOQ-1; Wed, 26 May 2021 05:13:15 -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 0351D100945F; Wed, 26 May 2021 09:13:15 +0000 (UTC) Received: from localhost (ovpn-115-80.ams2.redhat.com [10.36.115.80]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81C4F5D75A; Wed, 26 May 2021 09:13:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622020399; 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=omTh+2VqrlWG+mA8A8bpUVVby68xoQ90QJPFIO0Jcus=; b=IDX1LQUXMxihactxa9DUry996n6BTRoZPXUcN2+RYu8+6FoWPilodG4vypCwYE1usbtLKk aVGCVL70MfnxgW1YCEaEc+kKNhu3vHwPLcDY8qFyxTvxEUMr4yiP9WXEyCP8rJze35nPXb 4/xlp/Qcex/YMOARHPwNQn8fsy094zs= X-MC-Unique: reEX55CANoKMdtYsXMjNOQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 3/3] ui/vdagent: fix clipboard info memory leak in error path Date: Wed, 26 May 2021 10:12:48 +0100 Message-Id: <20210526091248.434459-4-stefanha@redhat.com> In-Reply-To: <20210526091248.434459-1-stefanha@redhat.com> References: <20210526091248.434459-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.371, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Laurent Vivier , Kevin Wolf , Thomas Huth , qemu-block@nongnu.org, Coiby Xu , Gerd Hoffmann , Stefan Hajnoczi , Paolo Bonzini 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" If the size of a VD_AGENT_CLIPBOARD_GRAB message is invalid we leak info when returning early. Thanks to Coverity for spotting this: *** CID 1453266: Resource leaks (RESOURCE_LEAK) /qemu/ui/vdagent.c: 465 in vdagent_chr_recv_clipboard() 459 info =3D qemu_clipboard_info_new(&vd->cbpeer, s); 460 if (size > sizeof(uint32_t) * 10) { 461 /* 462 * spice has 6 types as of 2021. Limiting to 10 entries 463 * so we we have some wiggle room. 464 */ >>> CID 1453266: Resource leaks (RESOURCE_LEAK) >>> Variable "info" going out of scope leaks the storage it points to. 465 return; 466 } 467 while (size >=3D sizeof(uint32_t)) { 468 trace_vdagent_cb_grab_type(GET_NAME(type_name, *(uint32= _t *)data)); 469 switch (*(uint32_t *)data) { 470 case VD_AGENT_CLIPBOARD_UTF8_TEXT: Fixes: f0349f4d8947ad32d0fa4678cbf5dbb356fcbda1 ("ui/vdagent: add clipboard= support") Cc: Gerd Hoffmann Signed-off-by: Stefan Hajnoczi Reviewed-by: Gerd Hoffmann --- ui/vdagent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/vdagent.c b/ui/vdagent.c index a253a8fe63..8fc54d330e 100644 --- a/ui/vdagent.c +++ b/ui/vdagent.c @@ -456,7 +456,6 @@ static void vdagent_chr_recv_clipboard(VDAgentChardev *= vd, VDAgentMessage *msg) switch (msg->type) { case VD_AGENT_CLIPBOARD_GRAB: trace_vdagent_cb_grab_selection(GET_NAME(sel_name, s)); - info =3D qemu_clipboard_info_new(&vd->cbpeer, s); if (size > sizeof(uint32_t) * 10) { /* * spice has 6 types as of 2021. Limiting to 10 entries @@ -464,6 +463,7 @@ static void vdagent_chr_recv_clipboard(VDAgentChardev *= vd, VDAgentMessage *msg) */ return; } + info =3D qemu_clipboard_info_new(&vd->cbpeer, s); while (size >=3D sizeof(uint32_t)) { trace_vdagent_cb_grab_type(GET_NAME(type_name, *(uint32_t *)da= ta)); switch (*(uint32_t *)data) { --=20 2.31.1