Skip to content

patch_parse: fix undefined behaviour due to arithmetic on NULL pointers#5338

Merged
ethomson merged 1 commit into
libgit2:masterfrom
pks-t:pks/patch-null-arithmetic
Dec 13, 2019
Merged

patch_parse: fix undefined behaviour due to arithmetic on NULL pointers#5338
ethomson merged 1 commit into
libgit2:masterfrom
pks-t:pks/patch-null-arithmetic

Conversation

@pks-t
Copy link
Copy Markdown
Member

@pks-t pks-t commented Dec 13, 2019

Doing arithmetic with NULL pointers is undefined behaviour in the C
standard. We do so regardless when parsing patches, as we happily add a
potential prefix length to prefixed paths. While this works out just
fine as the prefix length is always equal to zero in these cases, thus
resulting in another NULL pointer, it still is undefined behaviour and
was pointed out to us by OSSfuzz.

Fix the issue by checking whether paths are NULL, avoiding the
arithmetic if they are.

Doing arithmetic with NULL pointers is undefined behaviour in the C
standard. We do so regardless when parsing patches, as we happily add a
potential prefix length to prefixed paths. While this works out just
fine as the prefix length is always equal to zero in these cases, thus
resulting in another NULL pointer, it still is undefined behaviour and
was pointed out to us by OSSfuzz.

Fix the issue by checking whether paths are NULL, avoiding the
arithmetic if they are.
@ethomson ethomson merged commit cb17630 into libgit2:master Dec 13, 2019
@ethomson
Copy link
Copy Markdown
Member

Nice catch, thanks @pks-t

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants