Conversation
acceptfilter() returns &CStr referencing a stack-local accept_filter_arg struct. The returned reference outlives the stack frame, causing a use-after-free: any access to the returned CStr reads freed stack memory. Return an owned CString instead. This requires updating the trait signature in both freebsd/net.rs and netbsd/net.rs. Fixes #233 Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
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
Fixes a use-after-free in
acceptfilter()on FreeBSD/NetBSD.Problem
acceptfilter()returns&CStrthat references a stack-localaccept_filter_arg. Thefrom_raw_partscreates a slice borrowing data on the stack, but the function returns a reference with lifetime tied to&self. When the function returns, the stack frame is freed and the reference becomes dangling.Fix
Return an owned
CStringinstead of&CStr. Updated trait signatures infreebsd/net.rsandnetbsd/net.rsto match.Behind unstable feature
acceptfilter(issue rust-lang#121891).Fixes #233