Skip to content

Commit 4530a85

Browse files
SyntevoAlexgitster
authored andcommitted
real_path_if_valid(): remove unsafe API
This commit continues the work started with previous commit. Signed-off-by: Alexandr Miloslavskiy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3d7747e commit 4530a85

File tree

6 files changed

+14
-26
lines changed

6 files changed

+14
-26
lines changed

abspath.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,6 @@ char *strbuf_realpath(struct strbuf *resolved, const char *path,
202202
return retval;
203203
}
204204

205-
/*
206-
* Resolve `path` into an absolute, cleaned-up path. The return value
207-
* comes from a shared buffer.
208-
*/
209-
const char *real_path_if_valid(const char *path)
210-
{
211-
static struct strbuf realpath = STRBUF_INIT;
212-
return strbuf_realpath(&realpath, path, 0);
213-
}
214-
215205
char *real_pathdup(const char *path, int die_on_error)
216206
{
217207
struct strbuf realpath = STRBUF_INIT;

cache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,6 @@ static inline int is_absolute_path(const char *path)
13141314
int is_directory(const char *);
13151315
char *strbuf_realpath(struct strbuf *resolved, const char *path,
13161316
int die_on_error);
1317-
const char *real_path_if_valid(const char *path);
13181317
char *real_pathdup(const char *path, int die_on_error);
13191318
const char *absolute_path(const char *path);
13201319
char *absolute_pathdup(const char *path);

setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ static dev_t get_device_or_die(const char *path, const char *prefix, int prefix_
886886

887887
/*
888888
* A "string_list_each_func_t" function that canonicalizes an entry
889-
* from GIT_CEILING_DIRECTORIES using real_path_if_valid(), or
889+
* from GIT_CEILING_DIRECTORIES using real_pathdup(), or
890890
* discards it if unusable. The presence of an empty entry in
891891
* GIT_CEILING_DIRECTORIES turns off canonicalization for all
892892
* subsequent entries.

sha1-file.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -676,20 +676,15 @@ void add_to_alternates_memory(const char *reference)
676676
char *compute_alternate_path(const char *path, struct strbuf *err)
677677
{
678678
char *ref_git = NULL;
679-
const char *repo, *ref_git_s;
679+
const char *repo;
680680
int seen_error = 0;
681681

682-
ref_git_s = real_path_if_valid(path);
683-
if (!ref_git_s) {
682+
ref_git = real_pathdup(path, 0);
683+
if (!ref_git) {
684684
seen_error = 1;
685685
strbuf_addf(err, _("path '%s' does not exist"), path);
686686
goto out;
687-
} else
688-
/*
689-
* Beware: read_gitfile(), real_path() and mkpath()
690-
* return static buffer
691-
*/
692-
ref_git = xstrdup(ref_git_s);
687+
}
693688

694689
repo = read_gitfile(ref_git);
695690
if (!repo)

submodule.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,7 +2173,7 @@ const char *get_superproject_working_tree(void)
21732173
static struct strbuf realpath = STRBUF_INIT;
21742174
struct child_process cp = CHILD_PROCESS_INIT;
21752175
struct strbuf sb = STRBUF_INIT;
2176-
const char *one_up = real_path_if_valid("../");
2176+
struct strbuf one_up = STRBUF_INIT;
21772177
const char *cwd = xgetcwd();
21782178
const char *ret = NULL;
21792179
const char *subpath;
@@ -2188,10 +2188,11 @@ const char *get_superproject_working_tree(void)
21882188
*/
21892189
return NULL;
21902190

2191-
if (!one_up)
2191+
if (!strbuf_realpath(&one_up, "../", 0))
21922192
return NULL;
21932193

2194-
subpath = relative_path(cwd, one_up, &sb);
2194+
subpath = relative_path(cwd, one_up.buf, &sb);
2195+
strbuf_release(&one_up);
21952196

21962197
prepare_submodule_repo_env(&cp.env_array);
21972198
argv_array_pop(&cp.env_array);

worktree.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,20 @@ struct worktree *find_worktree(struct worktree **list,
226226

227227
struct worktree *find_worktree_by_path(struct worktree **list, const char *p)
228228
{
229+
struct strbuf wt_path = STRBUF_INIT;
229230
char *path = real_pathdup(p, 0);
230231

231232
if (!path)
232233
return NULL;
233234
for (; *list; list++) {
234-
const char *wt_path = real_path_if_valid((*list)->path);
235+
if (!strbuf_realpath(&wt_path, (*list)->path, 0))
236+
continue;
235237

236-
if (wt_path && !fspathcmp(path, wt_path))
238+
if (!fspathcmp(path, wt_path.buf))
237239
break;
238240
}
239241
free(path);
242+
strbuf_release(&wt_path);
240243
return *list;
241244
}
242245

0 commit comments

Comments
 (0)