Commit 579bd556f987d6059cca7f20219140dae23079f3

Stefan Sperling 2020-10-24T13:18:03

prevent a NULL dereference if 'got log -p' runs against a root commit

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/got/got.c b/got/got.c
index 5bfcaac..40ab964 100644
--- a/got/got.c
+++ b/got/got.c
@@ -3297,10 +3297,12 @@ print_patch(struct got_commit_object *commit, struct got_object_id *id,
 		err = got_object_id_str(&id_str2, obj_id2);
 		if (err)
 			goto done;
-		obj_id1 = got_object_commit_get_tree_id(pcommit);
-		err = got_object_id_str(&id_str1, obj_id1);
-		if (err)
-			goto done;
+		if (pcommit) {
+			obj_id1 = got_object_commit_get_tree_id(pcommit);
+			err = got_object_id_str(&id_str1, obj_id1);
+			if (err)
+				goto done;
+		}
 		printf("diff %s %s\n", id_str1 ? id_str1 : "/dev/null", id_str2);
 		err = diff_trees(obj_id1, obj_id2, "", diff_context, 0, repo);
 	}