Skip to content

temporary_cstring_as_ptr doesn't catch UAF when Result is assigned to a variable #4375

Closed
@alex

Description

@alex

Source:

use std::ffi::CString;
use libc::c_char;

extern "C" {
    fn foo(data: *const c_char);
}

pub fn bar(v: &[u8]) {
    let cstr = CString::new(v);
    unsafe {
        foo(cstr.unwrap().as_ptr())
    }
}

clippy doesn't complain about this, even though it's equally dangerous to foo(CString::new(v).unwrap().as_ptr()). It should complain about this formulation as well.

Tested with clippy on play.rust-lang.org: 0.0.212 (2019-08-11 72da101)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions