Commit ff8d2eb15f145640c3b54755b460a06b24f0ca0e

Patrick Steinhardt 2017-03-20T09:34:25

blame_git: check return value of object lookup The function `pass_whole_blame` performs an object lookup but does not check if the lookup actually succeeds. Convert the function to return an error code and check for it in the calling function.

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;
 		}