Merge pull request #270 from carlosmn/valgrind Two memory access fixes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
diff --git a/src/blob.c b/src/blob.c
index ceb2c9c..d18aa5c 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);
diff --git a/src/odb_pack.c b/src/odb_pack.c
index 8a88a0b..2328f52 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;