@@ -220,7 +220,7 @@ static int load_submodule_names(git_strmap *out, git_repository *repo, git_confi
220220 git_config_iterator * iter ;
221221 git_config_entry * entry ;
222222 git_buf buf = GIT_BUF_INIT ;
223- int rval ;
223+ int rval , isvalid ;
224224 int error = 0 ;
225225
226226 if ((error = git_config_iterator_glob_new (& iter , cfg , key )) < 0 )
@@ -232,7 +232,10 @@ static int load_submodule_names(git_strmap *out, git_repository *repo, git_confi
232232 ldot = strrchr (entry -> name , '.' );
233233
234234 git_buf_put (& buf , fdot + 1 , ldot - fdot - 1 );
235- if (!git_submodule_name_is_valid (repo , buf .ptr , 0 ))
235+ isvalid = git_submodule_name_is_valid (repo , buf .ptr , 0 );
236+ if (isvalid < 0 )
237+ return isvalid ;
238+ if (!isvalid )
236239 continue ;
237240
238241 git_strmap_insert (out , entry -> value , git_buf_detach (& buf ), & rval );
@@ -364,11 +367,25 @@ int git_submodule_lookup(
364367
365368int git_submodule_name_is_valid (const git_repository * repo , const char * name , int flags )
366369{
370+ git_buf buf = GIT_BUF_INIT ;
371+ int error , isvalid ;
372+
367373 if (flags == 0 )
368374 flags = GIT_PATH_REJECT_FILESYSTEM_DEFAULTS ;
369375
376+ /* Avoid allocating a new string if we can avoid it */
377+ if (index (name , '\\' )) {
378+ if ((error = git_path_normalize_slashes (& buf , name )) < 0 )
379+ return error ;
380+ } else {
381+ git_buf_attach_notowned (& buf , name , strlen (name ));
382+ }
383+
370384 /* FIXME: Un-consting it to reduce the amount of diff */
371- return git_path_isvalid ((git_repository * )repo , name , flags );
385+ isvalid = git_path_isvalid ((git_repository * )repo , buf .ptr , flags );
386+ git_buf_free (& buf );
387+
388+ return isvalid ;
372389}
373390
374391static void submodule_free_dup (void * sm )
@@ -1571,16 +1588,17 @@ static int submodule_update_head(git_submodule *submodule)
15711588
15721589int git_submodule_reload (git_submodule * sm , int force )
15731590{
1574- int error = 0 ;
1591+ int error = 0 , isvalid ;
15751592 git_config * mods ;
15761593
15771594 GIT_UNUSED (force );
15781595
15791596 assert (sm );
15801597
1581- if (!git_submodule_name_is_valid (sm -> repo , sm -> name , 0 )) {
1598+ isvalid = git_submodule_name_is_valid (sm -> repo , sm -> name , 0 );
1599+ if (isvalid <= 0 ) {
15821600 /* This should come with a warning, but we've no API for that */
1583- return 0 ;
1601+ return isvalid ;
15841602 }
15851603
15861604 if (!git_repository_is_bare (sm -> repo )) {
@@ -1924,7 +1942,7 @@ static int submodule_load_each(const git_config_entry *entry, void *payload)
19241942 git_strmap * map = data -> map ;
19251943 git_buf name = GIT_BUF_INIT ;
19261944 git_submodule * sm ;
1927- int error ;
1945+ int error , isvalid ;
19281946
19291947 if (git__prefixcmp (entry -> name , "submodule." ) != 0 )
19301948 return 0 ;
@@ -1940,8 +1958,9 @@ static int submodule_load_each(const git_config_entry *entry, void *payload)
19401958 if ((error = git_buf_set (& name , namestart , property - namestart - 1 )) < 0 )
19411959 return error ;
19421960
1943- if (!git_path_isvalid (data -> repo , name .ptr , GIT_PATH_REJECT_TRAVERSAL )) {
1944- error = 0 ;
1961+ isvalid = git_submodule_name_is_valid (data -> repo , name .ptr , 0 );
1962+ if (isvalid <= 0 ) {
1963+ error = isvalid ;
19451964 goto done ;
19461965 }
19471966
0 commit comments