Skip to content

fix use-after-free when recv a file#686

Merged
lidaobing merged 1 commit into
mainfrom
bf_use_after_free_when_recv_file
Jul 20, 2025
Merged

fix use-after-free when recv a file#686
lidaobing merged 1 commit into
mainfrom
bf_use_after_free_when_recv_file

Conversation

@lidaobing

@lidaobing lidaobing commented Jul 20, 2025

Copy link
Copy Markdown
Member

Summary by Sourcery

Bug Fixes:

  • Copy the file data into a string before detaching the thread to avoid dangling pointer access.

@sourcery-ai

sourcery-ai Bot commented Jul 20, 2025

Copy link
Copy Markdown

Reviewer's Guide

Copied 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 thread

sequenceDiagram
    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)
Loading

Class diagram for updated UdpData::RecvPalFile method

classDiagram
    class UdpData {
        +void RecvPalFile()
    }
    class RecvFile {
        +static void RecvEntry(CoreThread* coreThread, PPalInfo pal, string data, int packetno)
    }
    UdpData ..> RecvFile : calls RecvEntry in thread
Loading

File-Level Changes

Change Details Files
Capture file payload in a std::string before thread launch to avoid dangling pointer
  • Added string data = ptr; prior to spawning the thread
  • Replaced passing raw pointer ptr with the new data string to the thread invocation
src/iptux-core/internal/UdpData.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @lidaobing - I've reviewed your changes - here's some feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@github-actions

Copy link
Copy Markdown

Test Results

66 tests  ±0   66 ✅ ±0   3s ⏱️ -1s
32 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit a9f4417. ± Comparison against base commit e554e30.

@codecov

codecov Bot commented Jul 20, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 52.37%. Comparing base (e554e30) to head (a9f4417).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/iptux-core/internal/UdpData.cpp 0.00% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lidaobing lidaobing merged commit 6e816d1 into main Jul 20, 2025
16 of 18 checks passed
@lidaobing lidaobing deleted the bf_use_after_free_when_recv_file branch July 20, 2025 23:17
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.

1 participant