@matheusbsbs / matheus-bagliano / commits / a2f9fe92eb
Fork 0

lock_any_ref_for_update(): do not accept malformatted refs.

We used to use lock_any_ref_for_update() because the command needs to also update HEAD (which is not under refs/, so lock_ref_sha1() cannot be used). The function however did not check for refs with illegal characters in them. Use check_ref_format() to catch malformed refs. For this check, we specifically do not want to say having less than two levels in the name is illegal to allow HEAD (and perhaps other special refs in the future). Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jan 29, 2007 at 00:57 UTC a2f9fe92ebfdf9b5c458642fa0bf32b17433c6c1
2 files changed +4 -4
builtin-update-ref.c
+2 -4
@@ -61,10 +61,8 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
61
62 lock = lock_any_ref_for_update(refname, oldval ? oldsha1 : NULL);
63 if (!lock)
64 - return 1;
64 + die("%s: cannot lock the ref", refname);
65 if (write_ref_sha1(lock, sha1, msg) < 0)
66 - return 1;
67 -
68 - /* write_ref_sha1 always unlocks the ref, no need to do it explicitly */
66 + die("%s: cannot update the ref", refname);
67 return 0;
68 }
refs.c
+2
@@ -710,6 +710,8 @@ struct ref_lock *lock_ref_sha1(const char *ref, const unsigned char *old_sha1)
710
711 struct ref_lock *lock_any_ref_for_update(const char *ref, const unsigned char *old_sha1)
712 {
713 + if (check_ref_format(ref) == -1)
714 + return NULL;
715 return lock_ref_sha1_basic(ref, old_sha1, NULL);
716 }
717