summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2016-04-27 10:40:39 (GMT)
committerMichael Haggerty <mhagger@alum.mit.edu>2016-05-05 14:37:30 (GMT)
commite40f3557f7e767bd2be2a824bc3bc2379aa69931 (patch)
treef348ea258b59c04e6d8acbcfb0cf65d913e2ecfc /refs.c
parent35db25c65f6f77c153ef2b1183ea7821236201c8 (diff)
downloadgit-e40f3557f7e767bd2be2a824bc3bc2379aa69931.zip
git-e40f3557f7e767bd2be2a824bc3bc2379aa69931.tar.gz
git-e40f3557f7e767bd2be2a824bc3bc2379aa69931.tar.bz2
refname_is_safe(): insist that the refname already be normalized
The reference name is going to be compared to other reference names, so it should be in its normalized form. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/refs.c b/refs.c
index ca0280f..b18d995 100644
--- a/refs.c
+++ b/refs.c
@@ -125,14 +125,19 @@ int refname_is_safe(const char *refname)
if (skip_prefix(refname, "refs/", &rest)) {
char *buf;
int result;
+ size_t restlen = strlen(rest);
+
+ /* rest must not be empty, or start or end with "/" */
+ if (!restlen || *rest == '/' || rest[restlen - 1] == '/')
+ return 0;
/*
* Does the refname try to escape refs/?
* For example: refs/foo/../bar is safe but refs/foo/../../bar
* is not.
*/
- buf = xmallocz(strlen(rest));
- result = !normalize_path_copy(buf, rest);
+ buf = xmallocz(restlen);
+ result = !normalize_path_copy(buf, rest) && !strcmp(buf, rest);
free(buf);
return result;
}