rust-lang / rust-lang/rust-clippy
Suggestion: detect calling printf-style C APIs in dodgy ways
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Specifically, APIS like:
extern "C" {
fn foo(some: args, fmt: *const c_char, ...);
}
where they're variadic C functions where the last non-variadic argument is a *const c_char.
If you call it as foo(x, some_cstr.as_ptr()) that's almost always a format string vulnerability. Instead you should use a format arg like b"%s\0".as_ptr().cast() and then pass the string as the first entry in the variadic list.
It's might be enough just to detect the case where there's no variadic args? I don't really know if it's worth trying to do the c-style check that the format args are correct -- these APIs get so little use.
I don't know how doable this is as a lint, but I've seen the mistake a lot.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files, tests, or existing lint entry points are named. Start by determining how rust-clippy represents variadic extern "C" declarations and calls, then scope detection to a non-variadic *const c_char last parameter and absent variadic arguments. Done means lint behavior and tests covering the proposed call patterns.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- security, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100