Skip to content

Commit

Permalink
Implement secure_getenv.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Oct 4, 2023
1 parent 5c69b85 commit 59a9ef2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions c-scape/src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ unsafe extern "C" fn getenv(key: *const c_char) -> *mut c_char {
_getenv(key_bytes)
}

#[no_mangle]
unsafe extern "C" fn secure_getenv(key: *const c_char) -> *mut c_char {
//libc!(libc::secure_getenv(key));

if rustix::runtime::linux_secure() {
return null_mut();
}

let key = CStr::from_ptr(key.cast());
let key_bytes = key.to_bytes();

_getenv(key_bytes)
}

pub(crate) unsafe fn _getenv(key_bytes: &[u8]) -> *mut c_char {
let mut ptr = environ;
loop {
Expand Down

0 comments on commit 59a9ef2

Please sign in to comment.