Received: from fhigh-b7-smtp.messagingengine.com (fhigh-b7-smtp.messagingengine.com [202.12.124.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 763D53644CA for ; Mon, 10 Aug 2026 06:18:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.158 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786342682; cv=none; b=jPzBXE2CpR5O+gEwU0sRVuhvTSCVYGAWtHr8Vs2t2K/0OVdgp4aI/pc9i/SpRNxcVDaQXWfp94unw8dst80FiE5wEsAJ3vlPtaUBo69pgt0NfXEuY0LdbH2wEzt/KqOlBHSRSNVcsCEoZifT1qAL8yPhprTB112hcnmPlwPZN3Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786342682; c=relaxed/simple; bh=5aVd0th4gCpbleihFCPf7xfKIR83lnt8H7nMs+kNbjE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oLAKwNRbCMHJJrb7EqYuLdGVVDEIqQJZdqeQO3hyStVUCYMhkj+b71s0lAkw2lMLPH2TRizixX9bojfeREvKdRqN3g6KqrHciTuHQDIDmELwRNpP2rlUVPrHcHMiFbJHQrlHpr4W7dV/K7NVcb3KknYr3RkYM0OJUyHC2La2ycY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=SriIVcWj; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=KViY2Gm5; arc=none smtp.client-ip=202.12.124.158 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="SriIVcWj"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="KViY2Gm5" Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfhigh.stl.internal (Postfix) with ESMTP id 91D5A7A01DA; Mon, 10 Aug 2026 02:17:59 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Mon, 10 Aug 2026 02:17:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1786342679; x=1786429079; bh=QGkccLP6rk53CAs5/e/J6YVcbmAVeGLxMwe5nMCYxc8=; b= SriIVcWjLVLxedaMBcoekylmYWyBT/H5IOwbthOHQbz+/0n9rmN2dFxNXFSATRRY SdmQsFt3/izSkhBmmOhhhXKDt4RvstuWC1xR8GKlNHyuWKDYlUWquzM69Wthd3aQ vV9ePM26hsA6Etqaoy9rlppi1EDVp3nmuoW4zwFoMucviPPV/K3SI+8OFYztTN1W f1nMWUFsK/qNheAC9JTrbrZ40ov7YrH8Keihyys5eAeuyHzCq+hG0CJLRywjlLzl vIYqRhSaParAhiHVIPuY/6ujbNfmTp0Z+25GCeEaeH0ku0fZypjbsBwD9NgNUUQt tgz5Z+TSNPnJRNvlpdjxAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1786342679; x= 1786429079; bh=QGkccLP6rk53CAs5/e/J6YVcbmAVeG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DrC7HCz/SI4qizyJiqKMDnTXng X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 10 Aug 2026 02:17:58 -0400 (EDT) Received: by mail (OpenSMTPD) with ESMTPSA id 93010678 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 10 Aug 2026 06:17:55 +0000 (UTC) Date: Mon, 10 Aug 2026 08:17:52 +0200 From: Patrick Steinhardt To: Shlok Kulshreshtha Cc: git@vger.kernel.org, gitster@pobox.com, l.s.r@web.de, Johannes.Schindelin@gmx.de Subject: Re: [PATCH v2] object-name: avoid use-after-free in get_oid_with_context_1() Message-ID: References: <20260808200832.24313-1-diy2903@gmail.com> <20260809194212.77439-1-diy2903@gmail.com> Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260809194212.77439-1-diy2903@gmail.com> On Mon, Aug 10, 2026 at 01:12:09AM +0530, Shlok Kulshreshtha wrote: > diff --git a/object-name.c b/object-name.c > index 83efba0ba6..bffe795830 100644 > --- a/object-name.c > +++ b/object-name.c > @@ -1803,13 +1803,16 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo, > memcmp(ce->name, cp, namelen)) > break; > if (ce_stage(ce) == stage) { > + int ret = -1; > + > + if (!reject_tree_in_index(repo, only_to_die, ce, > + stage, prefix, cp)) { > + oidcpy(oid, &ce->oid); > + oc->mode = ce->ce_mode; > + ret = 0; > + } The function only ever returns `-1` or `0` itself, so we could've written it this way: int ret = reject_tree_in_index(repo, only_to_die, ce, stage, prefix, cp); if (!ret) { oidcpy(oid, &ce->oid); oc->mode = ce->ce_mode; } free(new_path); return ret; But I won't insist on that change, this is already a clear improvement. > diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh > index 4140c4d8ef..e88946c254 100755 > --- a/t/t1092-sparse-checkout-compatibility.sh > +++ b/t/t1092-sparse-checkout-compatibility.sh > @@ -1357,6 +1357,17 @@ do > " > done > > +test_expect_success 'relative path to a sparse directory' ' > + init_repos && > + > + # A "::" argument whose path is relative is resolved > + # into a heap-allocated buffer, and a sparse directory found at that > + # path is reported through it. Cover that combination, so that the > + # reporting does not read the buffer after it has been released. > + test_sparse_match test_must_fail git show :0:./folder1/ && > + test_sparse_match test_must_fail git rev-parse :0:./folder1/ > +' Yup, this test indeed catches the bug: --- sparse-checkout-err 2026-08-10 06:13:59.698011294 +0000 +++ sparse-index-err 2026-08-10 06:13:59.703981906 +0000 @@ -1 +1 @@ -fatal: path 'folder1/' does not exist (neither on disk nor in the index) +fatal: path '�[UU?' does not exist (neither on disk nor in the index) Overall this looks good to me, thanks! Patrick