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 ft_open_ex() has a potential panic issue without pre-checking #83

Open
cicilzx opened this issue Oct 17, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@cicilzx
Copy link

cicilzx commented Oct 17, 2024

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

#[allow(warnings, unused, non_snake_case)]
#[test]
fn test_ft_open_ex_muIpv() {
    let arg: String = String::from("\0\u{e}.r");
    let flag: u32 = 3590405307;
    let _ = ft_open_ex(arg.as_str(), flag);
}

Output:

thread 'test_ft_open_ex_muIpv' panicked at src/lib.rs:2008:48:
called `Result::unwrap()` on an `Err` value: NulError(0, [0, 14, 46, 114])
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::result::unwrap_failed
             at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/core/src/result.rs:1658:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/core/src/result.rs:1081:23
   4: libftd2xx::ft_open_ex
             at ./src/lib.rs:2008:20
   5: libftd2xx::test_ft_open_ex_muIpv
             at ./src/lib.rs:2504:13
   6: libftd2xx::test_ft_open_ex_muIpv::{{closure}}
             at ./src/lib.rs:2480:27
   7: core::ops::function::FnOnce::call_once
             at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/core/src/ops/function.rs:250:5
   8: 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 arg when calling the ffi::CString would make the external API more robust.

let cstr_arg = std::ffi::CString::new(arg).unwrap();

@newAM
Copy link
Member

newAM commented Oct 17, 2024

Good catch, thank you!

My laptop and desktop are all packed up since I'm moving, but I will get to this in a couple weeks!

@newAM newAM added the bug Something isn't working label Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants