Commit cb17630b75dbdc502c21da8e73641fa932bc8c6b

Edward Thomson 2019-12-14T06:59:19

Merge pull request #5338 from pks-t/pks/patch-null-arithmetic patch_parse: fix undefined behaviour due to arithmetic on NULL pointers

diff --git a/src/patch_parse.c b/src/patch_parse.c
index 7e2cc63..9d089ad 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -1025,13 +1025,17 @@ static int check_filenames(git_patch_parsed *patch)
 	/* Prefer the rename filenames as they are unambiguous and unprefixed */
 	if (patch->rename_old_path)
 		patch->base.delta->old_file.path = patch->rename_old_path;
-	else
+	else if (prefixed_old)
 		patch->base.delta->old_file.path = prefixed_old + old_prefixlen;
+	else
+		patch->base.delta->old_file.path = NULL;
 
 	if (patch->rename_new_path)
 		patch->base.delta->new_file.path = patch->rename_new_path;
-	else
+	else if (prefixed_new)
 		patch->base.delta->new_file.path = prefixed_new + new_prefixlen;
+	else
+		patch->base.delta->new_file.path = NULL;
 
 	if (!patch->base.delta->old_file.path &&
 	    !patch->base.delta->new_file.path)