ref_transaction_update(): check refname_is_safe() at a minimum
authorMichael Haggerty <mhagger@alum.mit.edu>
Wed, 27 Apr 2016 13:54:45 +0000 (15:54 +0200)
committerMichael Haggerty <mhagger@alum.mit.edu>
Mon, 13 Jun 2016 09:23:50 +0000 (11:23 +0200)
If the user has asked that a new value be set for a reference, we use
check_refname_format() to verify that the reference name satisfies all
of the rules. But in other cases, at least check that refname_is_safe().

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
refs.c
t/t1400-update-ref.sh
t/t1430-bad-ref-name.sh
diff --git a/refs.c b/refs.c
index 7c4eeb1c99ec324ce898a66309a1215982e1a0b5..842c5c7b0543ea21da3b46e9ad588cf587cb91e6 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -805,8 +805,9 @@ int ref_transaction_update(struct ref_transaction *transaction,
 {
        assert(err);
 
-       if (new_sha1 && !is_null_sha1(new_sha1) &&
-           check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
+       if ((new_sha1 && !is_null_sha1(new_sha1)) ?
+           check_refname_format(refname, REFNAME_ALLOW_ONELEVEL) :
+           !refname_is_safe(refname)) {
                strbuf_addf(err, "refusing to update ref with bad name '%s'",
                            refname);
                return -1;
index 40b0ccedfc5120cef92761a5eb663d06a3278874..08bd8fd8d603c6f05b1b8df9173a69ab3e912079 100755 (executable)
@@ -23,7 +23,7 @@ test_expect_success setup '
 m=refs/heads/master
 n_dir=refs/heads/gu
 n=$n_dir/fixes
-outside=foo
+outside=refs/foo
 
 test_expect_success \
        "create $m" \
index 25ddab4e984877cb9361919a893fce391d2f066a..8937e25e4955b79d72952289e7485652309def3a 100755 (executable)
@@ -285,7 +285,7 @@ test_expect_success 'update-ref -d cannot delete non-ref in .git dir' '
        echo precious >expect &&
        test_must_fail git update-ref -d my-private-file >output 2>error &&
        test_must_be_empty output &&
-       test_i18ngrep -e "cannot lock .*: unable to resolve reference" error &&
+       test_i18ngrep -e "refusing to update ref with bad name" error &&
        test_cmp expect .git/my-private-file
 '