diff options
author | Wolfgang Müller <wolf@oriole.systems> | 2021-05-17 11:02:42 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-05-17 12:39:29 +0300 |
commit | 99fc555188681caeedc983b9fc982d6dc8ee2a8c (patch) | |
tree | c572e55b79db540fe660e753a8c9d9a606b28203 /builtin | |
parent | 48bf2fa8bad054d66bd79c6ba903c89c704201f7 (diff) |
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 fac60b8925 (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 <wolf@oriole.systems>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/rev-parse.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 85bad9052e..7af8dab8bc 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -759,6 +759,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) continue; } if (opt_with_value(arg, "--path-format", &arg)) { + if (!arg) + die("--path-format requires an argument"); if (!strcmp(arg, "absolute")) { format = FORMAT_CANONICAL; } else if (!strcmp(arg, "relative")) { |