Skip to content

Commit 99fc555

Browse files
wylfengitster
authored andcommitted
rev-parse: fix segfault with missing --path-format argument
Calling "git rev-parse --path-format" without an argument segfaults instead of giving an error message. Commit fac60b8 (rev-parse: add option for absolute or relative path formatting, 2020-12-13) added the argument parsing code but forgot to handle NULL. Returning an error makes sense here because there is no default value we could use. Add a test case to verify. Signed-off-by: Wolfgang Müller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 48bf2fa commit 99fc555

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

builtin/rev-parse.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
759759
continue;
760760
}
761761
if (opt_with_value(arg, "--path-format", &arg)) {
762+
if (!arg)
763+
die("--path-format requires an argument");
762764
if (!strcmp(arg, "absolute")) {
763765
format = FORMAT_CANONICAL;
764766
} else if (!strcmp(arg, "relative")) {

t/t1500-rev-parse.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ test_expect_success '--path-format can change in the middle of the command line'
146146
test_cmp expect actual
147147
'
148148

149+
test_expect_success '--path-format does not segfault without an argument' '
150+
test_must_fail git rev-parse --path-format
151+
'
152+
149153
test_expect_success 'git-common-dir from worktree root' '
150154
echo .git >expect &&
151155
git rev-parse --git-common-dir >actual &&

0 commit comments

Comments
 (0)