erickt / erickt/rust-zmq

function `has()` would panic without pre-checking

Open
#409 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
997
Forks
212
PR merge metrics
No merged PRs in 30d

Description

Hi, I'm developing a fuzzer to test the safe abstraction, and I fonnd a panic bug when calling function `has()`. Bellow is a test case:
```rust
#[allow(warnings, unused, non_snake_case)]
#[test]
fn test_has_3lk9v() {
let capability = String::from("\0:");
let _ = has(capability.as_str());
}
```
Output:
```
thread 'test_has_3lk9v' panicked at src/lib.rs:1203:47:
called `Result::unwrap()` on an `Err` value: NulError(0, [0, 58])
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::unwrap
at /rustc/d84b9037541f45dc2c52a41d723265af211c0497/library/core/src/result.rs:1081:23
4: zmq::has
at ./src/lib.rs:1203:17
5: zmq::test_has_3lk9v
at ./src/lib.rs:1367:13
6: zmq::test_has_3lk9v::{{closure}}
at ./src/lib.rs:1354:20
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 that `&str` is legal before calling `ffi::CString` would make the API more robust.

Contributor guide

Open the contributing guide

Research direction

Start in src/lib.rs around has() at line 1203 and inspect the test area around the provided test case near line 1367. Run the NUL-containing input and add regression coverage; done means has() no longer panics for that input and the test suite passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, networking
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.