From patchwork Mon Jun 3 09:30:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13683412 Received: from wfout4-smtp.messagingengine.com (wfout4-smtp.messagingengine.com [64.147.123.147]) (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 CA7FA129E7D for ; Mon, 3 Jun 2024 09:30:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.147 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717407046; cv=none; b=kZdxYYjxmiXVT0s9a6MvH8cUUm4+lVU86/xP7KbdXXbm4TC1SUGz/ZlhSTN9KTbk/c0K8pfz6upWnvtlpopVutlX8qOhDcESlvzVJZHWNawV0VnacHwCuCyja3kOq3PyTEKHG5y7DryJupjfmY+3sA6TzgZ/4QCGtBBhYBxd/mc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717407046; c=relaxed/simple; bh=HAbBGoCrTzLWDSoHqrUwgvdIMpihJiEoSKiCW5NBj30=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EggYn079OaeR4ryM0HBwUGi8KnvVmuu6naq8cLCV4fP/WjYMh8vtoZ2t9gRIaCWI7Fb5SCpx258FCO65nyUYIla/F4kVuALotpYMtxRGrgcwjH5scFlNs1QDSL5JiKQvVDWcj3ZYoSufqf+l3qDuBjrVYeF3QLewqMRCP9uIpPU= 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=CXaYhWLo; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ffqiwkSX; arc=none smtp.client-ip=64.147.123.147 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="CXaYhWLo"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ffqiwkSX" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.west.internal (Postfix) with ESMTP id ECD731C000F1; Mon, 3 Jun 2024 05:30:43 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 03 Jun 2024 05:30:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :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=fm1; t=1717407043; x=1717493443; bh=+VIjeN12Vf CYsi6OQMnmB6s76PVdeppv5DUg8dZperI=; b=CXaYhWLo3OFTJOwoYzYmAUgdL6 3rWzLUXzsPMoK2D2x6QBYtTFMlJCWU852KHmDMLIId+DTxrcoB+mLJv+0OunX9lO Y+matSCISrQzES9MRR59senfh3lOX0GO0rqcC0q2fe9dAnVL4mMxVAmi9wJVNwx3 GVuJuBTzJaIJ7nfJeQoNOD7gPhRNXjdfdJ+93JpqdyWH6eYss5W/7BAgymtGfAkm 0jgPk4tdXSG/2M4qB0kuaSnIEtKy6Hxk39HVtZsEFZsJ54gJ6QOVrWKEh0sPDDm2 fc2/z2WFb+02fkQfMWGRTVfkFJ/rqJoIqiP9ClJ/JJBdK7kpcB3gGMeCAyqg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc: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-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1717407043; x=1717493443; bh=+VIjeN12VfCYsi6OQMnmB6s76PVd eppv5DUg8dZperI=; b=ffqiwkSXEEIMDi2I0Q4KsgmHmF+XUZsgMwcoLRBMZnzR +kM6SVp1snzur8jS1GYdFWhTcNVHvtadJqXk8/Z3SJ4kgO7C/K5xIUb+Z0SMO0D+ ue9g/BoT7/tCxJNq/Q1Dx6PCjFJDGrW2EqCuzBMF++dJkaMQMYvOQaKZD+mVcydo wl15ZAt3sDsGKyapPgoapw5Y1CVk7SesOIzZpHVsR1A39nMGyP+ivc/S+75zyqMy DYAuvUjLOxwLx0WkMBdlLwIsx1UJe4fB0B0WnJmKslzERUN1wWXXuGZvf4OvX8Q/ EL1pBljMKyfFFKOJKk+I+qtd8VwtOZycCYd82SU8Hw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvdelvddgudejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 3 Jun 2024 05:30:42 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 8660b339 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 3 Jun 2024 09:30:18 +0000 (UTC) Date: Mon, 3 Jun 2024 11:30:40 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Eric Sunshine , Junio C Hamano , Ramsay Jones , Justin Tobler Subject: [PATCH v4 07/12] refs/files: fix NULL pointer deref when releasing ref store Message-ID: <56baa798fbb2838227fbc08ed54f200e38545d28.1717402363.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `free_ref_cache()` function is not `NULL` safe and will thus segfault when being passed such a pointer. This can easily happen when trying to release a partially initialized "files" ref store. Fix this. Signed-off-by: Patrick Steinhardt --- refs/ref-cache.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/refs/ref-cache.c b/refs/ref-cache.c index b6c53fc8ed..4ce519bbc8 100644 --- a/refs/ref-cache.c +++ b/refs/ref-cache.c @@ -71,6 +71,8 @@ static void free_ref_entry(struct ref_entry *entry) void free_ref_cache(struct ref_cache *cache) { + if (!cache) + return; free_ref_entry(cache->root); free(cache); }