From: "Ophir Bleicher via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Ophir Bleicher <ophirble@gmail.com>, Ophir Bleicher <ophirble@gmail.com>
Subject: [PATCH] difftool: handle invalid paths without crashing
Date: Sun, 22 Nov 2026 13:39:25 +0000 [thread overview]
Message-ID: <pull.2503.git.git.1795354765127.gitgitgadget@gmail.com> (raw)
From: Ophir Bleicher <ophirble@gmail.com>
Check the cache entry returned by make_transient_cache_entry() in
builtin/difftool.c. An invalid path can cause the function to
dereference a NULL pointer, resulting in a segmentation fault:
$ blob=$(printf '%s\n' DEADBLOB | git hash-object -w --stdin)
$ tree=$(printf "100644 blob %s\t.git\n" "$blob" | git mktree)
$ commit=$(git commit-tree -m BADCOMMIT "$tree")
$ git difftool --dir-diff --no-symlinks --extcmd true "$commit" HEAD
error: invalid path '.git'
Segmentation fault (core dumped) git difftool ...
Add a regression test in t/t7800-difftool.sh for a tree containing
an invalid .git path to ensure git difftool --dir-diff exits
correctly.
Signed-off-by: Ophir Bleicher <ophirble@gmail.com>
---
difftool: handle invalid paths without crashing
Check the cache entry returned by make_transient_cache_entry() in
builtin/difftool.c. An invalid path can cause the function to
dereference a NULL pointer, resulting in a segmentation fault:
$ blob=$(printf '%s\n' DEADBLOB | git hash-object -w --stdin) $
tree=$(printf "100644 blob %s\t.git\n" "$blob" | git mktree) $
commit=$(git commit-tree -m BADCOMMIT "$tree") $ git difftool --dir-diff
--no-symlinks --extcmd true "$commit" HEAD error: invalid path '.git'
Segmentation fault (core dumped) git difftool ...
Add a regression test in t/t7800-difftool.sh for a tree containing an
invalid .git path to ensure git difftool --dir-diff exits correctly.
Signed-off-by: Ophir Bleicher ophirble@gmail.com
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2503%2FOphirBleicher%2Fbug-difftool-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2503/OphirBleicher/bug-difftool-v1
Pull-Request: https://github.com/git/git/pull/2503
builtin/difftool.c | 2 ++
t/t7800-difftool.sh | 8 ++++++++
2 files changed, 10 insertions(+)
diff --git a/builtin/difftool.c b/builtin/difftool.c
index bc7b2ea443..8208ade472 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -336,6 +336,8 @@ static int checkout_path(unsigned mode, struct object_id *oid,
int ret;
ce = make_transient_cache_entry(mode, oid, path, 0, NULL);
+ if (!ce)
+ return -1;
ret = checkout_entry(ce, state, NULL, NULL);
discard_cache_entry(ce);
diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh
index 0079aa9da4..9c79b2dec0 100755
--- a/t/t7800-difftool.sh
+++ b/t/t7800-difftool.sh
@@ -929,4 +929,12 @@ test_expect_success 'difftool --rotate/skip-to error condition' '
test_must_fail git difftool --no-prompt --extcmd=cat --rotate-to="3" HEAD^ &&
test_must_fail git difftool --no-prompt --extcmd=cat --skip-to="3" HEAD^
'
+
+test_expect_success 'difftool handles invalid .git path' '
+ blob=$(printf '%s\n' DEADBLOB | git hash-object -w --stdin) &&
+ tree=$(printf "100644 blob %s\t.git\n" "$blob" | git mktree) &&
+ commit=$(git commit-tree -m BADCOMMIT "$tree") &&
+ test_expect_code 1 git difftool --dir-diff --no-symlinks --extcmd true "$commit" HEAD
+'
+
test_done
base-commit: f7de81456940dd6f3274e461149bba12965de609
--
gitgitgadget
reply other threads:[~2026-11-22 13:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=pull.2503.git.git.1795354765127.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=ophirble@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.