[RFC 04/13] add_ref(): move the call of check_refname_format() to callers
From: <hidden>
Date: 2016-06-15 22:52:18
Subsystem:
the rest · Maintainer:
Linus Torvalds
From: Michael Haggerty <redacted>
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 <redacted>
---
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