Skip to content

Commit

Permalink
lock_any_ref_for_update(): do not accept malformatted refs.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Junio C Hamano committed Jan 29, 2007
1 parent df391b1 commit a2f9fe9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 2 additions & 4 deletions builtin-update-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)

lock = lock_any_ref_for_update(refname, oldval ? oldsha1 : NULL);
if (!lock)
return 1;
die("%s: cannot lock the ref", refname);
if (write_ref_sha1(lock, sha1, msg) < 0)
return 1;

/* write_ref_sha1 always unlocks the ref, no need to do it explicitly */
die("%s: cannot update the ref", refname);
return 0;
}
2 changes: 2 additions & 0 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,8 @@ struct ref_lock *lock_ref_sha1(const char *ref, const unsigned char *old_sha1)

struct ref_lock *lock_any_ref_for_update(const char *ref, const unsigned char *old_sha1)
{
if (check_ref_format(ref) == -1)
return NULL;
return lock_ref_sha1_basic(ref, old_sha1, NULL);
}

Expand Down

0 comments on commit a2f9fe9

Please sign in to comment.