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

function setup_pfioc_states() has a potential multiply with overflow issue without pre-checking #116

Open
cicilzx opened this issue Oct 17, 2024 · 0 comments

Comments

@cicilzx
Copy link

cicilzx commented Oct 17, 2024

Hi, I'm developing a fuzzer to test the safe abstraction, and I found a multiply with overflow when calling function src/lib/setup_pfioc_states(). Below is a test case:

#[allow(warnings, unused, non_snake_case)]
#[test]
fn test_setup_pfioc_states_8Cv9V() {
    let num_states = 2241257528;
    let _ = setup_pfioc_states(num_states);
}

Output:

thread 'test_setup_pfioc_states_8Cv9V' panicked at src/lib.rs:563:27:
attempt to multiply with overflow
stack backtrace:
   0: rust_begin_unwind
             at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/std/src/panicking.rs:652:5
   1: core::panicking::panic_fmt
             at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/core/src/panicking.rs:72:14
   2: core::panicking::panic_const::panic_const_mul_overflow
             at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/core/src/panicking.rs:179:21
   3: pfctl::setup_pfioc_states
             at ./src/lib.rs:563:27
   4: pfctl::test_setup_pfioc_states_8Cv9V
             at ./src/lib.rs:646:13
   5: pfctl::test_setup_pfioc_states_8Cv9V::{{closure}}
             at ./src/lib.rs:629:35
   6: core::ops::function::FnOnce::call_once
             at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/core/src/ops/function.rs:250:5
   7: core::ops::function::FnOnce::call_once
             at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I think checking the scope of pfioc_states after unsafe block would make the external API more robust.

let mut pfioc_states = unsafe { mem::zeroed::<ffi::pfvar::pfioc_states>() };

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

No branches or pull requests

1 participant