Re: [PATCH 2/2] setup: Don't dereference in-tree symlinks for absolute paths
- From
Torsten Bögershausen <tboegi@web.de>
- Date
- Jan 26, 2014, 17:19 UTC
- Message-ID
- <52E5439D.7060002@web.de>
- In-Reply-To
- <1390746146-9478-3-git-send-email-martinerikwerner@gmail.com>
On 2014-01-26 15.22, Martin Erik Werner wrote:
Show 35 quoted lines
> The prefix_path_gently() function currently applies real_path to
> everything if given an absolute path, dereferencing symlinks both
> outside and inside the work tree. In order to manipulate symliks in the
> work tree using absolute paths, symlinks should only be dereferenced
> outside the work tree.
>
> Modify prefix_path_gently() to first normalize the path in order to
> make sure path levels are separated by '/', then use this separator to
> check the real path of each level of the path until it has found the
> length that corresponds to the work tree.
>
> For absolute paths, the function did not, nor does now do, any actual
> prefixing, hence we simply remove the path corresponding to the work
> tree and return the remaining in-tree part of the path.
>
> Fixes t0060-82.
>
> Signed-off-by: Martin Erik Werner <martinerikwerner@gmail.com>
> ---
> setup.c | 54 ++++++++++++++++++++++++++++++++-------------------
> t/t0060-path-utils.sh | 2 +-
> 2 files changed, 35 insertions(+), 21 deletions(-)
>
> diff --git a/setup.c b/setup.c
> index 6c3f85f..bec587e 100644
> --- a/setup.c
> +++ b/setup.c
> @@ -22,11 +22,41 @@ char *prefix_path_gently(const char *prefix, int len,
> const char *orig = path;
> char *sanitized;
> if (is_absolute_path(orig)) {
> - const char *temp = real_path(path);
> - sanitized = xmalloc(len + strlen(temp) + 1);
> - strcpy(sanitized, temp);
> + char npath[strlen(path)];Is this portable ? This is variable-length array, isn't it ? Using xmalloc() may be better
Show 5 quoted lines
> if (remaining_prefix) > *remaining_prefix = 0; > + if (normalize_path_copy_len(npath, path, remaining_prefix)) > + return NULL; > + const char *work_tree = get_git_work_tree();
declaration after statements should be avoided (not only here)