git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Caleb White <cdwhite3@pm.me>
To: git@vger.kernel.org
Cc: Caleb White <cdwhite3@pm.me>
Subject: [PATCH v2 4/4] worktree: prevent null pointer dereference
Date: Sun, 06 Oct 2024 06:01:35 +0000	[thread overview]
Message-ID: <20241006060017.171788-5-cdwhite3@pm.me> (raw)
In-Reply-To: <20241006060017.171788-1-cdwhite3@pm.me>

[-- Attachment #1: Type: text/plain, Size: 625 bytes --]

If worktrees is NULL, free_worktrees() should return immediately to
prevent a null pointer dereference.

Signed-off-by: Caleb White <cdwhite3@pm.me>
---
 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);
 }
-- 
2.46.2


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 509 bytes --]

  parent reply	other threads:[~2024-10-06  6:01 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-06  6:00 [PATCH v2 0/4] Link worktrees with relative paths Caleb White
2024-10-06  6:00 ` [PATCH v2 1/4] worktree: refactor infer_backlink() to use *strbuf Caleb White
2024-10-06 15:09   ` shejialuo
2024-10-06 15:13     ` Kristoffer Haugsbakk
2024-10-06 18:41     ` Eric Sunshine
2024-10-07  2:26       ` Caleb White
2024-10-07  4:12         ` shejialuo
2024-10-07  4:19           ` Caleb White
2024-10-07  4:28             ` shejialuo
2024-10-07  4:31               ` Caleb White
2024-10-07  3:56       ` shejialuo
2024-10-07  4:01         ` Caleb White
2024-10-07  4:19           ` shejialuo
2024-10-06 23:47     ` Caleb White
2024-10-06 18:16   ` Eric Sunshine
2024-10-07  2:42     ` Caleb White
2024-10-07  3:26       ` Eric Sunshine
2024-10-07  3:28         ` Caleb White
2024-10-06  6:01 ` [PATCH v2 2/4] worktree: link worktrees with relative paths Caleb White
2024-10-06 11:05   ` Eric Sunshine
2024-10-06 22:37     ` Caleb White
2024-10-06 15:37   ` shejialuo
2024-10-06 23:57     ` Caleb White
2024-10-07  3:45       ` shejialuo
2024-10-07  4:02         ` Eric Sunshine
2024-10-07 16:59         ` Caleb White
2024-10-06  6:01 ` [PATCH v2 3/4] worktree: sync worktree paths after gitdir move Caleb White
2024-10-06 11:12   ` Eric Sunshine
2024-10-06 22:41     ` Caleb White
2024-10-06 22:48       ` Eric Sunshine
2024-10-06 23:13         ` Caleb White
2024-10-06 23:27           ` Eric Sunshine
2024-10-06  6:01 ` Caleb White [this message]
2024-10-06 11:24   ` [PATCH v2 4/4] worktree: prevent null pointer dereference Eric Sunshine
2024-10-06 23:03     ` Caleb White
2024-10-06 23:24       ` Eric Sunshine
2024-10-07  3:09         ` Caleb White
2024-10-06  6:18 ` [PATCH v2 0/4] Link worktrees with relative paths Eric Sunshine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241006060017.171788-5-cdwhite3@pm.me \
    --to=cdwhite3@pm.me \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).