]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refname_is_safe(): use skip_prefix()
authorMichael Haggerty <mhagger@alum.mit.edu>
Wed, 27 Apr 2016 10:39:11 +0000 (12:39 +0200)
committerMichael Haggerty <mhagger@alum.mit.edu>
Thu, 5 May 2016 14:37:30 +0000 (16:37 +0200)
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
refs.c

diff --git a/refs.c b/refs.c
index 87dc82f1d87d6c0969b97f94035233bec0bc3729..5789152743ffbf0ac0f9a0270e2d689349cf7682 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -120,17 +120,19 @@ int check_refname_format(const char *refname, int flags)
 
 int refname_is_safe(const char *refname)
 {
-       if (starts_with(refname, "refs/")) {
+       const char *rest;
+
+       if (skip_prefix(refname, "refs/", &rest)) {
                char *buf;
                int result;
 
-               buf = xmallocz(strlen(refname));
                /*
                 * Does the refname try to escape refs/?
                 * For example: refs/foo/../bar is safe but refs/foo/../../bar
                 * is not.
                 */
-               result = !normalize_path_copy(buf, refname + strlen("refs/"));
+               buf = xmallocz(strlen(rest));
+               result = !normalize_path_copy(buf, rest);
                free(buf);
                return result;
        }