Commit 7e53e8ce454b31e933b7ad6df90ffdfdc678cd81

Edward Thomson 2017-03-22T20:26:52

Merge pull request #4167 from pks-t/pks/ci-fixes Coverity fixes

diff --git a/src/blame_git.c b/src/blame_git.c
index 96785c7..735b62d 100644
--- a/src/blame_git.c
+++ b/src/blame_git.c
@@ -478,14 +478,15 @@ cleanup:
  * The blobs of origin and porigin exactly match, so everything origin is
  * suspected for can be blamed on the parent.
  */
-static void pass_whole_blame(git_blame *blame,
+static int pass_whole_blame(git_blame *blame,
 		git_blame__origin *origin, git_blame__origin *porigin)
 {
 	git_blame__entry *e;
 
-	if (!porigin->blob)
-		git_object_lookup((git_object**)&porigin->blob, blame->repository,
-				git_blob_id(origin->blob), GIT_OBJ_BLOB);
+	if (!porigin->blob &&
+	    git_object_lookup((git_object**)&porigin->blob, blame->repository,
+				git_blob_id(origin->blob), GIT_OBJ_BLOB) < 0)
+		return -1;
 	for (e=blame->ent; e; e=e->next) {
 		if (!same_suspect(e->suspect, origin))
 			continue;
@@ -493,6 +494,8 @@ static void pass_whole_blame(git_blame *blame,
 		origin_decref(e->suspect);
 		e->suspect = porigin;
 	}
+
+	return 0;
 }
 
 static int pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt)
@@ -543,7 +546,8 @@ static int pass_blame(git_blame *blame, git_blame__origin *origin, uint32_t opt)
 		}
 		if (porigin->blob && origin->blob &&
 		    !git_oid_cmp(git_blob_id(porigin->blob), git_blob_id(origin->blob))) {
-			pass_whole_blame(blame, origin, porigin);
+			error = pass_whole_blame(blame, origin, porigin);
+				goto finish;
 			origin_decref(porigin);
 			goto finish;
 		}
diff --git a/src/config_file.c b/src/config_file.c
index cd5727c..50c5a3d 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -1041,8 +1041,9 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
 	GITERR_CHECK_ALLOC_ADD(&alloc_len, base_name_len, quoted_len);
 	GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2);
 
-	git_buf_grow(&buf, alloc_len);
-	git_buf_printf(&buf, "%s.", base_name);
+	if (git_buf_grow(&buf, alloc_len) < 0 ||
+	    git_buf_printf(&buf, "%s.", base_name) < 0)
+		goto end_parse;
 
 	rpos = 0;
 
@@ -1082,6 +1083,11 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
 	} while (line + rpos < last_quote);
 
 end_parse:
+	if (git_buf_oom(&buf)) {
+		git_buf_free(&buf);
+		return -1;
+	}
+
 	if (line[rpos] != '"' || line[rpos + 1] != ']') {
 		set_parse_error(reader, rpos, "Unexpected text after closing quotes");
 		git_buf_free(&buf);
diff --git a/src/diff_parse.c b/src/diff_parse.c
index 9391568..24a8a4a 100644
--- a/src/diff_parse.c
+++ b/src/diff_parse.c
@@ -44,7 +44,11 @@ static git_diff_parsed *diff_parsed_alloc(void)
 	diff->base.patch_fn = git_patch_parsed_from_diff;
 	diff->base.free_fn = diff_parsed_free;
 
-	git_diff_init_options(&diff->base.opts, GIT_DIFF_OPTIONS_VERSION);
+	if (git_diff_init_options(&diff->base.opts, GIT_DIFF_OPTIONS_VERSION) < 0) {
+		git__free(&diff);
+		return NULL;
+	}
+
 	diff->base.opts.flags &= ~GIT_DIFF_IGNORE_CASE;
 
 	git_pool_init(&diff->base.pool, 1);
diff --git a/src/odb_pack.c b/src/odb_pack.c
index b80d033..51770a8 100644
--- a/src/odb_pack.c
+++ b/src/odb_pack.c
@@ -428,7 +428,7 @@ static int pack_backend__read_prefix(
 			git_oid_cpy(out_oid, short_oid);
 	} else {
 		struct git_pack_entry e;
-		git_rawobj raw;
+		git_rawobj raw = {NULL};
 
 		if ((error = pack_entry_find_prefix(
 				&e, (struct pack_backend *)backend, short_oid, len)) == 0 &&
diff --git a/src/openssl_stream.c b/src/openssl_stream.c
index bb9b32c..c0a9c3c 100644
--- a/src/openssl_stream.c
+++ b/src/openssl_stream.c
@@ -66,7 +66,7 @@ static void shutdown_ssl_locking(void)
 	CRYPTO_set_locking_callback(NULL);
 
 	for (i = 0; i < num_locks; ++i)
-		git_mutex_free(openssl_locks);
+		git_mutex_free(&openssl_locks[i]);
 	git__free(openssl_locks);
 }
 
diff --git a/src/patch_parse.c b/src/patch_parse.c
index d993c03..0a9edcd 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -444,9 +444,9 @@ static int parse_header_git(
 				goto done;
 
 			parse_advance_ws(ctx);
-			parse_advance_expected_str(ctx, "\n");
 
-			if (ctx->line_len > 0) {
+			if (parse_advance_expected_str(ctx, "\n") < 0 ||
+			    ctx->line_len > 0) {
 				error = parse_err("trailing data at line %"PRIuZ, ctx->line_num);
 				goto done;
 			}