Commit d427f9522d439535acf5f3e56ad8fa0ab79b0ed3

Iliyas Jorio 2022-03-13T17:40:54

diff_delta_format_path: handle null filename This fixes a crash in test cases test_diff_parse__new_file_with_space_and_regenerate_patch and test_diff_parse__delete_file_with_space_and_regenerate_patch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
diff --git a/src/libgit2/diff_print.c b/src/libgit2/diff_print.c
index 03d25b0..a910362 100644
--- a/src/libgit2/diff_print.c
+++ b/src/libgit2/diff_print.c
@@ -316,6 +316,12 @@ static int diff_print_oid_range(
 static int diff_delta_format_path(
 	git_str *out, const char *prefix, const char *filename)
 {
+	if (!filename)
+	{
+		/* don't prefix "/dev/null" */
+		return git_str_puts(out, "/dev/null");
+	}
+
 	if (git_str_joinpath(out, prefix, filename) < 0)
 		return -1;