git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: mhagger@alum.mit.edu
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>,
	cmn@elego.de, A Large Angry SCM <gitzilla@gmail.com>,
	Daniel Barkalow <barkalow@iabervon.org>,
	Sverre Rabbelier <srabbelier@gmail.com>,
	Michael Haggerty <mhagger@alum.mit.edu>
Subject: [RFC 04/13] add_ref(): move the call of check_refname_format() to callers
Date: Wed, 19 Oct 2011 22:55:07 +0200	[thread overview]
Message-ID: <1319057716-28094-5-git-send-email-mhagger@alum.mit.edu> (raw)
In-Reply-To: <1319057716-28094-1-git-send-email-mhagger@alum.mit.edu>

From: Michael Haggerty <mhagger@alum.mit.edu>

Do not call check_refname_format() in add_ref(); instead change its
callers to do the check.  (In fact, don't do any checking in
add_extra_ref(), because that function handles bizarre things like
"refs/tags/3.1.1.1^{}".)

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---

I'm still not clear on how extra_refs are used.  Are they generated
from local refs or are they generated from remote refs?  If the
latter, then it is probably irresponsible not to do *some* sanity
checking in add_extra_ref() to prevent any chance of refnames like
"../../../etc/passwd".

 refs.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/refs.c b/refs.c
index 8299e51..a40dfa5 100644
--- a/refs.c
+++ b/refs.c
@@ -60,8 +60,6 @@ static void add_ref(const char *name, const unsigned char *sha1,
 	entry = xmalloc(sizeof(struct ref_entry) + len);
 	hashcpy(entry->sha1, sha1);
 	hashclr(entry->peeled);
-	if (check_refname_format(name, REFNAME_ALLOW_ONELEVEL|REFNAME_DOT_COMPONENT))
-		die("Reference has invalid format: '%s'", name);
 	memcpy(entry->name, name, len);
 	entry->flag = flag;
 	if (new_entry)
@@ -232,6 +230,8 @@ static void read_packed_refs(FILE *f, struct ref_array *array)
 
 		name = parse_ref_line(refline, sha1);
 		if (name) {
+			if (check_refname_format(name, REFNAME_FULL))
+				die("Reference has invalid format: '%s'", name);
 			add_ref(name, sha1, flag, array, &last);
 			continue;
 		}
@@ -336,6 +336,8 @@ static void get_ref_dir(const char *submodule, const char *base,
 					hashclr(sha1);
 					flag |= REF_BROKEN;
 				}
+			if (check_refname_format(ref, REFNAME_FULL))
+				die("Reference has invalid format: '%s'", ref);
 			add_ref(ref, sha1, flag, array, NULL);
 		}
 		free(ref);
-- 
1.7.7

  parent reply	other threads:[~2011-10-19 20:55 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-19 20:55 [RFC 00/13] Checking full vs. partial refnames mhagger
2011-10-19 20:55 ` [RFC 01/13] check_refname_component(): iterate via index rather than via pointer mhagger
2011-10-19 20:55 ` [RFC 02/13] parse_refname_prefix(): new function mhagger
2011-10-19 20:55 ` [RFC 03/13] Teach check_refname_format() to check full refnames mhagger
2011-10-19 20:55 ` mhagger [this message]
2011-10-19 21:49   ` [RFC 04/13] add_ref(): move the call of check_refname_format() to callers Junio C Hamano
2011-10-19 21:59     ` Michael Haggerty
2011-10-19 20:55 ` [RFC 05/13] receive-pack::update(): use check_refname_format(..., REFNAME_FULL) mhagger
2011-10-19 20:55 ` [RFC 06/13] strbuf_check_branch_ref(): " mhagger
2011-10-19 20:55 ` [RFC 07/13] one_local_ref(): " mhagger
2011-10-19 20:55 ` [RFC 08/13] expand_namespace(): the refname is full, so use REFNAME_FULL option mhagger
2011-10-19 20:55 ` [RFC 09/13] new_branch(): verify that new branch name is a valid full refname mhagger
2011-10-19 21:52   ` Junio C Hamano
2011-10-19 20:55 ` [RFC 10/13] strbuf_check_tag_ref(): the refname is full, so use REFNAME_FULL option mhagger
2011-10-19 20:55 ` [RFC 11/13] replace_object(): " mhagger
2011-10-19 20:55 ` [RFC 12/13] resolve_ref: use check_refname_format(..., REFNAME_FULL) mhagger
2011-10-19 20:55 ` [RFC 13/13] filter_refs(): the refname is full, so use REFNAME_FULL option mhagger

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=1319057716-28094-5-git-send-email-mhagger@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=barkalow@iabervon.org \
    --cc=cmn@elego.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=gitzilla@gmail.com \
    --cc=peff@peff.net \
    --cc=srabbelier@gmail.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).