fix use-after-free when recv a file#686
Merged
Merged
Conversation
Reviewer's GuideCopied received file data into a local std::string and passed it to the detached thread to prevent use-after-free. Sequence diagram for safe file data handling in detached threadsequenceDiagram
participant UdpData
participant Thread
participant RecvFile
UdpData->>UdpData: Receive file data (ptr)
UdpData->>UdpData: Copy ptr to local string (data)
UdpData->>Thread: Start detached thread with data
Thread->>RecvFile: Call RecvEntry(coreThread, pal, data, packetno)
Class diagram for updated UdpData::RecvPalFile methodclassDiagram
class UdpData {
+void RecvPalFile()
}
class RecvFile {
+static void RecvEntry(CoreThread* coreThread, PPalInfo pal, string data, int packetno)
}
UdpData ..> RecvFile : calls RecvEntry in thread
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @lidaobing - I've reviewed your changes - here's some feedback:
- Consider moving
datainto the thread (e.g. usingstd::move(data)) to avoid an extra copy when spawning the detached thread. - Wrap the call to
RecvFile::RecvEntryinside a try/catch within the detached thread to prevent unexpected exceptions from calling std::terminate.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider moving `data` into the thread (e.g. using `std::move(data)`) to avoid an extra copy when spawning the detached thread.
- Wrap the call to `RecvFile::RecvEntry` inside a try/catch within the detached thread to prevent unexpected exceptions from calling std::terminate.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #686 +/- ##
==========================================
- Coverage 52.38% 52.37% -0.02%
==========================================
Files 64 64
Lines 8599 8601 +2
==========================================
Hits 4505 4505
- Misses 4094 4096 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
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.
Summary by Sourcery
Bug Fixes: