Skip to content

patch_parse: fix segfault due to line containing static contents - #5179

Merged
ethomson merged 1 commit into
libgit2:masterfrom
pks-t:pks/patch-parse-free
Jul 20, 2019
Merged

patch_parse: fix segfault due to line containing static contents#5179
ethomson merged 1 commit into
libgit2:masterfrom
pks-t:pks/patch-parse-free

Conversation

@pks-t

@pks-t pks-t commented Jul 20, 2019

Copy link
Copy Markdown
Member

With commit dedf70a (patch_parse: do not depend on parsed buffer's
lifetime, 2019-07-05), all lines of the patch are allocated with
strdup to make lifetime of the parsed patch independent of the buffer
that is currently being parsed. In patch b089328 (patch_parse: ensure
valid patch output with EOFNL, 2019-07-11), we introduced another
code location where we add lines to the parsed patch. But as that one
was implemented via a separate pull request, it wasn't converted to use
strdup, as well. As a consequence, we generate a segfault when trying
to deallocate the potentially static buffer that's now in some of the
lines.

Use git__strdup to fix the issue.


This bug has been introduced due to #5158 and #5159 having bad interactions with each other.

With commit dedf70a (patch_parse: do not depend on parsed buffer's
lifetime, 2019-07-05), all lines of the patch are allocated with
`strdup` to make lifetime of the parsed patch independent of the buffer
that is currently being parsed. In patch b089328 (patch_parse: ensure
valid patch output with EOFNL, 2019-07-11), we introduced another
code location where we add lines to the parsed patch. But as that one
was implemented via a separate pull request, it wasn't converted to use
`strdup`, as well. As a consequence, we generate a segfault when trying
to deallocate the potentially static buffer that's now in some of the
lines.

Use `git__strdup` to fix the issue.
@ethomson

Copy link
Copy Markdown
Member

Oops, nice catch.

@pks-t

pks-t commented Jul 20, 2019

Copy link
Copy Markdown
Member Author

Yeah. Unfortunately this breaks all current test runs, so I'd like to get this in as quick as possible

@ethomson

Copy link
Copy Markdown
Member

Yeah. Unfortunately this breaks all current test runs, so I'd like to get this in as quick as possible

Indeed. I'm going to go ahead and merge it.

@ethomson
ethomson merged commit 1f44079 into libgit2:master Jul 20, 2019
@pks-t

pks-t commented Jul 20, 2019

Copy link
Copy Markdown
Member Author

Thanks a lot for the fast lane! :)

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