Re: [PATCH 2/2] Restrict ref-like names immediately below $GIT_DIR
- From
Michael Haggerty <mhagger@alum.mit.edu>
- Date
- Oct 12, 2011, 21:42 UTC
- Message-ID
- <4E9609E3.1000300@alum.mit.edu>
- In-Reply-To
- <7vr52i9j8g.fsf@alter.siamese.dyndns.org>
On 10/12/2011 08:07 PM, Junio C Hamano wrote:
Show 36 quoted lines
> Michael Haggerty <mhagger@alum.mit.edu> writes:
>
>> On 10/12/2011 07:49 PM, Junio C Hamano wrote:
>>> diff --git a/refs.c b/refs.c
>>> index e3692bd..e54c482 100644
>>> --- a/refs.c
>>> +++ b/refs.c
>>> @@ -994,12 +994,34 @@ const char *ref_fetch_rules[] = {
>>> NULL
>>> };
>>>
>>> +static int refname_ok_at_root_level(const char *str, int len)
>>> +{
>>> + int seen_non_root_char = 0;
>>> +
>>> + while (len--) {
>>> + char ch = *str++;
>>> +
>>> + if (ch == '/')
>>> + return 1;
>>> + /*
>>> + * Only accept likes of .git/HEAD, .git/MERGE_HEAD at
>>> + * the root level as a ref.
>>> + */
>>> + if (ch != '_' && (ch < 'A' || 'Z' < ch))
>>> + seen_non_root_char = 1;
>>> + }
>>> + return !seen_non_root_char;
>>> +}
>>> +
>>
>> Nit: the seen_non_root_char variable can be replaced by an early "return
>> 0" from the loop and "return 1" if the loop falls through.
>
> Hmm, I thought that would fail when you feed "refs/heads/master" to the
> function.You're right. My brain must be scrambled from all of the rebasing that I have been doing ;-)
How about adding
/* * Accept strings that are either ALL_CAPS or include a '/'. */
(I think the underscore is implied by the example, but the comment could be expanded if necessary to be explicit.)
Michael
-- Michael Haggerty mhagger@alum.mit.edu http://softwareswirl.blogspot.com/