Re: [PATCH 2/2] Restrict ref-like names immediately below $GIT_DIR
- From
Jeff King <peff@peff.net>
- Date
- Oct 12, 2011, 21:51 UTC
- Message-ID
- <20111012215105.GA4498@sigill.intra.peff.net>
- In-Reply-To
- <7vvcru9k22.fsf_-_@alter.siamese.dyndns.org>
On Wed, Oct 12, 2011 at 10:49:41AM -0700, Junio C Hamano wrote:
Show 18 quoted lines
> +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;
> +}I thought from your earlier comment:
> I wanted to start as loose as possible to avoid negatively impacting > existing users, later to tighten. As fsck and friends never look > outside of refs/, I think the prefix refs/ is a reasonable restriction > that is safe.
that you did agree with tightening this up to allow just refs/ as a subdirectory.
Squashable patch is below.
diff --git a/refs.c b/refs.c index 0f26d9d..b159c4a 100644 --- a/refs.c +++ b/refs.c @@ -994,21 +994,20 @@ int check_refname_format(const char *ref, int flags) static int refname_ok_at_root_level(const char *str, int len) { - int seen_non_root_char = 0; + if (len >= 5 && !memcmp(str, "refs/", 5)) + return 1; 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 0; } - return !seen_non_root_char; + return 1; } int refname_match(const char *abbrev_name, const char *full_name, const char **rules)