Skip to content

Commit 491c049

Browse files
committed
stash: fix 'show -p' with unknown options
"git stash show -p" with unknown options would fail with a use-after-free error. This commit fixes that error by ensuring that revision_args has its argument count updated correctly. Signed-off-by: Adam Johnson <me@adamj.eu>
1 parent 8613c2b commit 491c049

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

builtin/stash.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,7 @@ static int show_stash(int argc, const char **argv, const char *prefix,
956956
}
957957

958958
argc = setup_revisions(revision_args.nr, revision_args.v, &rev, NULL);
959+
revision_args.nr = argc;
959960
if (argc > 1)
960961
goto usage;
961962
if (!rev.diffopt.output_format) {

t/t3903-stash.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,17 @@ test_expect_success 'stash show - stashes on stack, stash-like argument' '
699699
test_cmp expected actual
700700
'
701701

702+
test_expect_success 'stash show -p - stashes on stack, unknown argument shows usage' '
703+
git stash clear &&
704+
test_when_finished "git reset --hard HEAD" &&
705+
git reset --hard &&
706+
echo foo >>file &&
707+
git stash &&
708+
test_when_finished "git stash drop" &&
709+
test_expect_code 129 git stash show -p --unknown 2>usage &&
710+
grep -F "usage: git stash show" usage
711+
'
712+
702713
test_expect_success 'stash show -p - stashes on stack, stash-like argument' '
703714
git stash clear &&
704715
test_when_finished "git reset --hard HEAD" &&

0 commit comments

Comments
 (0)