-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
(RFC) rust: mark extern "C" ffi functions as unsafe - v4 #6276
Closed
Conversation
This file contains 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
Based on the Rust clippy lint that recommends that any public function that dereferences a raw pointer, mark all FFI functions that reference raw pointers with build_slice and cast_pointer as unsafe. This commits starts by removing the unsafe wrapper inside the build_slice and cast_pointer macros then marks all functions that use these macros as unsafe.
Instead use Box::into_raw and from_raw which is more idiomatic for this purpose. For now do this for Rust objects that are opaque to C, but have their life time (allocation and free) managed from C.
As of Rust 1.30 the primary location of c_void is inside std::ffi and not std::os::raw which is for platform specific types.
Information:
|
jasonish
pushed a commit
to jasonish/suricata
that referenced
this pull request
Aug 30, 2023
When comparing IPv6 addresses based on uint32_t chunks, one needs to apply ntohl() conversion to the individual parts, otherwise on little endian systems individual bytes are compared in the wrong order. Avoid this all and leverage memcmp(), it'll short circuit on the first differing byte and its return values tells us which address sorts lower. Bug: OISF#6276
jasonish
pushed a commit
to jasonish/suricata
that referenced
this pull request
Aug 30, 2023
When comparing IPv6 addresses based on uint32_t chunks, one needs to apply ntohl() conversion to the individual parts, otherwise on little endian systems individual bytes are compared in the wrong order. Avoid this all and leverage memcmp(), it'll short circuit on the first differing byte and its return values tells us which address sorts lower. Bug: OISF#6276
jasonish
pushed a commit
to jasonish/suricata
that referenced
this pull request
Aug 30, 2023
When comparing IPv6 addresses based on uint32_t chunks, one needs to apply ntohl() conversion to the individual parts, otherwise on little endian systems individual bytes are compared in the wrong order. Avoid this all and leverage memcmp(), it'll short circuit on the first differing byte and its return values tells us which address sorts lower. Bug: OISF#6276 (cherry picked from commit ccefbd8)
catenacyber
pushed a commit
to catenacyber/suricata
that referenced
this pull request
Sep 6, 2023
When comparing IPv6 addresses based on uint32_t chunks, one needs to apply ntohl() conversion to the individual parts, otherwise on little endian systems individual bytes are compared in the wrong order. Avoid this all and leverage memcmp(), it'll short circuit on the first differing byte and its return values tells us which address sorts lower. Bug: OISF#6276
victorjulien
pushed a commit
to victorjulien/suricata
that referenced
this pull request
Sep 7, 2023
When comparing IPv6 addresses based on uint32_t chunks, one needs to apply ntohl() conversion to the individual parts, otherwise on little endian systems individual bytes are compared in the wrong order. Avoid this all and leverage memcmp(), it'll short circuit on the first differing byte and its return values tells us which address sorts lower. Bug: OISF#6276 (cherry picked from commit 0ddc44f)
victorjulien
pushed a commit
to victorjulien/suricata
that referenced
this pull request
Sep 7, 2023
When comparing IPv6 addresses based on uint32_t chunks, one needs to apply ntohl() conversion to the individual parts, otherwise on little endian systems individual bytes are compared in the wrong order. Avoid this all and leverage memcmp(), it'll short circuit on the first differing byte and its return values tells us which address sorts lower. Bug: OISF#6276 (cherry picked from commit 0ddc44f)
victorjulien
pushed a commit
to victorjulien/suricata
that referenced
this pull request
Sep 7, 2023
When comparing IPv6 addresses based on uint32_t chunks, one needs to apply ntohl() conversion to the individual parts, otherwise on little endian systems individual bytes are compared in the wrong order. Avoid this all and leverage memcmp(), it'll short circuit on the first differing byte and its return values tells us which address sorts lower. Bug: OISF#6276 (cherry picked from commit 0ddc44f)
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.
Rebase of #4666.
In addition to marking extern FFI functions that dereference raw pointers,
also attempt to remove as many transmutes as possible.
For now remove all transmute where a Rust opaque pointer is being passed
back to C for lifetime management.