-
Notifications
You must be signed in to change notification settings - Fork 417
Fix lifetimes of outputs for Patch #1141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@weihanglo Would you be able to review this? It's a bit difficult at times to understand the ownership requirements, but I think this is correct. |
weihanglo
approved these changes
Mar 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking with this libgit2 code snippet, it looks correct. At this it should be there when patch is still valid. Thanks!
naseschwarz
pushed a commit
to naseschwarz/gitui
that referenced
this pull request
Mar 18, 2025
git2-rs changed the lifetime of the result of Patch::hunk() to reference the patch struct: rust-lang/git2-rs#1141 Thus, returning a patch struct and a reference into it is flagged by the borrow checker upon move when returning. This patch avoids returning both alltogether by separating retrieving and retrieving the patch.
extrawurst
pushed a commit
to gitui-org/gitui
that referenced
this pull request
Mar 18, 2025
* Bump git2 from 0.20.0 to 0.20.1 Bumps [git2](https://github.com/rust-lang/git2-rs) from 0.20.0 to 0.20.1. - [Changelog](https://github.com/rust-lang/git2-rs/blob/master/CHANGELOG.md) - [Commits](rust-lang/git2-rs@git2-0.20.0...git2-0.20.1) --- updated-dependencies: - dependency-name: git2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Avoid passing reference into struct git2-rs changed the lifetime of the result of Patch::hunk() to reference the patch struct: rust-lang/git2-rs#1141 Thus, returning a patch struct and a reference into it is flagged by the borrow checker upon move when returning. This patch avoids returning both alltogether by separating retrieving and retrieving the patch. --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Naseschwarz <naseschwarz@0x53a.de>
facebook-github-bot
pushed a commit
to facebook/sapling
that referenced
this pull request
May 15, 2025
Summary: # Changelog ## 0.20.2 - 2025-05-05 [0.20.1...0.20.2](rust-lang/git2-rs@git2-0.20.1...git2-0.20.2) ### Added - Added `Status::WT_UNREADABLE`. [#1151](rust-lang/git2-rs#1151) ### Fixed - Added missing codes for `GIT_EDIRECTORY`, `GIT_EMERGECONFLICT`, `GIT_EUNCHANGED`, `GIT_ENOTSUPPORTED`, and `GIT_EREADONLY` to `Error::raw_code`. [#1153](rust-lang/git2-rs#1153) - Fixed missing initialization in `Indexer::new`. [#1160](rust-lang/git2-rs#1160) ## 0.20.1 - 2025-03-17 [0.20.0...0.20.1](rust-lang/git2-rs@git2-0.20.0...git2-0.20.1) ### Added - Added `Repository::branch_upstream_merge()` [#1131](rust-lang/git2-rs#1131) - Added `Index::conflict_get()` [#1134](rust-lang/git2-rs#1134) - Added `Index::conflict_remove()` [#1133](rust-lang/git2-rs#1133) - Added `opts::set_cache_object_limit()` [#1118](rust-lang/git2-rs#1118) - Added `Repo::merge_file_from_index()` and associated `MergeFileOptions` and `MergeFileResult`. [#1062](rust-lang/git2-rs#1062) ### Changed - The `url` dependency minimum raised to 2.5.4 [#1128](rust-lang/git2-rs#1128) - Changed the tracing callback to abort the process if the callback panics instead of randomly detecting the panic in some other function. [#1121](rust-lang/git2-rs#1121) - Credential helper config (loaded with `CredentialHelper::config`) now checks for helpers that start with something that looks like an absolute path, rather than checking for a `/` or `\` anywhere in the helper string (which resolves an issue if the helper had arguments with `/` or `\`). [#1137](rust-lang/git2-rs#1137) ### Fixed - Fixed panic in `Remote::url_bytes` if the url is empty. [#1120](rust-lang/git2-rs#1120) - Fixed incorrect lifetimes on `Patch::delta`, `Patch::hunk`, and `Patch::line_in_hunk`. The return values must not outlive the `Patch`. [#1141](rust-lang/git2-rs#1141) - Bumped requirement to libgit2-sys 0.18.1, which fixes linking of advapi32 on Windows. [#1143](rust-lang/git2-rs#1143) ignore-conflict-markers Reviewed By: JakobDegen Differential Revision: D74659779 fbshipit-source-id: a18bcd8f58bc62c7eedbfa5939a791002e18d7bc
facebook-github-bot
pushed a commit
to facebookincubator/reindeer
that referenced
this pull request
May 15, 2025
Summary: # Changelog ## 0.20.2 - 2025-05-05 [0.20.1...0.20.2](rust-lang/git2-rs@git2-0.20.1...git2-0.20.2) ### Added - Added `Status::WT_UNREADABLE`. [#1151](rust-lang/git2-rs#1151) ### Fixed - Added missing codes for `GIT_EDIRECTORY`, `GIT_EMERGECONFLICT`, `GIT_EUNCHANGED`, `GIT_ENOTSUPPORTED`, and `GIT_EREADONLY` to `Error::raw_code`. [#1153](rust-lang/git2-rs#1153) - Fixed missing initialization in `Indexer::new`. [#1160](rust-lang/git2-rs#1160) ## 0.20.1 - 2025-03-17 [0.20.0...0.20.1](rust-lang/git2-rs@git2-0.20.0...git2-0.20.1) ### Added - Added `Repository::branch_upstream_merge()` [#1131](rust-lang/git2-rs#1131) - Added `Index::conflict_get()` [#1134](rust-lang/git2-rs#1134) - Added `Index::conflict_remove()` [#1133](rust-lang/git2-rs#1133) - Added `opts::set_cache_object_limit()` [#1118](rust-lang/git2-rs#1118) - Added `Repo::merge_file_from_index()` and associated `MergeFileOptions` and `MergeFileResult`. [#1062](rust-lang/git2-rs#1062) ### Changed - The `url` dependency minimum raised to 2.5.4 [#1128](rust-lang/git2-rs#1128) - Changed the tracing callback to abort the process if the callback panics instead of randomly detecting the panic in some other function. [#1121](rust-lang/git2-rs#1121) - Credential helper config (loaded with `CredentialHelper::config`) now checks for helpers that start with something that looks like an absolute path, rather than checking for a `/` or `\` anywhere in the helper string (which resolves an issue if the helper had arguments with `/` or `\`). [#1137](rust-lang/git2-rs#1137) ### Fixed - Fixed panic in `Remote::url_bytes` if the url is empty. [#1120](rust-lang/git2-rs#1120) - Fixed incorrect lifetimes on `Patch::delta`, `Patch::hunk`, and `Patch::line_in_hunk`. The return values must not outlive the `Patch`. [#1141](rust-lang/git2-rs#1141) - Bumped requirement to libgit2-sys 0.18.1, which fixes linking of advapi32 on Windows. [#1143](rust-lang/git2-rs#1143) ignore-conflict-markers Reviewed By: JakobDegen Differential Revision: D74659779 fbshipit-source-id: a18bcd8f58bc62c7eedbfa5939a791002e18d7bc
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes the lifetimes for the functions that return data from a
Patch
. From what I can tell, these are returning data owned by thePatch
object itself. Previously they had lifetimes tied to the values that created thePatch
, but that allows these outputs to outlive the patch, allowing a use-after-free.Note that there was a previous fix here in #523, but I think that was mistake to change these accessor functions. The
Patch
itself still has a lifetime tied to its inputs introduced in #523.Fixes #1135