Skip to content

Soundness Fix for the Trigger struct as well as added unsafe call for the QuickTune struct since the type is not yet fully represented with rusts type system, and the fact the C struct is a union that we do not enforce.#48

Merged
QuantumEF merged 2 commits into
masterfrom
struct_soundness_fix
Mar 17, 2026

Conversation

@QuantumEF

Copy link
Copy Markdown
Collaborator

The trigger struct wav converted into the C ABI representation as 2 as casts to different pointer types. The direct conversion was invalid as the Rust struct was not repr C.

While the QuickTune struct is Repr C the C repr is actually a union. So this must be accounted for. The functions that utilize QuickTine have been marked as unsafe for now.

… the QuickTune struct since the type is not yet fully represented with rusts type system, and the fact the C struct is a union that we do not enforce.
@QuantumEF QuantumEF enabled auto-merge (squash) March 14, 2026 20:29
@QuantumEF QuantumEF requested a review from TroyNeubauer March 14, 2026 22:07

@TroyNeubauer TroyNeubauer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice catch!

Comment thread src/types/backend.rs
Comment on lines +45 to +46
/// Precautionary test since the From<Backend> impl has 2 casts as I believe the [bladerf_backend] type is not consistent across platforms.
fn backend_enum_conversion_test() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you elaborate on this? What kind of failure mode are you trying to guard against?

The variants in the header file have ordinals 0..=100 so we shouldnt have any issues with representing that in our #[repr(i32)] enum Backend { ... } (even if enum bladerf_backend is sized differently on different platforms)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I put this in primarily as a sanity check if there are future code changes. I don't think it should be needed, but because of the double as cast, I was thinking about going through and adding some sort of brute force tests to anything that is repr(C). I did not really put a lot of though into this specific item, it was more of an addition so I would not have to think

Comment thread src/bladerf.rs
@QuantumEF

Copy link
Copy Markdown
Collaborator Author

I have double checked and this change does work

@TroyNeubauer TroyNeubauer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Makes sense. Ill look into fixing CI

@QuantumEF QuantumEF merged commit 9d6ed35 into master Mar 17, 2026
5 of 7 checks passed
@QuantumEF QuantumEF deleted the struct_soundness_fix branch March 17, 2026 02:55
@QuantumEF

Copy link
Copy Markdown
Collaborator Author

Makes sense. Ill look into fixing CI

Ok, thank you!

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.

3 participants