Skip to content

Commit 1c16df2

Browse files
committed
Merge branch 'bw/realpath-wo-chdir'
The implementation of "real_path()" was to go there with chdir(2) and call getcwd(3), but this obviously wouldn't be usable in a threaded environment. Rewrite it to manually resolve relative paths including symbolic links in path components. * bw/realpath-wo-chdir: real_path: set errno when max number of symlinks is exceeded real_path: prevent redefinition of MAXSYMLINKS
2 parents 5918bdc + 0b9864a commit 1c16df2

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

abspath.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ static void get_root_part(struct strbuf *resolved, struct strbuf *remaining)
6262
}
6363

6464
/* We allow "recursive" symbolic links. Only within reason, though. */
65-
#define MAXSYMLINKS 5
65+
#ifndef MAXSYMLINKS
66+
#define MAXSYMLINKS 32
67+
#endif
6668

6769
/*
6870
* Return the real path (i.e., absolute path, with symlinks resolved
@@ -139,6 +141,8 @@ char *strbuf_realpath(struct strbuf *resolved, const char *path,
139141
strbuf_reset(&symlink);
140142

141143
if (num_symlinks++ > MAXSYMLINKS) {
144+
errno = ELOOP;
145+
142146
if (die_on_error)
143147
die("More than %d nested symlinks "
144148
"on path '%s'", MAXSYMLINKS, path);

dir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2731,8 +2731,8 @@ void connect_work_tree_and_git_dir(const char *work_tree_, const char *git_dir_)
27312731
{
27322732
struct strbuf file_name = STRBUF_INIT;
27332733
struct strbuf rel_path = STRBUF_INIT;
2734-
char *git_dir = xstrdup(real_path(git_dir_));
2735-
char *work_tree = xstrdup(real_path(work_tree_));
2734+
char *git_dir = real_pathdup(git_dir_);
2735+
char *work_tree = real_pathdup(work_tree_);
27362736

27372737
/* Update gitfile */
27382738
strbuf_addf(&file_name, "%s/.git", work_tree);

0 commit comments

Comments
 (0)