diff options
author | Ævar Arnfjörð Bjarmason <avarab@gmail.com> | 2022-12-20 16:40:18 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-12-25 10:01:09 +0300 |
commit | 891cb09db6c0e6bf11b8175bc5ea5f45493afb85 (patch) | |
tree | 66d2e5dbfefcc002beeef34234229770c2ae0aff /builtin/bundle.c | |
parent | 8706a59933d09354c5e3eb09a543453655a97183 (diff) |
bundle: don't segfault on "git bundle <subcmd>"
Since aef7d75e580 (builtin/bundle.c: let parse-options parse
subcommands, 2022-08-19) we've been segfaulting if no argument was
provided.
The fix is easy, as all of the "git bundle" subcommands require a
non-option argument we can check that we have arguments left after
calling parse-options().
This makes use of code added in 73c3253d75e (bundle: framework for
options before bundle file, 2019-11-10), before this change that code
has always been unreachable. In 73c3253d75e we'd never reach it as we
already checked "argc < 2" in cmd_bundle() itself.
Then when aef7d75e580 (whose segfault we're fixing here) migrated this
code to the subcommand API it removed that "argc < 2" check, but we
were still checking the wrong "argc" in parse_options_cmd_bundle(), we
need to check the "newargc". The "argc" will always be >= 1, as it
will necessarily contain at least the subcommand name
itself (e.g. "create").
As an aside, this could be safely squashed into this, but let's not do
that for this minimal segfault fix, as it's an unrelated refactoring:
--- a/builtin/bundle.c
+++ b/builtin/bundle.c
@@ -55,13 +55,12 @@ static int parse_options_cmd_bundle(int argc,
const char * const usagestr[],
const struct option options[],
char **bundle_file) {
- int newargc;
- newargc = parse_options(argc, argv, NULL, options, usagestr,
+ argc = parse_options(argc, argv, NULL, options, usagestr,
PARSE_OPT_STOP_AT_NON_OPTION);
- if (!newargc)
+ if (!argc)
usage_with_options(usagestr, options);
*bundle_file = prefix_filename(prefix, argv[0]);
- return newargc;
+ return argc;
}
static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {
Reported-by: Hubert Jasudowicz <hubertj@stmcyber.pl>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Tested-by: Hubert Jasudowicz <hubertj@stmcyber.pl>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/bundle.c')
-rw-r--r-- | builtin/bundle.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/builtin/bundle.c b/builtin/bundle.c index e80efce3a4..13309f2ea9 100644 --- a/builtin/bundle.c +++ b/builtin/bundle.c @@ -48,7 +48,7 @@ static int parse_options_cmd_bundle(int argc, int newargc; newargc = parse_options(argc, argv, NULL, options, usagestr, PARSE_OPT_STOP_AT_NON_OPTION); - if (argc < 1) + if (!newargc) usage_with_options(usagestr, options); *bundle_file = prefix_filename(prefix, argv[0]); return newargc; |