refname_is_safe(): use skip_prefix()

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

Michael Haggerty committed Apr 27, 2016 at 12:39 UTC 39950fef8bb45e944655e48393ee04c0b33211f5
1 file changed +5 -3
refs.c
+5 -3
@@ -120,17 +120,19 @@ int check_refname_format(const char *refname, int flags)
120
121 int refname_is_safe(const char *refname)
122 {
123 - if (starts_with(refname, "refs/")) {
123 + const char *rest;
124 +
125 + if (skip_prefix(refname, "refs/", &rest)) {
126 char *buf;
127 int result;
128
127 - buf = xmallocz(strlen(refname));
129 /*
130 * Does the refname try to escape refs/?
131 * For example: refs/foo/../bar is safe but refs/foo/../../bar
132 * is not.
133 */
133 - result = !normalize_path_copy(buf, refname + strlen("refs/"));
134 + buf = xmallocz(strlen(rest));
135 + result = !normalize_path_copy(buf, rest);
136 free(buf);
137 return result;
138 }