@@ -590,6 +590,62 @@ void test_index_tests__cannot_add_invalid_filename(void)
590590 cl_fixture_cleanup ("invalid" );
591591}
592592
593+ static void assert_add_fails (git_repository * repo , const char * fn )
594+ {
595+ git_index * index ;
596+ git_buf path = GIT_BUF_INIT ;
597+ git_index_entry entry = {{0 }};
598+
599+ cl_git_pass (git_repository_index (& index , repo ));
600+ cl_assert (git_index_entrycount (index ) == 0 );
601+
602+ entry .path = fn ;
603+ entry .mode = GIT_FILEMODE_BLOB ;
604+ cl_git_pass (git_oid_fromstr (& entry .id , "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391" ));
605+
606+ cl_git_fail (git_index_add (index , & entry ));
607+
608+ cl_assert (git_index_entrycount (index ) == 0 );
609+
610+ git_buf_dispose (& path );
611+ git_index_free (index );
612+ }
613+
614+ /*
615+ * Test that writing an invalid filename fails on filesystem
616+ * specific protected names
617+ */
618+ void test_index_tests__cannot_add_protected_invalid_filename (void )
619+ {
620+ git_repository * repo ;
621+ git_index * index ;
622+
623+ cl_must_pass (p_mkdir ("invalid" , 0700 ));
624+
625+ cl_git_pass (git_repository_init (& repo , "./invalid" , 0 ));
626+
627+ /* add a file to the repository so we can reference it later */
628+ cl_git_pass (git_repository_index (& index , repo ));
629+ cl_git_mkfile ("invalid/dummy.txt" , "" );
630+ cl_git_pass (git_index_add_bypath (index , "dummy.txt" ));
631+ cl_must_pass (p_unlink ("invalid/dummy.txt" ));
632+ cl_git_pass (git_index_remove_bypath (index , "dummy.txt" ));
633+ git_index_free (index );
634+
635+ cl_repo_set_bool (repo , "core.protectHFS" , true);
636+ cl_repo_set_bool (repo , "core.protectNTFS" , true);
637+
638+ assert_add_fails (repo , ".git./hello" );
639+ assert_add_fails (repo , ".git\xe2\x80\xad/hello" );
640+ assert_add_fails (repo , "git~1/hello" );
641+ assert_add_fails (repo , ".git\xe2\x81\xaf/hello" );
642+ assert_add_fails (repo , ".git::$INDEX_ALLOCATION/dummy-file" );
643+
644+ git_repository_free (repo );
645+
646+ cl_fixture_cleanup ("invalid" );
647+ }
648+
593649static void replace_char (char * str , char in , char out )
594650{
595651 char * c = str ;
0 commit comments