@@ -849,6 +849,19 @@ struct cache_entry *make_empty_transient_cache_entry(size_t len,
849
849
return xcalloc (1 , cache_entry_size (len ));
850
850
}
851
851
852
+ enum verify_path_result {
853
+ PATH_OK ,
854
+ PATH_INVALID ,
855
+ PATH_DIR_WITH_SEP ,
856
+ };
857
+
858
+ static enum verify_path_result verify_path_internal (const char * , unsigned );
859
+
860
+ int verify_path (const char * path , unsigned mode )
861
+ {
862
+ return verify_path_internal (path , mode ) == PATH_OK ;
863
+ }
864
+
852
865
struct cache_entry * make_cache_entry (struct index_state * istate ,
853
866
unsigned int mode ,
854
867
const struct object_id * oid ,
@@ -859,7 +872,7 @@ struct cache_entry *make_cache_entry(struct index_state *istate,
859
872
struct cache_entry * ce , * ret ;
860
873
int len ;
861
874
862
- if (! verify_path (path , mode )) {
875
+ if (verify_path_internal (path , mode ) == PATH_INVALID ) {
863
876
error (_ ("invalid path '%s'" ), path );
864
877
return NULL ;
865
878
}
@@ -993,60 +1006,62 @@ static int verify_dotfile(const char *rest, unsigned mode)
993
1006
return 1 ;
994
1007
}
995
1008
996
- int verify_path (const char * path , unsigned mode )
1009
+ static enum verify_path_result verify_path_internal (const char * path ,
1010
+ unsigned mode )
997
1011
{
998
1012
char c = 0 ;
999
1013
1000
1014
if (has_dos_drive_prefix (path ))
1001
- return 0 ;
1015
+ return PATH_INVALID ;
1002
1016
1003
1017
if (!is_valid_path (path ))
1004
- return 0 ;
1018
+ return PATH_INVALID ;
1005
1019
1006
1020
goto inside ;
1007
1021
for (;;) {
1008
1022
if (!c )
1009
- return 1 ;
1023
+ return PATH_OK ;
1010
1024
if (is_dir_sep (c )) {
1011
1025
inside :
1012
1026
if (protect_hfs ) {
1013
1027
1014
1028
if (is_hfs_dotgit (path ))
1015
- return 0 ;
1029
+ return PATH_INVALID ;
1016
1030
if (S_ISLNK (mode )) {
1017
1031
if (is_hfs_dotgitmodules (path ))
1018
- return 0 ;
1032
+ return PATH_INVALID ;
1019
1033
}
1020
1034
}
1021
1035
if (protect_ntfs ) {
1022
1036
#if defined GIT_WINDOWS_NATIVE || defined __CYGWIN__
1023
1037
if (c == '\\' )
1024
- return 0 ;
1038
+ return PATH_INVALID ;
1025
1039
#endif
1026
1040
if (is_ntfs_dotgit (path ))
1027
- return 0 ;
1041
+ return PATH_INVALID ;
1028
1042
if (S_ISLNK (mode )) {
1029
1043
if (is_ntfs_dotgitmodules (path ))
1030
- return 0 ;
1044
+ return PATH_INVALID ;
1031
1045
}
1032
1046
}
1033
1047
1034
1048
c = * path ++ ;
1035
1049
if ((c == '.' && !verify_dotfile (path , mode )) ||
1036
1050
is_dir_sep (c ))
1037
- return 0 ;
1051
+ return PATH_INVALID ;
1038
1052
/*
1039
1053
* allow terminating directory separators for
1040
1054
* sparse directory entries.
1041
1055
*/
1042
1056
if (c == '\0' )
1043
- return S_ISDIR (mode );
1057
+ return S_ISDIR (mode ) ? PATH_DIR_WITH_SEP :
1058
+ PATH_INVALID ;
1044
1059
} else if (c == '\\' && protect_ntfs ) {
1045
1060
if (is_ntfs_dotgit (path ))
1046
- return 0 ;
1061
+ return PATH_INVALID ;
1047
1062
if (S_ISLNK (mode )) {
1048
1063
if (is_ntfs_dotgitmodules (path ))
1049
- return 0 ;
1064
+ return PATH_INVALID ;
1050
1065
}
1051
1066
}
1052
1067
@@ -1349,7 +1364,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
1349
1364
1350
1365
if (!ok_to_add )
1351
1366
return -1 ;
1352
- if (! verify_path (ce -> name , ce -> ce_mode ))
1367
+ if (verify_path_internal (ce -> name , ce -> ce_mode ) == PATH_INVALID )
1353
1368
return error (_ ("invalid path '%s'" ), ce -> name );
1354
1369
1355
1370
if (!skip_df_check &&
0 commit comments