Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E6763C433FE for ; Wed, 23 Nov 2022 08:06:27 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0773285239; Wed, 23 Nov 2022 09:06:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com 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; unprotected) header.d=gmail.com header.i=@gmail.com header.b="n0C6aC+T"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 097A68521C; Wed, 23 Nov 2022 09:06:24 +0100 (CET) Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 10C5785239 for ; Wed, 23 Nov 2022 09:06:22 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilin.mikhail.ol@gmail.com Received: by mail-lf1-x143.google.com with SMTP id b3so27030874lfv.2 for ; Wed, 23 Nov 2022 00:06:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qOwzWdZA3kKIin2b6ho3mSHFJAxmQoqvByiDMrjIVRA=; b=n0C6aC+TpoBpkM26S/wlxDuvvf7H4NaAsVWYztVe4pLr+U1JntagSMkbNlsBsOTnwG ulhfL513nmcs6Z3ncUERCBa4NpODXNOb/RkTRiya5/0boy06sbwz27QAsl0uXomepOvK pHExrSCdwgPD6HxBjqcxInSFJ5y0+jBVb+/h3xdYDUwKrpix9bZIuLVbE8Z4VTWx+Qnw cH6zqYYBmvd7EPL3ub5cTx4qFJmzhtWD1/H/yHoneFeb/5WOWikBcNOSCEQopDi2Vk4b Bvo6PPffP/F+V9kzW8MlV+iRFLZoDuvQie/FbsNXLvu1zx4SzeicvIx5i1Grt9jqzA2p jSRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qOwzWdZA3kKIin2b6ho3mSHFJAxmQoqvByiDMrjIVRA=; b=6FRuUzGzp9Q9fw7gxqIQoEiAAOZCEk2z5zBNpYZkYMYLdjk2kGNOkXiYtaihCl+ZnS NdlubIEc7g0C6eB2vOEpTOthW0kG+agMhi/ZLeJc+ClNkC3Gd95rqw9wopXGjEUK24q2 FnkFYkBIOWYLlEt1wlTLuvtDpLy2xlDXwWajvgv7VWzuZKoi0RA1VtxpC/Cs1Slnwq7p 6F1lB59L/J840VnNZBODc9Tg0BAcFA1aERu+D80QISY4+1L9DsKwxfRB0MC/T/255XKK I499a2UwsyHD3sSYfNa/Zb1H8RYCS4z+KHrQqQiQ53fTSOUt7hi5AldXXGFR4wTl4R29 4HjQ== X-Gm-Message-State: ANoB5pmFCsBR0fc6W9tCdanhOT5o7n54Mib6Pb0kHva+kZTl/L2gTwQm tqJSagZn9g/4KyQQq2Pi0t+uiGQ1iUQ= X-Google-Smtp-Source: AA0mqf45vN1LSme35n4wpM611QsK6qUB1w/s2Na2YQw2qhJ9VbX4m6p3cNXBDh6hjIXUoc9JRTVyHQ== X-Received: by 2002:ac2:4ec3:0:b0:4a2:3c09:3019 with SMTP id p3-20020ac24ec3000000b004a23c093019mr8552202lfr.90.1669190780912; Wed, 23 Nov 2022 00:06:20 -0800 (PST) Received: from milin-wrk.rasu.local ([178.70.40.200]) by smtp.gmail.com with ESMTPSA id c5-20020a056512324500b004b48cc444ccsm2812360lfr.100.2022.11.23.00.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 00:06:20 -0800 (PST) From: Mikhail Ilin To: u-boot@lists.denx.de Cc: Mikhail Ilin , Stefan Roese , Stephen Warren Subject: [PATCH] fs: ext4: Fix dereferencing the null pointer 'ptr' Date: Wed, 23 Nov 2022 11:06:13 +0300 Message-Id: <20221123080613.15517-1-ilin.mikhail.ol@gmail.com> X-Mailer: git-send-email 2.17.1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.6 at phobos.denx.de X-Virus-Status: Clean If memory allocation fails on line 780, then 'fail' will be jumped to and 'ptr' will be null, causing it to be dereferenced it on line 855. Thus, before using 'ptr[i]' one must make sure that the 'ptr' pointer is not NULL. Fixes: 934b14f2bb30 ("ext4: free allocations by parse_path()") Signed-off-by: Mikhail Ilin --- fs/ext4/ext4_common.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c index 1185cb2c04..3cdd1a04a9 100644 --- a/fs/ext4/ext4_common.c +++ b/fs/ext4/ext4_common.c @@ -851,10 +851,12 @@ end: fail: free(depth_dirname); free(parse_dirname); - for (i = 0; i < depth; i++) { - if (!ptr[i]) - break; - free(ptr[i]); + if (ptr) { + for (i = 0; i < depth; i++) { + if (!ptr[i]) + break; + free(ptr[i]); + } } free(ptr); free(parent_inode); -- 2.17.1