difftool: handle invalid paths without crashing
PATCH 1/1 difftool: handle invalid paths without crashing
From: Ophir Bleicher <[email protected]>
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.
---
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.
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(+)
builtin/difftool.c +2 -0
@@ -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);
t/t7800-difftool.sh +8 -0
@@ -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
Signature · 1 line
gitgitgadget