Skip to content

Commit 1a7bd4f

Browse files
committed
Merge branch 'jk/maint-upload-archive' into maint
* jk/maint-upload-archive: archive: don't let remote clients get unreachable commits
2 parents a31275d + 7b51c33 commit 1a7bd4f

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

archive.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ static void parse_pathspec_arg(const char **pathspec,
247247
}
248248

249249
static void parse_treeish_arg(const char **argv,
250-
struct archiver_args *ar_args, const char *prefix)
250+
struct archiver_args *ar_args, const char *prefix,
251+
int remote)
251252
{
252253
const char *name = argv[0];
253254
const unsigned char *commit_sha1;
@@ -256,8 +257,17 @@ static void parse_treeish_arg(const char **argv,
256257
const struct commit *commit;
257258
unsigned char sha1[20];
258259

259-
if (get_sha1(name, sha1))
260-
die("Not a valid object name");
260+
/* Remotes are only allowed to fetch actual refs */
261+
if (remote) {
262+
char *ref = NULL;
263+
if (!dwim_ref(name, strlen(name), sha1, &ref))
264+
die("no such ref: %s", name);
265+
free(ref);
266+
}
267+
else {
268+
if (get_sha1(name, sha1))
269+
die("Not a valid object name");
270+
}
261271

262272
commit = lookup_commit_reference_gently(sha1, 1);
263273
if (commit) {
@@ -414,7 +424,7 @@ int write_archive(int argc, const char **argv, const char *prefix,
414424
setup_git_directory();
415425
}
416426

417-
parse_treeish_arg(argv, &args, prefix);
427+
parse_treeish_arg(argv, &args, prefix, remote);
418428
parse_pathspec_arg(argv + 1, &args);
419429

420430
return ar->write_archive(ar, &args);

t/t5000-tar-tree.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,14 @@ test_expect_success \
242242
'git archive --list outside of a git repo' \
243243
'GIT_DIR=some/non-existing/directory git archive --list'
244244

245+
test_expect_success 'clients cannot access unreachable commits' '
246+
test_commit unreachable &&
247+
sha1=`git rev-parse HEAD` &&
248+
git reset --hard HEAD^ &&
249+
git archive $sha1 >remote.tar &&
250+
test_must_fail git archive --remote=. $sha1 >remote.tar
251+
'
252+
245253
test_expect_success 'git-archive --prefix=olde-' '
246254
git archive --prefix=olde- >h.tar HEAD &&
247255
(

0 commit comments

Comments
 (0)