@@ -762,86 +762,19 @@ void git_index_entry__init_from_stat(
762
762
entry -> file_size = st -> st_size ;
763
763
}
764
764
765
- /*
766
- * We fundamentally don't like some paths: we don't want
767
- * dot or dot-dot anywhere, and for obvious reasons don't
768
- * want to recurse into ".git" either.
769
- *
770
- * Also, we don't want double slashes or slashes at the
771
- * end that can make pathnames ambiguous.
772
- */
773
- static int verify_dotfile (const char * rest )
774
- {
775
- /*
776
- * The first character was '.', but that
777
- * has already been discarded, we now test
778
- * the rest.
779
- */
780
-
781
- /* "." is not allowed */
782
- if (* rest == '\0' || * rest == '/' )
783
- return -1 ;
784
-
785
- switch (* rest ) {
786
- /*
787
- * ".git" followed by NUL or slash is bad. This
788
- * shares the path end test with the ".." case.
789
- */
790
- case 'g' :
791
- case 'G' :
792
- if (rest [1 ] != 'i' && rest [1 ] != 'I' )
793
- break ;
794
- if (rest [2 ] != 't' && rest [2 ] != 'T' )
795
- break ;
796
- rest += 2 ;
797
- /* fallthrough */
798
- case '.' :
799
- if (rest [1 ] == '\0' || rest [1 ] == '/' )
800
- return -1 ;
801
- }
802
- return 0 ;
803
- }
804
-
805
- static int verify_component (char c , const char * rest )
806
- {
807
- if ((c == '.' && verify_dotfile (rest )) < 0 || c == '/' || c == '\0' ) {
808
- giterr_set (GITERR_INDEX , "Invalid path component in index: '%c%s'" , c , rest );
809
- return -1 ;
810
- }
811
- return 0 ;
812
- }
813
-
814
- static int verify_path (const char * path )
815
- {
816
- char c ;
817
-
818
- /* TODO: should we check this? */
819
- /*
820
- if (has_dos_drive_prefix(path))
821
- return -1;
822
- */
823
-
824
- c = * path ++ ;
825
- if (verify_component (c , path ) < 0 )
826
- return -1 ;
827
-
828
- while ((c = * path ++ ) != '\0' ) {
829
- if (c == '/' ) {
830
- c = * path ++ ;
831
- if (verify_component (c , path ) < 0 )
832
- return -1 ;
833
- }
834
- }
835
- return 0 ;
836
- }
837
-
838
- static int index_entry_create (git_index_entry * * out , const char * path )
765
+ static int index_entry_create (
766
+ git_index_entry * * out ,
767
+ git_repository * repo ,
768
+ const char * path )
839
769
{
840
770
size_t pathlen = strlen (path );
841
771
struct entry_internal * entry ;
842
772
843
- if (verify_path (path ) < 0 )
773
+ if (!git_path_isvalid (repo , path ,
774
+ GIT_PATH_REJECT_DEFAULTS | GIT_PATH_REJECT_DOT_GIT )) {
775
+ giterr_set (GITERR_INDEX , "Invalid path: '%s'" , path );
844
776
return -1 ;
777
+ }
845
778
846
779
entry = git__calloc (sizeof (struct entry_internal ) + pathlen + 1 , 1 );
847
780
GITERR_CHECK_ALLOC (entry );
@@ -855,7 +788,9 @@ static int index_entry_create(git_index_entry **out, const char *path)
855
788
}
856
789
857
790
static int index_entry_init (
858
- git_index_entry * * entry_out , git_index * index , const char * rel_path )
791
+ git_index_entry * * entry_out ,
792
+ git_index * index ,
793
+ const char * rel_path )
859
794
{
860
795
int error = 0 ;
861
796
git_index_entry * entry = NULL ;
@@ -867,7 +802,7 @@ static int index_entry_init(
867
802
"Could not initialize index entry. "
868
803
"Index is not backed up by an existing repository." );
869
804
870
- if (index_entry_create (& entry , rel_path ) < 0 )
805
+ if (index_entry_create (& entry , INDEX_OWNER ( index ), rel_path ) < 0 )
871
806
return -1 ;
872
807
873
808
/* write the blob to disk and get the oid and stat info */
@@ -933,7 +868,10 @@ static void index_entry_cpy(git_index_entry *tgt, const git_index_entry *src)
933
868
tgt -> path = tgt_path ; /* reset to existing path data */
934
869
}
935
870
936
- static int index_entry_dup (git_index_entry * * out , const git_index_entry * src )
871
+ static int index_entry_dup (
872
+ git_index_entry * * out ,
873
+ git_repository * repo ,
874
+ const git_index_entry * src )
937
875
{
938
876
git_index_entry * entry ;
939
877
@@ -942,7 +880,7 @@ static int index_entry_dup(git_index_entry **out, const git_index_entry *src)
942
880
return 0 ;
943
881
}
944
882
945
- if (index_entry_create (& entry , src -> path ) < 0 )
883
+ if (index_entry_create (& entry , repo , src -> path ) < 0 )
946
884
return -1 ;
947
885
948
886
index_entry_cpy (entry , src );
@@ -1211,7 +1149,7 @@ int git_index_add(git_index *index, const git_index_entry *source_entry)
1211
1149
return -1 ;
1212
1150
}
1213
1151
1214
- if ((ret = index_entry_dup (& entry , source_entry )) < 0 ||
1152
+ if ((ret = index_entry_dup (& entry , INDEX_OWNER ( index ), source_entry )) < 0 ||
1215
1153
(ret = index_insert (index , & entry , 1 )) < 0 )
1216
1154
return ret ;
1217
1155
@@ -1331,9 +1269,9 @@ int git_index_conflict_add(git_index *index,
1331
1269
1332
1270
assert (index );
1333
1271
1334
- if ((ret = index_entry_dup (& entries [0 ], ancestor_entry )) < 0 ||
1335
- (ret = index_entry_dup (& entries [1 ], our_entry )) < 0 ||
1336
- (ret = index_entry_dup (& entries [2 ], their_entry )) < 0 )
1272
+ if ((ret = index_entry_dup (& entries [0 ], INDEX_OWNER ( index ), ancestor_entry )) < 0 ||
1273
+ (ret = index_entry_dup (& entries [1 ], INDEX_OWNER ( index ), our_entry )) < 0 ||
1274
+ (ret = index_entry_dup (& entries [2 ], INDEX_OWNER ( index ), their_entry )) < 0 )
1337
1275
goto on_error ;
1338
1276
1339
1277
for (i = 0 ; i < 3 ; i ++ ) {
@@ -1850,7 +1788,10 @@ static int read_conflict_names(git_index *index, const char *buffer, size_t size
1850
1788
}
1851
1789
1852
1790
static size_t read_entry (
1853
- git_index_entry * * out , const void * buffer , size_t buffer_size )
1791
+ git_index_entry * * out ,
1792
+ git_index * index ,
1793
+ const void * buffer ,
1794
+ size_t buffer_size )
1854
1795
{
1855
1796
size_t path_length , entry_size ;
1856
1797
const char * path_ptr ;
@@ -1914,7 +1855,7 @@ static size_t read_entry(
1914
1855
1915
1856
entry .path = (char * )path_ptr ;
1916
1857
1917
- if (index_entry_dup (out , & entry ) < 0 )
1858
+ if (index_entry_dup (out , INDEX_OWNER ( index ), & entry ) < 0 )
1918
1859
return 0 ;
1919
1860
1920
1861
return entry_size ;
@@ -2015,7 +1956,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
2015
1956
/* Parse all the entries */
2016
1957
for (i = 0 ; i < header .entry_count && buffer_size > INDEX_FOOTER_SIZE ; ++ i ) {
2017
1958
git_index_entry * entry ;
2018
- size_t entry_size = read_entry (& entry , buffer , buffer_size );
1959
+ size_t entry_size = read_entry (& entry , index , buffer , buffer_size );
2019
1960
2020
1961
/* 0 bytes read means an object corruption */
2021
1962
if (entry_size == 0 ) {
@@ -2376,6 +2317,7 @@ int git_index_entry_stage(const git_index_entry *entry)
2376
2317
}
2377
2318
2378
2319
typedef struct read_tree_data {
2320
+ git_index * index ;
2379
2321
git_vector * old_entries ;
2380
2322
git_vector * new_entries ;
2381
2323
git_vector_cmp entry_cmp ;
@@ -2396,7 +2338,7 @@ static int read_tree_cb(
2396
2338
if (git_buf_joinpath (& path , root , tentry -> filename ) < 0 )
2397
2339
return -1 ;
2398
2340
2399
- if (index_entry_create (& entry , path .ptr ) < 0 )
2341
+ if (index_entry_create (& entry , INDEX_OWNER ( data -> index ), path .ptr ) < 0 )
2400
2342
return -1 ;
2401
2343
2402
2344
entry -> mode = tentry -> attr ;
@@ -2437,6 +2379,7 @@ int git_index_read_tree(git_index *index, const git_tree *tree)
2437
2379
2438
2380
git_vector_set_cmp (& entries , index -> entries ._cmp ); /* match sort */
2439
2381
2382
+ data .index = index ;
2440
2383
data .old_entries = & index -> entries ;
2441
2384
data .new_entries = & entries ;
2442
2385
data .entry_cmp = index -> entries_search ;
@@ -2556,7 +2499,7 @@ int git_index_add_all(
2556
2499
break ;
2557
2500
2558
2501
/* make the new entry to insert */
2559
- if ((error = index_entry_dup (& entry , wd )) < 0 )
2502
+ if ((error = index_entry_dup (& entry , INDEX_OWNER ( index ), wd )) < 0 )
2560
2503
break ;
2561
2504
2562
2505
entry -> id = blobid ;
0 commit comments