summaryrefslogtreecommitdiff
path: root/builtin-ls-files.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-01-29 06:44:27 (GMT)
committerJunio C Hamano <gitster@pobox.com>2008-02-05 08:44:10 (GMT)
commitd089ebaad5315325d67db30176df1bbd7754fda9 (patch)
tree2c3c9e8d7a66de215e409d223ae69bc2c1e39a04 /builtin-ls-files.c
parent7a2078b4b00fb1c5d7b0bf8155778f79377b8f2f (diff)
downloadgit-d089ebaad5315325d67db30176df1bbd7754fda9.zip
git-d089ebaad5315325d67db30176df1bbd7754fda9.tar.gz
git-d089ebaad5315325d67db30176df1bbd7754fda9.tar.bz2
setup: sanitize absolute and funny paths in get_pathspec()
The prefix_path() function called from get_pathspec() is responsible for translating list of user-supplied pathspecs to list of pathspecs that is relative to the root of the work tree. When working inside a subdirectory, the user-supplied pathspecs are taken to be relative to the current subdirectory. Among special path components in pathspecs, we used to accept and interpret only "." ("the directory", meaning a no-op) and ".." ("up one level") at the beginning. Everything else was passed through as-is. For example, if you are in Documentation/ directory of the project, you can name Documentation/howto/maintain-git.txt as: howto/maintain-git.txt ../Documentation/howto/maitain-git.txt ../././Documentation/howto/maitain-git.txt but not as: howto/./maintain-git.txt $(pwd)/howto/maintain-git.txt This patch updates prefix_path() in several ways: - If the pathspec is not absolute, prefix (i.e. the current subdirectory relative to the root of the work tree, with terminating slash, if not empty) and the pathspec is concatenated first and used in the next step. Otherwise, that absolute pathspec is used in the next step. - Then special path components "." (no-op) and ".." (up one level) are interpreted to simplify the path. It is an error to have too many ".." to cause the intermediate result to step outside of the input to this step. - If the original pathspec was not absolute, the result from the previous step is the resulting "sanitized" pathspec. Otherwise, the result from the previous step is still absolute, and it is an error if it does not begin with the directory that corresponds to the root of the work tree. The directory is stripped away from the result and is returned. - In any case, the resulting pathspec in the array get_pathspec() returns omit the ones that caused errors. With this patch, the last two examples also behave as expected. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-ls-files.c')
-rw-r--r--builtin-ls-files.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index 0f0ab2d..3801cf4 100644
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
@@ -572,8 +572,17 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
pathspec = get_pathspec(prefix, argv + i);
/* Verify that the pathspec matches the prefix */
- if (pathspec)
+ if (pathspec) {
+ if (argc != i) {
+ int cnt;
+ for (cnt = 0; pathspec[cnt]; cnt++)
+ ;
+ if (cnt != (argc - i))
+ exit(1); /* error message already given */
+ }
prefix = verify_pathspec(prefix);
+ } else if (argc != i)
+ exit(1); /* error message already given */
/* Treat unmatching pathspec elements as errors */
if (pathspec && error_unmatch) {