From patchwork Fri Dec 18 14:24:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Genoud X-Patchwork-Id: 1418310 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=posteo.net Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=posteo.net header.i=@posteo.net header.a=rsa-sha256 header.s=2017 header.b=aFKbPZqa; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CyB3N4lQcz9sW8 for ; Sat, 19 Dec 2020 01:25:10 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2D6B582CEC; Fri, 18 Dec 2020 15:25:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=posteo.net Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; secure) header.d=posteo.net header.i=@posteo.net header.b="aFKbPZqa"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A449482CE6; Fri, 18 Dec 2020 15:24:58 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 47ECB82CE6 for ; Fri, 18 Dec 2020 15:24:56 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=posteo.net Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=richard.genoud@posteo.net Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id D4EAE240102 for ; Fri, 18 Dec 2020 15:24:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1608301495; bh=jiJUVEydXTqtz0OrLI1dgpAOI23onSgqX8bPEoi1M8M=; h=From:To:Cc:Subject:Date:From; b=aFKbPZqatQDCNwesxsrCg+tTJuGVfbpycvq5IeDwDrmDcFc5mj5hPeAIoP24YsfAg jIS9EFgj/t6Pd3ZDcaGVd2fkhGa1QwJaZczBDqeZeK8DIzEncSBeY3fT+7bQJ0NnC9 eM2yPbVYBu/yBlzbKLKoz0ybxXZWDdTJqIZuvbiQrjzcFFS8KpZtAUC82t2uJZMk+w o/ELXl/2AAdVEfDj5nZMnSA9CJaTXpwdVXVGBz4eYSVK8LKgpvvFWJT02hK7BPD1yM qP4p+ds8N8JNosejBhUrHN+H0DS+NSzNWI+Ex9eLZ4Mh5h84tYppB0Hkge42eIET6F ur1ttQorzeKnQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4CyB2s717Dz9rxK; Fri, 18 Dec 2020 15:24:53 +0100 (CET) From: Richard Genoud To: Tom Rini Cc: Joao Marcos Costa , Thomas Petazzoni , Miquel Raynal , u-boot@lists.denx.de, Richard Genoud Subject: [PATCH] fs: squasfs: fix a possible NULL pointer dereference in sqfs_opendir() Date: Fri, 18 Dec 2020 15:24:40 +0100 Message-Id: <20201218142440.21783-1-richard.genoud@posteo.net> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean token_count may be != 0 and token_list not yet allocated when the out code is reached Reported-by: Coverity CID 313547 Fixes: ea1b1651c6a8 ("fs/squashfs: sqfs_opendir: simplify error handling") Signed-off-by: Richard Genoud --- fs/squashfs/sqfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c index 608a2bb454c..c47046b76e5 100644 --- a/fs/squashfs/sqfs.c +++ b/fs/squashfs/sqfs.c @@ -949,8 +949,9 @@ int sqfs_opendir(const char *filename, struct fs_dir_stream **dirsp) *dirsp = (struct fs_dir_stream *)dirs; out: - for (j = 0; j < token_count; j++) - free(token_list[j]); + if (token_list) + for (j = 0; j < token_count; j++) + free(token_list[j]); free(token_list); free(pos_list); free(path);