summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2007-07-03 22:56:59 -0700
committerJunio C Hamano <gitster@pobox.com>2007-07-03 22:56:59 -0700
commite2b1accc59ab5d682d71fd801ebe959c3e871488 (patch)
treefe7ff753798566ed54d2ac8af556ccc58cb4f471 /sha1_file.c
parentf6b78c6eb626d477b252d39ef2801d4670675a2b (diff)
parented5f07a6fdc5653e24a5bd6c216d12bc878496bd (diff)
downloadgit-e2b1accc59ab5d682d71fd801ebe959c3e871488.tar.gz
Merge branch 'maint'
* maint: Document -<n> for git-format-patch glossary: add 'reflog' diff --no-index: fix --name-status with added files Don't smash stack when $GIT_ALTERNATE_OBJECT_DIRECTORIES is too long
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/sha1_file.c b/sha1_file.c
index f2b1ae0325..1efd9ae19a 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -352,10 +352,14 @@ static void read_info_alternates(const char * relative_base, int depth)
char *map;
size_t mapsz;
struct stat st;
- char path[PATH_MAX];
+ const char alt_file_name[] = "info/alternates";
+ /* Given that relative_base is no longer than PATH_MAX,
+ ensure that "path" has enough space to append "/", the
+ file name, "info/alternates", and a trailing NUL. */
+ char path[PATH_MAX + 1 + sizeof alt_file_name];
int fd;
- sprintf(path, "%s/info/alternates", relative_base);
+ sprintf(path, "%s/%s", relative_base, alt_file_name);
fd = open(path, O_RDONLY);
if (fd < 0)
return;
@@ -836,7 +840,10 @@ void install_packed_git(struct packed_git *pack)
static void prepare_packed_git_one(char *objdir, int local)
{
- char path[PATH_MAX];
+ /* Ensure that this buffer is large enough so that we can
+ append "/pack/" without clobbering the stack even if
+ strlen(objdir) were PATH_MAX. */
+ char path[PATH_MAX + 1 + 4 + 1 + 1];
int len;
DIR *dir;
struct dirent *de;
@@ -858,6 +865,9 @@ static void prepare_packed_git_one(char *objdir, int local)
if (!has_extension(de->d_name, ".idx"))
continue;
+ if (len + namelen + 1 > sizeof(path))
+ continue;
+
/* Don't reopen a pack we already have. */
strcpy(path + len, de->d_name);
for (p = packed_git; p; p = p->next) {