Skip to content

Commit 332b56b

Browse files
pks-tgitster
authored andcommitted
builtin/bundle: abort "verify" early when there is no repository
Verifying a bundle requires us to have a repository. This is encoded in `verify_bundle()`, which will return an error if there is no repository. We call `open_bundle()` before we call `verify_bundle()` though, which already performs some verifications even though we may ultimately abort due to a missing repository. This is problematic because `open_bundle()` already reads the bundle header and verifies that it contains a properly formatted hash. When there is no repository we have no clue what hash function to expect though, so we always end up assuming SHA1 here, which may or may not be correct. Furthermore, we are about to stop initializing `the_hash_algo` when there is no repository, which will lead to segfaults. Check early on whether we have a repository to fix this issue. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ce992ce commit 332b56b

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

builtin/bundle.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {
140140
builtin_bundle_verify_usage, options, &bundle_file);
141141
/* bundle internals use argv[1] as further parameters */
142142

143+
if (!startup_info->have_repository) {
144+
ret = error(_("need a repository to verify a bundle"));
145+
goto cleanup;
146+
}
147+
143148
if ((bundle_fd = open_bundle(bundle_file, &header, &name)) < 0) {
144149
ret = 1;
145150
goto cleanup;

0 commit comments

Comments
 (0)