X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=entry.c;h=004182c99d27a6a5825d2429f9104fc7a8f1dc80;hb=d0af3734f14410e9c297aa08bf46fdb153a25ccb;hp=d3e86c722a6663a65f69b73621f57aa6331a5e5b;hpb=00d3278c8534a8244ae3447189401111e017fd5d;p=git.git diff --git a/entry.c b/entry.c index d3e86c722..004182c99 100644 --- a/entry.c +++ b/entry.c @@ -175,6 +175,23 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout return 0; } +/* + * This is like 'lstat()', except it refuses to follow symlinks + * in the path, after skipping "skiplen". + */ +static int check_path(const char *path, int len, struct stat *st, int skiplen) +{ + const char *slash = path + len; + + while (path < slash && *slash != '/') + slash--; + if (!has_dirs_only_path(path, slash - path, skiplen)) { + errno = ENOENT; + return -1; + } + return lstat(path, st); +} + int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath) { static char path[PATH_MAX + 1]; @@ -188,8 +205,8 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t strcpy(path + len, ce->name); len += ce_namelen(ce); - if (!lstat(path, &st)) { - unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID); + if (!check_path(path, len, &st, state->base_dir_len)) { + unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE); if (!changed) return 0; if (!state->force) {