ref_transaction_update(): check refname_is_safe() at a minimum

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>

Michael Haggerty committed Apr 27, 2016 at 15:54 UTC 8a679de6f1a4bd077f828273f75eea46947b5b73
3 files changed +5 -4
refs.c
+3 -2
@@ -805,8 +805,9 @@ int ref_transaction_update(struct ref_transaction *transaction,
805 {
806 assert(err);
807
808 - if (new_sha1 && !is_null_sha1(new_sha1) &&
809 - check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
808 + if ((new_sha1 && !is_null_sha1(new_sha1)) ?
809 + check_refname_format(refname, REFNAME_ALLOW_ONELEVEL) :
810 + !refname_is_safe(refname)) {
811 strbuf_addf(err, "refusing to update ref with bad name '%s'",
812 refname);
813 return -1;
t/t1400-update-ref.sh
+1 -1
@@ -23,7 +23,7 @@ test_expect_success setup '
23 m=refs/heads/master
24 n_dir=refs/heads/gu
25 n=$n_dir/fixes
26 -outside=foo
26 +outside=refs/foo
27
28 test_expect_success \
29 "create $m" \
t/t1430-bad-ref-name.sh
+1 -1
@@ -285,7 +285,7 @@ test_expect_success 'update-ref -d cannot delete non-ref in .git dir' '
285 echo precious >expect &&
286 test_must_fail git update-ref -d my-private-file >output 2>error &&
287 test_must_be_empty output &&
288 - test_i18ngrep -e "cannot lock .*: unable to resolve reference" error &&
288 + test_i18ngrep -e "refusing to update ref with bad name" error &&
289 test_cmp expect .git/my-private-file
290 '
291