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

(RFC) rust: mark extern "C" ffi functions as unsafe - v4 #6276

Closed
wants to merge 3 commits into from

Conversation

jasonish
Copy link
Member

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.

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.
@suricata-qa
Copy link

Information:

field test baseline %
tlpr1_stats_chk
.flow.mgr.rows_maxlen 470 539 87.2%
Pipeline 3618

@jasonish jasonish closed this Jul 27, 2021
@jasonish jasonish deleted the rust/unsafe-ffi/v4 branch August 23, 2021 18:18
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
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants