git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ronnie Sahlberg <sahlberg@google.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: [PATCH 12/12] refs.c: fix handling of badly named refs
Date: Tue, 22 Jul 2014 14:36:20 -0700	[thread overview]
Message-ID: <CAL=YDW=zo2=6rJkZ0rXqe7=1X8j5yegHieHgmmJPO11u_U4d_Q@mail.gmail.com> (raw)
In-Reply-To: <CAL=YDWnTNKGW3AAr7twZ44KUb1Pxu0kms5Lt_3-4LBYGQw2+PQ@mail.gmail.com>

On Tue, Jul 22, 2014 at 2:30 PM, Ronnie Sahlberg <sahlberg@google.com> wrote:
> On Tue, Jul 22, 2014 at 1:41 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> Ronnie Sahlberg <sahlberg@google.com> writes:
>>
>>> We currently do not handle badly named refs well :
>>> $ cp .git/refs/heads/master .git/refs/heads/master.....@\*@\\.
>>> $ git branch
>>>    fatal: Reference has invalid format: 'refs/heads/master.....@*@\.'
>>> $ git branch -D master.....@\*@\\.
>>>   error: branch 'master.....@*@\.' not found.
>>>
>>> But we can not really recover from a badly named ref with less than
>>> manually deleting the .git/refs/heads/<refname> file.
>>>
>>> Change resolve_ref_unsafe to take a flags field instead of a 'reading'
>>> boolean and update all callers that used a non-zero value for reading
>>> to pass the flag RESOLVE_REF_READING instead.
>>> Add another flag RESOLVE_REF_ALLOW_BAD_NAME that will make
>>> resolve_ref_unsafe skip checking the refname for sanity and use this
>>> from branch.c so that we will be able to call resolve_ref_unsafe on such
>>> refs when trying to delete it.
>>
>> Makes sense.
>>
>>> Add checks for refname sanity when updating (not deleting) a ref in
>>> ref_transaction_update and in ref_transaction_create to make the transaction
>>> fail if an attempt is made to create/update a badly named ref.
>>> Since all ref changes will later go through the transaction layer this means
>>> we no longer need to check for and fail for bad refnames in
>>> lock_ref_sha1_basic.
>>>
>>> Change lock_ref_sha1_basic to not fail for bad refnames. Just check the
>>> refname, and print an error, and remember that the refname is bad so that
>>> we can skip calling verify_lock().
>>
>> This is somewhat puzzling, though.
>>
>>> @@ -2180,6 +2196,8 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
>>>               else
>>>                       unable_to_lock_index_die(ref_file, errno);
>>>       }
>>> +     if (bad_refname)
>>> +             return lock;
>>
>> Hmph.  If the only offence was that the ref was named badly due to
>> historically loose code, does the caller not still benefit from the
>> verify-lock check to make sure that other people did not muck with
>> the ref while we were planning to update it?
>>
>
> I don't think we need to do that.
> That would imply that we would need to be able to also allow reading
> the content of a badly named ref.
> Currently a badly named ref can not be accessed by any function except
>  git branch -D <badlynamedref> which contains the special flag that
> allows locking it eventhough the ref has an illegal name.
>
> So no one else should be able to read or modify the ref at all.
>
> I think it is sufficient for this case to just have the semantics
> "just delete it, I don't care what it used to point to." for this
> special case  git branch -D <badrefname>
> so therefore since it is not the content of the ref but the name of
> the ref itself we have a problem with I don't think we need to read
> the old value or verify it.

It is also that prior to this change we could not access these badly
named refs at all.
This change tries to be careful to not open up too much as it tries to
only allow   git branch -D  and nothing else to start working for such
refs.
(To avoid accidentally opening things up so that it becomes possible
to start using/depending on such refs)

  reply	other threads:[~2014-07-22 21:36 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-16 22:23 [PATCH 00/12] Use ref transactions part 3 Ronnie Sahlberg
2014-07-16 22:23 ` [PATCH 01/12] wrapper.c: simplify warn_if_unremovable Ronnie Sahlberg
2014-07-18 22:21   ` Junio C Hamano
2014-07-16 22:23 ` [PATCH 02/12] wrapper.c: add a new function unlink_or_msg Ronnie Sahlberg
2014-07-18 22:25   ` Junio C Hamano
2014-07-18 22:59     ` Junio C Hamano
2014-07-22 17:42       ` Ronnie Sahlberg
2014-07-22 17:56         ` Junio C Hamano
2014-07-16 22:23 ` [PATCH 03/12] refs.c: add an err argument to delete_ref_loose Ronnie Sahlberg
2014-07-16 22:23 ` [PATCH 04/12] refs.c: pass the ref log message to _create/delete/update instead of _commit Ronnie Sahlberg
2014-07-16 22:23 ` [PATCH 05/12] refs.c: pass NULL as *flags to read_ref_full Ronnie Sahlberg
2014-07-18 22:31   ` Junio C Hamano
2014-07-22 18:19     ` Ronnie Sahlberg
2014-07-22 21:44       ` Ronnie Sahlberg
2014-07-16 22:23 ` [PATCH 06/12] refs.c: move the check for valid refname to lock_ref_sha1_basic Ronnie Sahlberg
2014-07-18 22:37   ` Junio C Hamano
2014-07-16 22:23 ` [PATCH 07/12] refs.c: call lock_ref_sha1_basic directly from commit Ronnie Sahlberg
2014-07-16 22:23 ` [PATCH 08/12] refs.c: pass a skip list to name_conflict_fn Ronnie Sahlberg
2014-07-16 22:23 ` [PATCH 09/12] refs.c: propagate any errno==ENOTDIR from _commit back to the callers Ronnie Sahlberg
2014-07-16 22:23 ` [PATCH 10/12] fetch.c: change s_update_ref to use a ref transaction Ronnie Sahlberg
2014-07-16 22:23 ` [PATCH 11/12] refs.c: make write_ref_sha1 static Ronnie Sahlberg
2014-07-16 22:23 ` [PATCH 12/12] refs.c: fix handling of badly named refs Ronnie Sahlberg
2014-07-22 20:41   ` Junio C Hamano
2014-07-22 21:30     ` Ronnie Sahlberg
2014-07-22 21:36       ` Ronnie Sahlberg [this message]
2014-07-22 21:46       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAL=YDW=zo2=6rJkZ0rXqe7=1X8j5yegHieHgmmJPO11u_U4d_Q@mail.gmail.com' \
    --to=sahlberg@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).