Skip to content

patch_parse: fix segfault when header path contains whitespace only#5298

Merged
ethomson merged 1 commit into
libgit2:masterfrom
pks-t:pks/patch-whitespace-only-paths
Nov 6, 2019
Merged

patch_parse: fix segfault when header path contains whitespace only#5298
ethomson merged 1 commit into
libgit2:masterfrom
pks-t:pks/patch-whitespace-only-paths

Conversation

@pks-t

@pks-t pks-t commented Nov 6, 2019

Copy link
Copy Markdown
Member

When parsing header paths from a patch, we reject any patches with empty
paths as malformed patches. We perform the check whether a path is empty
before sanitizing it, though, which may lead to a path becoming empty
after the check, e.g. if we have trimmed whitespace. This may lead to a
segfault later when any part of our patching logic actually references
such a path, which may then be a NULL pointer.

Fix the issue by performing the check after sanitizing. Add tests to
catch the issue as they would have produced a segfault previosuly.

When parsing header paths from a patch, we reject any patches with empty
paths as malformed patches. We perform the check whether a path is empty
before sanitizing it, though, which may lead to a path becoming empty
after the check, e.g. if we have trimmed whitespace. This may lead to a
segfault later when any part of our patching logic actually references
such a path, which may then be a `NULL` pointer.

Fix the issue by performing the check after sanitizing. Add tests to
catch the issue as they would have produced a segfault previosuly.
@ethomson

ethomson commented Nov 6, 2019

Copy link
Copy Markdown
Member

Nice one. 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