From: Junio C Hamano Date: Tue, 29 Jan 2008 02:03:00 GMT Subject: Re: [RFH/PATCH] prefix_path(): disallow absolute paths Message-ID: <7vd4rls817.fsf@gitster.siamese.dyndns.org> In-Reply-To: <7vwspts9vj.fsf@gitster.siamese.dyndns.org> This is on top of the original "sanitary_path_copy()" patch to fix the case where the user gives `pwd`/foobar (or just `pwd`) to us. After making sure the leading part matches with the work tree, we need to strip that to make the result relative to the work tree. setup.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/setup.c b/setup.c index 156d417..0688e7b 100644 --- a/setup.c +++ b/setup.c @@ -110,6 +110,9 @@ const char *prefix_path(const char *prefix, int len, const char *path) free(sanitized); return NULL; } + sanitized += len; + if (*sanitized == '/') + sanitized++; } return sanitized; } @@ -201,6 +204,8 @@ const char **get_pathspec(const char *prefix, const char **pathspec) src++; } *dst = NULL; + if (!*pathspec) + return NULL; return pathspec; }