From nobody Fri May 17 05:26:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1682763828; cv=none; d=zohomail.com; s=zohoarc; b=IU4im2mwzNFdSnJSr/lv+E5dIPpQ6e3Jd0U8jL7jZRTPIPLC2CmVpC6Pi7MX0MzR5ylZMgildbkTQDbZZgU4uZtb2pfveRX6pAx6z4/rgV1Hfs3j9tLyMAYisLgbb22PbRs6igmH2ZW9q+DQQ4/6x69HTxPY3VmWWBr60nXD3fY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682763828; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=IWAKooGvBdVCecmlIZf3+b8K8g8I/jByv36bz0e5teU=; b=f/vXoxh6ByR0+N3S3GYX2YtXRN2C9f4cjFP1Koqw328skKKxwtZ7RST1rmlBe/2Qm2jSx2+J9GZtlBIUWJDL+QHZIKtzYYj66TeeQoRStB3qemHoEgR/KC+2I+61Lik+eualqkrML/6MgXP8Kwz/wr+XpSVDMBPKy0oPZJ1tEdo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682763828053484.434822881332; Sat, 29 Apr 2023 03:23:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pshjL-0002bD-Ow; Sat, 29 Apr 2023 06:23:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <429af9531f2802072c18c982ceb477db579e2167@lizzy.crudebyte.com>) id 1pshjK-0002b0-TO for qemu-devel@nongnu.org; Sat, 29 Apr 2023 06:23:02 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <429af9531f2802072c18c982ceb477db579e2167@lizzy.crudebyte.com>) id 1pshjJ-00057y-16 for qemu-devel@nongnu.org; Sat, 29 Apr 2023 06:23:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Message-Id:Cc:To:Subject:Date:From:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Content-ID: Content-Description; bh=IWAKooGvBdVCecmlIZf3+b8K8g8I/jByv36bz0e5teU=; b=O37zP EFWPUEgF4S+UgPiMOx1K3pebqSDaa97s3BeMlyxcO5pKP1egL9iwKgHTA+gz8q2zgBsv92C9Ru6tG 9rU+MbdH+G6cBe6v3hFJgS2ViLUWqjdGCuzBQtZRza/p9BoTIFVaSVVBzCQvG3GSN0/vEt6lgkTYB AAwKWef3v63RgmQ10RF8XpdlxgFw0Vy/SY7e/zwf//FuZxLul2ngreVBZyU7yJzp1Besx2xDHhfEf pmkiCJV2VAujX1s0+eGWonHvnD3xz2+pMwYOGfj1oRYvZiiXNzGgADqDXP7AzfFxullZWbMm1fGxg UgM5wAyaMlN+xwcaI9SlyYB+cCuIA==; From: Christian Schoenebeck Date: Sat, 29 Apr 2023 11:25:33 +0200 Subject: [PATCH] tests/9p: fix potential leak in v9fs_rreaddir() To: qemu-devel@nongnu.org Cc: Greg Kurz , Paolo Bonzini Message-Id: 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: none client-ip=91.194.90.13; envelope-from=429af9531f2802072c18c982ceb477db579e2167@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @crudebyte.com) X-ZM-MESSAGEID: 1682763831038100002 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Free allocated directory entries in v9fs_rreaddir() if argument `entries` was passed as NULL, to avoid a memory leak. It is explicitly allowed by design for `entries` to be NULL. [1] [1] https://lore.kernel.org/all/1690923.g4PEXVpXuU@silver Reported-by: Coverity (CID 1487558) Signed-off-by: Christian Schoenebeck Reviewed-by: Greg Kurz --- tests/qtest/libqos/virtio-9p-client.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/qtest/libqos/virtio-9p-client.c b/tests/qtest/libqos/vir= tio-9p-client.c index e4a368e036..b8adc8d4b9 100644 --- a/tests/qtest/libqos/virtio-9p-client.c +++ b/tests/qtest/libqos/virtio-9p-client.c @@ -594,6 +594,8 @@ void v9fs_rreaddir(P9Req *req, uint32_t *count, uint32_= t *nentries, { uint32_t local_count; struct V9fsDirent *e =3D NULL; + /* only used to avoid a leak if entries was NULL */ + struct V9fsDirent *unused_entries =3D NULL; uint16_t slen; uint32_t n =3D 0; =20 @@ -612,6 +614,8 @@ void v9fs_rreaddir(P9Req *req, uint32_t *count, uint32_= t *nentries, e =3D g_new(struct V9fsDirent, 1); if (entries) { *entries =3D e; + } else { + unused_entries =3D e; } } else { e =3D e->next =3D g_new(struct V9fsDirent, 1); @@ -628,6 +632,7 @@ void v9fs_rreaddir(P9Req *req, uint32_t *count, uint32_= t *nentries, *nentries =3D n; } =20 + v9fs_free_dirents(unused_entries); v9fs_req_free(req); } =20 --=20 2.30.2