Skip to content

Commit

Permalink
fix: undefined behaviour in metrics receiver when passed a boolean va…
Browse files Browse the repository at this point in the history
…lue with more than lsb set
  • Loading branch information
sighphyre committed Nov 27, 2024
1 parent 64ee3e8 commit 5904404
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions java-engine/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

# Ignore Gradle build output directory
build
hs_err*.log
7 changes: 6 additions & 1 deletion yggdrasilffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,13 @@ pub unsafe extern "C" fn free_response(response_ptr: *mut c_char) {
pub unsafe extern "C" fn count_toggle(
engine_ptr: *mut c_void,
toggle_name_ptr: *const c_char,
enabled: bool,
enabled: u8,
) -> *const c_char {
// Java/C# may pass other set bits but Rust expects a boolean to only have a single bit set
// so we need to check exactly that the last bit it 1 or 0 and use the boolean value accordingly

let enabled = enabled & 1 == 1;

let result: Result<Option<()>, FFIError> = (|| {
let engine = get_engine(engine_ptr)?;
let toggle_name = get_str(toggle_name_ptr)?;
Expand Down

0 comments on commit 5904404

Please sign in to comment.