Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

filter: only close filter if it's been initialized correctly#4196

Merged
ethomson merged 1 commit intolibgit2:masterlibgit2/libgit2:masterfrom
pks-t:pks/filter-segfaultpks-t/libgit2:pks/filter-segfaultCopy head branch name to clipboard
Apr 11, 2017
Merged

filter: only close filter if it's been initialized correctly#4196
ethomson merged 1 commit intolibgit2:masterlibgit2/libgit2:masterfrom
pks-t:pks/filter-segfaultpks-t/libgit2:pks/filter-segfaultCopy head branch name to clipboard

Conversation

@pks-t
Copy link
Member

@pks-t pks-t commented Apr 7, 2017

In the function git_filter_list_stream_data, we initialize, write and
subesquently close the stream which should receive content processed by
the filter. While we skip writing to the stream if its initialization
failed, we still try to close it unconditionally -- even if the
initialization failed, where the stream might not be set at all, leading
us to segfault.

Semantics in this code is not really clear. The function handling the
same logic for files instead of data seems to do the right thing here in
only closing the stream when initialization succeeded. When stepping
back a bit, this is only reasonable: if a stream cannot be initialized,
the caller would not expect it to be closed again. So actually, both
callers of stream_list_init fail to do so. The data streaming function
will always close the stream and the file streaming function will not
close the stream if writing to it has failed.

The fix is thus two-fold:

  • callers of stream_list_init now close the stream iff it has been
    initialized
  • stream_list_init now closes the lastly initialized stream if
    the current stream in the chain failed to initialize

Add a test which segfaulted previous to these changes.

In the function `git_filter_list_stream_data`, we initialize, write and
subesquently close the stream which should receive content processed by
the filter. While we skip writing to the stream if its initialization
failed, we still try to close it unconditionally -- even if the
initialization failed, where the stream might not be set at all, leading
us to segfault.

Semantics in this code is not really clear. The function handling the
same logic for files instead of data seems to do the right thing here in
only closing the stream when initialization succeeded. When stepping
back a bit, this is only reasonable: if a stream cannot be initialized,
the caller would not expect it to be closed again. So actually, both
callers of `stream_list_init` fail to do so. The data streaming function
will always close the stream and the file streaming function will not
close the stream if writing to it has failed.

The fix is thus two-fold:

- callers of `stream_list_init` now close the stream iff it has been
  initialized
- `stream_list_init` now closes the lastly initialized stream if
  the current stream in the chain failed to initialize

Add a test which segfaulted previous to these changes.
@pks-t
Copy link
Member Author

pks-t commented Apr 7, 2017

This extends the incomplete fix provided in #3659

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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.