send-pack: tighten checks for remote names
"git push $URL HEAD~6" created a bogus ref HEAD~6 immediately under $GIT_DIR of the remote repository. While we should keep refspecs that have arbitrary extended SHA-1 expression on the source side working (e.g. "HEAD~6:refs/tags/yesterday"), we should not create bogus ref on the other end. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Dec 13, 2006 at 10:30 UTC
37adac765a469f8f8495e2befe7afeda65a2b272
2 files changed
+22
-1
refs.c
+1
-1
@@ -534,7 +534,7 @@ int check_ref_format(const char *ref)
534
level++;
535
if (!ch) {
536
if (level < 2)
537
- return -1; /* at least of form "heads/blah" */
537
+ return -2; /* at least of form "heads/blah" */
538
return 0;
539
}
540
}
send-pack.c
+21
@@ -406,6 +406,25 @@ static int send_pack(int in, int out, int nr_refspec, char **refspec)
406
return ret;
407
}
408
409
+static void verify_remote_names(int nr_heads, char **heads)
410
+{
411
+ int i;
412
+
413
+ for (i = 0; i < nr_heads; i++) {
414
+ const char *remote = strchr(heads[i], ':');
415
+
416
+ remote = remote ? (remote + 1) : heads[i];
417
+ switch (check_ref_format(remote)) {
418
+ case 0: /* ok */
419
+ case -2: /* ok but a single level -- that is fine for
420
+ * a match pattern.
421
+ */
422
+ continue;
423
+ }
424
+ die("remote part of refspec is not a valid name in %s",
425
+ heads[i]);
426
+ }
427
+}
428
429
int main(int argc, char **argv)
430
{
@@ -457,6 +476,8 @@ int main(int argc, char **argv)
476
usage(send_pack_usage);
477
if (heads && send_all)
478
usage(send_pack_usage);
479
+ verify_remote_names(nr_heads, heads);
480
+
481
pid = git_connect(fd, dest, exec);
482
if (pid < 0)
483
return 1;