mirror of https://github.com/git/git.git
real_path_if_valid(): remove unsafe API
This commit continues the work started with previous commit. Signed-off-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
3d7747e318
commit
4530a85b4c
10
abspath.c
10
abspath.c
|
@ -202,16 +202,6 @@ error_out:
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Resolve `path` into an absolute, cleaned-up path. The return value
|
|
||||||
* comes from a shared buffer.
|
|
||||||
*/
|
|
||||||
const char *real_path_if_valid(const char *path)
|
|
||||||
{
|
|
||||||
static struct strbuf realpath = STRBUF_INIT;
|
|
||||||
return strbuf_realpath(&realpath, path, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *real_pathdup(const char *path, int die_on_error)
|
char *real_pathdup(const char *path, int die_on_error)
|
||||||
{
|
{
|
||||||
struct strbuf realpath = STRBUF_INIT;
|
struct strbuf realpath = STRBUF_INIT;
|
||||||
|
|
1
cache.h
1
cache.h
|
@ -1314,7 +1314,6 @@ static inline int is_absolute_path(const char *path)
|
||||||
int is_directory(const char *);
|
int is_directory(const char *);
|
||||||
char *strbuf_realpath(struct strbuf *resolved, const char *path,
|
char *strbuf_realpath(struct strbuf *resolved, const char *path,
|
||||||
int die_on_error);
|
int die_on_error);
|
||||||
const char *real_path_if_valid(const char *path);
|
|
||||||
char *real_pathdup(const char *path, int die_on_error);
|
char *real_pathdup(const char *path, int die_on_error);
|
||||||
const char *absolute_path(const char *path);
|
const char *absolute_path(const char *path);
|
||||||
char *absolute_pathdup(const char *path);
|
char *absolute_pathdup(const char *path);
|
||||||
|
|
2
setup.c
2
setup.c
|
@ -886,7 +886,7 @@ static dev_t get_device_or_die(const char *path, const char *prefix, int prefix_
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A "string_list_each_func_t" function that canonicalizes an entry
|
* A "string_list_each_func_t" function that canonicalizes an entry
|
||||||
* from GIT_CEILING_DIRECTORIES using real_path_if_valid(), or
|
* from GIT_CEILING_DIRECTORIES using real_pathdup(), or
|
||||||
* discards it if unusable. The presence of an empty entry in
|
* discards it if unusable. The presence of an empty entry in
|
||||||
* GIT_CEILING_DIRECTORIES turns off canonicalization for all
|
* GIT_CEILING_DIRECTORIES turns off canonicalization for all
|
||||||
* subsequent entries.
|
* subsequent entries.
|
||||||
|
|
13
sha1-file.c
13
sha1-file.c
|
@ -676,20 +676,15 @@ void add_to_alternates_memory(const char *reference)
|
||||||
char *compute_alternate_path(const char *path, struct strbuf *err)
|
char *compute_alternate_path(const char *path, struct strbuf *err)
|
||||||
{
|
{
|
||||||
char *ref_git = NULL;
|
char *ref_git = NULL;
|
||||||
const char *repo, *ref_git_s;
|
const char *repo;
|
||||||
int seen_error = 0;
|
int seen_error = 0;
|
||||||
|
|
||||||
ref_git_s = real_path_if_valid(path);
|
ref_git = real_pathdup(path, 0);
|
||||||
if (!ref_git_s) {
|
if (!ref_git) {
|
||||||
seen_error = 1;
|
seen_error = 1;
|
||||||
strbuf_addf(err, _("path '%s' does not exist"), path);
|
strbuf_addf(err, _("path '%s' does not exist"), path);
|
||||||
goto out;
|
goto out;
|
||||||
} else
|
}
|
||||||
/*
|
|
||||||
* Beware: read_gitfile(), real_path() and mkpath()
|
|
||||||
* return static buffer
|
|
||||||
*/
|
|
||||||
ref_git = xstrdup(ref_git_s);
|
|
||||||
|
|
||||||
repo = read_gitfile(ref_git);
|
repo = read_gitfile(ref_git);
|
||||||
if (!repo)
|
if (!repo)
|
||||||
|
|
|
@ -2173,7 +2173,7 @@ const char *get_superproject_working_tree(void)
|
||||||
static struct strbuf realpath = STRBUF_INIT;
|
static struct strbuf realpath = STRBUF_INIT;
|
||||||
struct child_process cp = CHILD_PROCESS_INIT;
|
struct child_process cp = CHILD_PROCESS_INIT;
|
||||||
struct strbuf sb = STRBUF_INIT;
|
struct strbuf sb = STRBUF_INIT;
|
||||||
const char *one_up = real_path_if_valid("../");
|
struct strbuf one_up = STRBUF_INIT;
|
||||||
const char *cwd = xgetcwd();
|
const char *cwd = xgetcwd();
|
||||||
const char *ret = NULL;
|
const char *ret = NULL;
|
||||||
const char *subpath;
|
const char *subpath;
|
||||||
|
@ -2188,10 +2188,11 @@ const char *get_superproject_working_tree(void)
|
||||||
*/
|
*/
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!one_up)
|
if (!strbuf_realpath(&one_up, "../", 0))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
subpath = relative_path(cwd, one_up, &sb);
|
subpath = relative_path(cwd, one_up.buf, &sb);
|
||||||
|
strbuf_release(&one_up);
|
||||||
|
|
||||||
prepare_submodule_repo_env(&cp.env_array);
|
prepare_submodule_repo_env(&cp.env_array);
|
||||||
argv_array_pop(&cp.env_array);
|
argv_array_pop(&cp.env_array);
|
||||||
|
|
|
@ -226,17 +226,20 @@ struct worktree *find_worktree(struct worktree **list,
|
||||||
|
|
||||||
struct worktree *find_worktree_by_path(struct worktree **list, const char *p)
|
struct worktree *find_worktree_by_path(struct worktree **list, const char *p)
|
||||||
{
|
{
|
||||||
|
struct strbuf wt_path = STRBUF_INIT;
|
||||||
char *path = real_pathdup(p, 0);
|
char *path = real_pathdup(p, 0);
|
||||||
|
|
||||||
if (!path)
|
if (!path)
|
||||||
return NULL;
|
return NULL;
|
||||||
for (; *list; list++) {
|
for (; *list; list++) {
|
||||||
const char *wt_path = real_path_if_valid((*list)->path);
|
if (!strbuf_realpath(&wt_path, (*list)->path, 0))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (wt_path && !fspathcmp(path, wt_path))
|
if (!fspathcmp(path, wt_path.buf))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free(path);
|
free(path);
|
||||||
|
strbuf_release(&wt_path);
|
||||||
return *list;
|
return *list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue