Skip to content

Commit 88617d1

Browse files
ttaylorrgitster
authored andcommitted
multi-pack-index: fix potential segfault without sub-command
Since cd57bc4 (builtin/multi-pack-index.c: display usage on unrecognized command, 2021-03-30) we have used a "usage" label to avoid having two separate callers of usage_with_options (one when no arguments are given, and another for unrecognized sub-commands). But the first caller has been broken since cd57bc4, since it will happily jump to usage without arguments, and then pass argv[0] to the "unrecognized subcommand" error. Many compilers will save us from a segfault here, but the end result is ugly, since it mentions an unrecognized subcommand when we didn't even pass one, and (on GCC) includes "(null)" in its output. Move the "usage" label down past the error about unrecognized subcommands so that it is only triggered when it should be. While we're at it, bulk up our test coverage in this area, too. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3007752 commit 88617d1

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

builtin/multi-pack-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ int cmd_multi_pack_index(int argc, const char **argv,
176176
else if (!strcmp(argv[0], "expire"))
177177
return cmd_multi_pack_index_expire(argc, argv);
178178
else {
179-
usage:
180179
error(_("unrecognized subcommand: %s"), argv[0]);
180+
usage:
181181
usage_with_options(builtin_multi_pack_index_usage,
182182
builtin_multi_pack_index_options);
183183
}

t/t5319-multi-pack-index.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,4 +824,9 @@ test_expect_success 'load reverse index when missing .idx, .pack' '
824824
)
825825
'
826826

827+
test_expect_success 'usage shown without sub-command' '
828+
test_expect_code 129 git multi-pack-index 2>err &&
829+
! test_i18ngrep "unrecognized subcommand" err
830+
'
831+
827832
test_done

0 commit comments

Comments
 (0)