]> git.proxmox.com Git - libgit2.git/commitdiff
refs: No component of a refname can end with '.lock'
authornulltoken <emeric.fermas@gmail.com>
Thu, 7 Feb 2013 22:40:10 +0000 (23:40 +0100)
committernulltoken <emeric.fermas@gmail.com>
Mon, 11 Feb 2013 22:19:40 +0000 (23:19 +0100)
src/refs.c
tests-clar/refs/isvalidname.c

index e75f51001ba3cf7c2b90918fb9a5cd2ad9577d58..fd57ce8f747a19dc41a5fd1659432101aee4691d 100644 (file)
@@ -1599,6 +1599,7 @@ static int ensure_segment_validity(const char *name)
 {
        const char *current = name;
        char prev = '\0';
+       int lock_len = strlen(GIT_FILELOCK_EXTENSION);
 
        if (*current == '.')
                return -1; /* Refname starts with "." */
@@ -1619,6 +1620,11 @@ static int ensure_segment_validity(const char *name)
                prev = *current;
        }
 
+       /* A refname component can not end with ".lock" */
+       if (current - name >= lock_len &&
+               !git__strncmp(current - lock_len, GIT_FILELOCK_EXTENSION, lock_len))
+                       return -1;
+
        return (int)(current - name);
 }
 
@@ -1714,10 +1720,6 @@ int git_reference__normalize_name(
        if (current[segment_len - 1] == '/')
                goto cleanup;
 
-       /* A refname can not end with ".lock" */
-       if (!git__suffixcmp(name, GIT_FILELOCK_EXTENSION))
-               goto cleanup;
-
        if ((segments_count == 1 ) && !(flags & GIT_REF_FORMAT_ALLOW_ONELEVEL))
                goto cleanup;
 
index b61a023602c32b21880ef95bc2fdc38a95b8637e..e9fbdbcd15d5a55824b6a5dc557f5232e328b40d 100644 (file)
@@ -13,6 +13,7 @@ void test_refs_isvalidname__can_detect_invalid_formats(void)
        cl_assert_equal_i(false, git_reference_is_valid_name("/stupid/name/master"));
        cl_assert_equal_i(false, git_reference_is_valid_name("/"));
        cl_assert_equal_i(false, git_reference_is_valid_name(""));
+       cl_assert_equal_i(false, git_reference_is_valid_name("refs/heads/sub.lock/webmatrix"));
 }
 
 void test_refs_isvalidname__wont_hopefully_choke_on_valid_formats(void)