Skip to content
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

Fix use-after-free violation in NetlinkException #295

Merged
merged 2 commits into from
Jun 21, 2024
Merged

Conversation

abeltrano
Copy link
Contributor

Type

  • Bug fix
  • Feature addition
  • Feature update
  • Documentation
  • Build Infrastructure

Side Effects

  • Breaking change
  • Non-functional change

Goals

Technical Details

When creating an instance of NetlinkException, and temporary instance of NetlinkErrorCategory is passed to the std::error_code constructor. However, std::error_code expects a const reference and does not make a copy of it. Since we passed a temporary, this later results in a use-after-free bug which would cause either a crash (good case) or weird results when reading the error category information from the NetlinkException later. This is solved by using a singleton NetlinkErrorCategory and passing this instance to the std::error_code constructor.

  • Add function to generate singleton instance of NetlinkErrorCategory.
  • Pass valid, long-lived instance of NetlinkErrorCategory to std:;error_code constructor when creating a NetlinkException.
  • Add unit test to ensure NetlinkException doesn't cause a crash or trigger AddressSanitizer.

Test Results

  • All unit tests pass.

Reviewer Focus

  • None

Future Work

  • None

Checklist

  • Build target all compiles cleanly.
  • clang-format and clang-tidy deltas produced no new output.
  • Newly added functions include doxygen-style comment block.

@abeltrano abeltrano requested a review from a team as a code owner June 20, 2024 22:09
@abeltrano abeltrano changed the title Fix use-after-free in NetlinkException Fix use-after-free violation in NetlinkException Jun 20, 2024
@abeltrano abeltrano merged commit 090673f into develop Jun 21, 2024
5 checks passed
@abeltrano abeltrano deleted the nlexceptbug branch June 21, 2024 01:01
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.

Bug: NetlinkException causes use-after-free violation
1 participant