From patchwork Sun Oct 6 06:01:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb White X-Patchwork-Id: 13823683 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) (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 0BD9716B75C for ; Sun, 6 Oct 2024 06:01:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728194502; cv=none; b=TWsaxWSwaEQdgyCS6cqPwUT38LMA/3pBEe6TsF1blIa4TLi5S/p8U+XZEeV4JbyiCp9IKzMZ4/gDdp7GpFsNVhXwEQBuYbtpce2acuCWkr4NOmVd8SElcOVoGhJ4o/Utj/LLedCLurVAYJyda0HH7maKDz2SbwHt1MQ2zQH90pg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728194502; c=relaxed/simple; bh=hmxG7654v9pL/lC/2kRtpa2/HmKluFMZkNq5wJRpDi8=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=phHGA81T1owSGlB22M2jigxeNp14gHeUn31ZniGXfdqYcfft3AnABdLQwNSyFzlLTcx+lZm0C14fydetkuBNIB7/FbNzw0BwdcrHWzanMDPLOq3chotp9tAFIcEET4DzzWBLrx2YHr4t/3cmxjTzEjG0LQYc4ShtRs9BgyOoanw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me; spf=pass smtp.mailfrom=pm.me; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b=nFE+e5YC; arc=none smtp.client-ip=185.70.43.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pm.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b="nFE+e5YC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1728194499; x=1728453699; bh=eJAYFAmyEddl+GzJ3o1Du0u3FEXKNwKwbZkbjU99GNk=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=nFE+e5YCHJMxBVF40MFrBa3YfCLgq4R2e+qcsrAQnks8TgEhs26Oq6cPUdfBPoXYk jFTO7sV5L3d+M9VhZTOYVcwDJVPBxj2nvxzMF8ymFMuPhkfkFjLU6vldBqw8+mpuPb xpkqsCcptY5mKKSdVzgrO+P1dazO2zPHtEQ0bncTOTbVWQIIR4V01EXUR3ZfDZYC9D YHC2ZAeyEcJDe3R0mmI+WahsAFZRPJJHGOvaMOkEYrw+0nSwul6Bb05+BFG3T9fFlC oPBCpPa2hDy16pZbeCbE/TVAGRXHrwOM47xd77j3W+ocv9n1JUw/WrKGtXseytjHnK PymarbpeGL3SQ== Date: Sun, 06 Oct 2024 06:01:35 +0000 To: git@vger.kernel.org From: Caleb White Cc: Caleb White Subject: [PATCH v2 4/4] worktree: prevent null pointer dereference Message-ID: <20241006060017.171788-5-cdwhite3@pm.me> In-Reply-To: <20241006060017.171788-1-cdwhite3@pm.me> References: <20241006060017.171788-1-cdwhite3@pm.me> Feedback-ID: 31210263:user:proton X-Pm-Message-ID: b785527e36168ce301cd77bddf838212ba32ae9f Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If worktrees is NULL, free_worktrees() should return immediately to prevent a null pointer dereference. Signed-off-by: Caleb White --- worktree.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/worktree.c b/worktree.c index b08ecce..1cf15b0 100644 --- a/worktree.c +++ b/worktree.c @@ -28,8 +28,9 @@ void free_worktree(struct worktree *worktree) void free_worktrees(struct worktree **worktrees) { - int i = 0; - for (i = 0; worktrees[i]; i++) + if (!worktrees) + return; + for (int i = 0; worktrees[i]; i++) free_worktree(worktrees[i]); free (worktrees); }