Commit 0c01f93e8c89a16b3531e4fb32384fe90bf4c548

Russell Belfer 2013-05-29T14:50:24

Merge pull request #1619 from ethomson/gitignore_slash allow (ignore) bare slash in gitignore

diff --git a/src/attr_file.c b/src/attr_file.c
index 85cd876..d059cfe 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -397,7 +397,8 @@ int git_attr_fnmatch__parse(
 
 	*base = scan;
 
-	spec->length = scan - pattern;
+	if ((spec->length = scan - pattern) == 0)
+		return GIT_ENOTFOUND;
 
 	if (pattern[spec->length - 1] == '/') {
 		spec->length--;
diff --git a/src/pool.c b/src/pool.c
index b3cd496..d484769 100644
--- a/src/pool.c
+++ b/src/pool.c
@@ -194,6 +194,11 @@ char *git_pool_strndup(git_pool *pool, const char *str, size_t n)
 
 	assert(pool && str && pool->item_size == sizeof(char));
 
+	if (n + 1 == 0) {
+		giterr_set_oom();
+		return NULL;
+	}
+
 	if ((ptr = git_pool_malloc(pool, (uint32_t)(n + 1))) != NULL) {
 		memcpy(ptr, str, n);
 		*(((char *)ptr) + n) = '\0';
diff --git a/tests-clar/attr/ignore.c b/tests-clar/attr/ignore.c
index 8df0eb9..0f945eb 100644
--- a/tests-clar/attr/ignore.c
+++ b/tests-clar/attr/ignore.c
@@ -34,6 +34,27 @@ void test_attr_ignore__honor_temporary_rules(void)
 	assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
 }
 
+void test_attr_ignore__allow_root(void)
+{
+	cl_git_rewritefile("attr/.gitignore", "/");
+
+	assert_is_ignored(false, "File.txt");
+	assert_is_ignored(false, "NewFolder");
+	assert_is_ignored(false, "NewFolder/NewFolder");
+	assert_is_ignored(false, "NewFolder/NewFolder/File.txt");
+}
+
+void test_attr_ignore__ignore_root(void)
+{
+	cl_git_rewritefile("attr/.gitignore", "/\n\n/NewFolder\n/NewFolder/NewFolder");
+
+	assert_is_ignored(false, "File.txt");
+	assert_is_ignored(true, "NewFolder");
+	assert_is_ignored(true, "NewFolder/NewFolder");
+	assert_is_ignored(true, "NewFolder/NewFolder/File.txt");
+}
+
+
 void test_attr_ignore__skip_gitignore_directory(void)
 {
 	cl_git_rewritefile("attr/.git/info/exclude", "/NewFolder\n/NewFolder/NewFolder");
diff --git a/tests-clar/core/pool.c b/tests-clar/core/pool.c
index c42bb6d..3073c4a 100644
--- a/tests-clar/core/pool.c
+++ b/tests-clar/core/pool.c
@@ -133,3 +133,13 @@ void test_core_pool__free_list(void)
 
 	git_pool_clear(&p);
 }
+
+void test_core_pool__strndup_limit(void)
+{
+	git_pool p;
+
+	cl_git_pass(git_pool_init(&p, 1, 100));
+	cl_assert(git_pool_strndup(&p, "foo", -1) == NULL);
+	git_pool_clear(&p);
+}
+