@@ -537,7 +537,8 @@ static int read_gitfile(git_str *path_out, const char *file_path)
537
537
}
538
538
539
539
typedef struct {
540
- git_str repo_path ;
540
+ const char * repo_path ;
541
+ git_str tmp ;
541
542
bool * is_safe ;
542
543
} validate_ownership_data ;
543
544
@@ -552,6 +553,18 @@ static int validate_ownership_cb(const git_config_entry *entry, void *payload)
552
553
} else {
553
554
const char * test_path = entry -> value ;
554
555
556
+ if (git_str_sets (& data -> tmp , test_path ) < 0 ||
557
+ git_fs_path_to_dir (& data -> tmp ) < 0 )
558
+ return -1 ;
559
+
560
+ /*
561
+ * Ensure that `git_fs_path_to_dir` mutated the
562
+ * input path by adding a trailing backslash.
563
+ * A trailing backslash on the input is not allowed.
564
+ */
565
+ if (strcmp (data -> tmp .ptr , test_path ) == 0 )
566
+ return 0 ;
567
+
555
568
#ifdef GIT_WIN32
556
569
/*
557
570
* Git for Windows does some truly bizarre things with
@@ -581,7 +594,8 @@ static int validate_ownership_cb(const git_config_entry *entry, void *payload)
581
594
strncmp (test_path , "//wsl.localhost/" , strlen ("//wsl.localhost/" )) != 0 )
582
595
test_path ++ ;
583
596
#endif
584
- if (strcmp (test_path , data -> repo_path .ptr ) == 0 )
597
+
598
+ if (strcmp (data -> tmp .ptr , data -> repo_path ) == 0 )
585
599
* data -> is_safe = true;
586
600
}
587
601
@@ -594,21 +608,14 @@ static int validate_ownership_config(
594
608
bool use_env )
595
609
{
596
610
validate_ownership_data ownership_data = {
597
- GIT_STR_INIT , is_safe
611
+ path , GIT_STR_INIT , is_safe
598
612
};
599
613
git_config * config ;
600
614
int error ;
601
615
602
616
if (load_global_config (& config , use_env ) != 0 )
603
617
return 0 ;
604
618
605
- git_str_sets (& ownership_data .repo_path , path );
606
- if (git_str_oom (& ownership_data .repo_path ))
607
- return -1 ;
608
- if (git_str_len (& ownership_data .repo_path ) > 1 &&
609
- ownership_data .repo_path .ptr [git_str_len (& ownership_data .repo_path ) - 1 ] == '/' )
610
- git_str_shorten (& ownership_data .repo_path , 1 );
611
-
612
619
error = git_config_get_multivar_foreach (config ,
613
620
"safe.directory" , NULL ,
614
621
validate_ownership_cb ,
@@ -618,7 +625,7 @@ static int validate_ownership_config(
618
625
error = 0 ;
619
626
620
627
git_config_free (config );
621
- git_str_dispose (& ownership_data .repo_path );
628
+ git_str_dispose (& ownership_data .tmp );
622
629
623
630
return error ;
624
631
}
@@ -685,26 +692,9 @@ static int validate_ownership(git_repository *repo)
685
692
goto done ;
686
693
687
694
if (!is_safe ) {
688
- git_str nice_path = GIT_STR_INIT ;
689
- #ifdef GIT_WIN32
690
- /* see comment above in validate_ownership_cb */
691
- if (!strncasecmp (path , "//" , strlen ("//" )))
692
- git_str_puts (& nice_path , "%(prefix)/" );
693
- #endif
694
- git_str_puts (& nice_path , path );
695
- if (!git_str_oom (& nice_path )) {
696
- if (git_str_len (& nice_path ) > 1 && nice_path .ptr [git_str_len (& nice_path ) - 1 ] == '/' )
697
- git_str_shorten (& nice_path , 1 );
698
- git_error_set (
699
- GIT_ERROR_CONFIG ,
700
- "repository path '%s' is not owned by current user.\n\nTo add an exception use the path '%s'." ,
701
- path , nice_path .ptr );
702
- } else
703
- git_error_set (
704
- GIT_ERROR_CONFIG ,
705
- "repository path '%s' is not owned by current user." ,
706
- path );
707
- git_str_dispose (& nice_path );
695
+ git_error_set (GIT_ERROR_CONFIG ,
696
+ "repository path '%s' is not owned by current user" ,
697
+ path );
708
698
error = GIT_EOWNER ;
709
699
}
710
700
0 commit comments