Skip to content

Commit a86ed75

Browse files
committed
Merge branch 'rs/make-verify-path-really-verify-again'
Recent sparse-index work broke safety against attempts to add paths with trailing slashes to the index, which has been corrected. * rs/make-verify-path-really-verify-again: read-cache: let verify_path() reject trailing dir separators again read-cache: add verify_path_internal() t3905: show failure to ignore sub-repo
2 parents 092228e + c8ad9d0 commit a86ed75

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

read-cache.c

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,19 @@ struct cache_entry *make_empty_transient_cache_entry(size_t len,
849849
return xcalloc(1, cache_entry_size(len));
850850
}
851851

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+
852865
struct cache_entry *make_cache_entry(struct index_state *istate,
853866
unsigned int mode,
854867
const struct object_id *oid,
@@ -859,7 +872,7 @@ struct cache_entry *make_cache_entry(struct index_state *istate,
859872
struct cache_entry *ce, *ret;
860873
int len;
861874

862-
if (!verify_path(path, mode)) {
875+
if (verify_path_internal(path, mode) == PATH_INVALID) {
863876
error(_("invalid path '%s'"), path);
864877
return NULL;
865878
}
@@ -993,60 +1006,62 @@ static int verify_dotfile(const char *rest, unsigned mode)
9931006
return 1;
9941007
}
9951008

996-
int verify_path(const char *path, unsigned mode)
1009+
static enum verify_path_result verify_path_internal(const char *path,
1010+
unsigned mode)
9971011
{
9981012
char c = 0;
9991013

10001014
if (has_dos_drive_prefix(path))
1001-
return 0;
1015+
return PATH_INVALID;
10021016

10031017
if (!is_valid_path(path))
1004-
return 0;
1018+
return PATH_INVALID;
10051019

10061020
goto inside;
10071021
for (;;) {
10081022
if (!c)
1009-
return 1;
1023+
return PATH_OK;
10101024
if (is_dir_sep(c)) {
10111025
inside:
10121026
if (protect_hfs) {
10131027

10141028
if (is_hfs_dotgit(path))
1015-
return 0;
1029+
return PATH_INVALID;
10161030
if (S_ISLNK(mode)) {
10171031
if (is_hfs_dotgitmodules(path))
1018-
return 0;
1032+
return PATH_INVALID;
10191033
}
10201034
}
10211035
if (protect_ntfs) {
10221036
#if defined GIT_WINDOWS_NATIVE || defined __CYGWIN__
10231037
if (c == '\\')
1024-
return 0;
1038+
return PATH_INVALID;
10251039
#endif
10261040
if (is_ntfs_dotgit(path))
1027-
return 0;
1041+
return PATH_INVALID;
10281042
if (S_ISLNK(mode)) {
10291043
if (is_ntfs_dotgitmodules(path))
1030-
return 0;
1044+
return PATH_INVALID;
10311045
}
10321046
}
10331047

10341048
c = *path++;
10351049
if ((c == '.' && !verify_dotfile(path, mode)) ||
10361050
is_dir_sep(c))
1037-
return 0;
1051+
return PATH_INVALID;
10381052
/*
10391053
* allow terminating directory separators for
10401054
* sparse directory entries.
10411055
*/
10421056
if (c == '\0')
1043-
return S_ISDIR(mode);
1057+
return S_ISDIR(mode) ? PATH_DIR_WITH_SEP :
1058+
PATH_INVALID;
10441059
} else if (c == '\\' && protect_ntfs) {
10451060
if (is_ntfs_dotgit(path))
1046-
return 0;
1061+
return PATH_INVALID;
10471062
if (S_ISLNK(mode)) {
10481063
if (is_ntfs_dotgitmodules(path))
1049-
return 0;
1064+
return PATH_INVALID;
10501065
}
10511066
}
10521067

@@ -1349,7 +1364,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
13491364

13501365
if (!ok_to_add)
13511366
return -1;
1352-
if (!verify_path(ce->name, ce->ce_mode))
1367+
if (verify_path_internal(ce->name, ce->ce_mode) == PATH_INVALID)
13531368
return error(_("invalid path '%s'"), ce->name);
13541369

13551370
if (!skip_df_check &&

t/t3905-stash-include-untracked.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,4 +422,10 @@ test_expect_success 'stash show --{include,only}-untracked on stashes without un
422422
test_must_be_empty actual
423423
'
424424

425+
test_expect_success 'stash -u ignores sub-repository' '
426+
test_when_finished "rm -rf sub-repo" &&
427+
git init sub-repo &&
428+
git stash -u
429+
'
430+
425431
test_done

0 commit comments

Comments
 (0)