aboutsummaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2005-07-05 18:10:59 -0700
committerLinus Torvalds <torvalds@g5.osdl.org>2005-07-05 18:10:59 -0700
commitf17a1b1bec5cef1d39521aac92f94858acda6433 (patch)
tree680718d879623d294b4cdf36bd00d97016b5cc9c /sha1_file.c
parent319aae27567f3ddc40e9083c425f7eaf567006a0 (diff)
downloadgit-f17a1b1bec5cef1d39521aac92f94858acda6433.tar.gz
git-f17a1b1bec5cef1d39521aac92f94858acda6433.tar.xz
Fix up path-cleanup in git_path() properly
GIT_DIR=. ends up being what some of the pack senders use, and we sometimes messed up when cleaning up the path, ie a ".//HEAD" was cleaned up into "/HEAD", not "HEAD" like it should be. We should do some other cleanup, and probably also verify that symlinks don't point to outside the git area.
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 74dc2aab2..bbb749c56 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -104,15 +104,13 @@ char *get_index_file(void)
char *git_path(const char *fmt, ...)
{
- static char pathname[PATH_MAX];
+ static char pathname[PATH_MAX], *ret;
va_list args;
int len;
if (!git_dir)
setup_git_env();
len = strlen(git_dir);
- if (len == 1 && *git_dir == '.')
- len = 0;
if (len > PATH_MAX-100)
return "pad-path";
memcpy(pathname, git_dir, len);
@@ -121,7 +119,15 @@ char *git_path(const char *fmt, ...)
va_start(args, fmt);
vsnprintf(pathname + len, sizeof(pathname) - len, fmt, args);
va_end(args);
- return pathname;
+ ret = pathname;
+
+ /* Clean it up */
+ if (!memcmp(pathname, "./", 2)) {
+ ret += 2;
+ while (*ret == '/')
+ ret++;
+ }
+ return ret;
}
int get_sha1(const char *str, unsigned char *sha1)