Skip to content

Commit cb17630

Browse files
authored
Merge pull request libgit2#5338 from pks-t/pks/patch-null-arithmetic
patch_parse: fix undefined behaviour due to arithmetic on NULL pointers
2 parents e1d7747 + c6f9ad7 commit cb17630

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/patch_parse.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,13 +1025,17 @@ static int check_filenames(git_patch_parsed *patch)
10251025
/* Prefer the rename filenames as they are unambiguous and unprefixed */
10261026
if (patch->rename_old_path)
10271027
patch->base.delta->old_file.path = patch->rename_old_path;
1028-
else
1028+
else if (prefixed_old)
10291029
patch->base.delta->old_file.path = prefixed_old + old_prefixlen;
1030+
else
1031+
patch->base.delta->old_file.path = NULL;
10301032

10311033
if (patch->rename_new_path)
10321034
patch->base.delta->new_file.path = patch->rename_new_path;
1033-
else
1035+
else if (prefixed_new)
10341036
patch->base.delta->new_file.path = prefixed_new + new_prefixlen;
1037+
else
1038+
patch->base.delta->new_file.path = NULL;
10351039

10361040
if (!patch->base.delta->old_file.path &&
10371041
!patch->base.delta->new_file.path)

0 commit comments

Comments
 (0)