From cdb6f9bf5e77b6e83d4bdc6cd75c31d0d3377800 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 20 Jun 2011 17:34:01 +0200 Subject: [PATCH 1/2] Allocate enough memory for the terminator in commit parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also allow space for the null-terminator when allocating the buffer in packfile_unpack_compressed. Up to now, the last newline had served as a terminator, but 858ef372 searches for a double-newline and exposes the problem. Signed-off-by: Carlos Martín Nieto --- src/odb_pack.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/odb_pack.c b/src/odb_pack.c index 8a88a0baa..2328f527c 100644 --- a/src/odb_pack.c +++ b/src/odb_pack.c @@ -1246,7 +1246,8 @@ static int packfile_unpack_compressed( z_stream stream; unsigned char *buffer, *in; - buffer = git__malloc(size); + buffer = git__malloc(size + 1); + memset(buffer, 0x0, size + 1); memset(&stream, 0, sizeof(stream)); stream.next_out = buffer; From 4cea2f0369238008100e00a5b2bc74eded24b6ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 20 Jun 2011 17:53:21 +0200 Subject: [PATCH 2/2] Stat files with full pathnames MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Call gitfo_lstat with the full pathname instead of the relative one, which fails in case the current working directory is different from the workdir. Signed-off-by: Carlos Martín Nieto --- src/blob.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/blob.c b/src/blob.c index ceb2c9c44..d18aa5c36 100644 --- a/src/blob.c +++ b/src/blob.c @@ -88,15 +88,19 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat git_odb_stream *stream; struct stat st; - gitfo_lstat(path, &st); - - islnk = S_ISLNK(st.st_mode); - if (repo->path_workdir == NULL) return git__throw(GIT_ENOTFOUND, "Failed to create blob. (No working directory found)"); git__joinpath(full_path, repo->path_workdir, path); + error = gitfo_lstat(full_path, &st); + if (error < 0) { + return git__throw(GIT_EOSERR, "Failed to stat blob. %s", strerror(errno)); + } + + islnk = S_ISLNK(st.st_mode); + + if (!islnk) { if ((fd = gitfo_open(full_path, O_RDONLY)) < 0) return git__throw(GIT_ENOTFOUND, "Failed to create blob. Could not open '%s'", full_path);