Merge branch 'explicit_bzero_in_strings' into 'master'

explicit_bzero implementation proposal

See merge request redox-os/relibc!337
This commit is contained in:
Jeremy Soller
2023-03-22 21:58:50 +00:00
2 changed files with 13 additions and 0 deletions
+9
View File
@@ -1,6 +1,7 @@
//! strings implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/strings.h.html
use core::ptr;
use core::arch;
use crate::{
header::{ctype, string},
@@ -22,6 +23,14 @@ pub unsafe extern "C" fn bzero(dst: *mut c_void, n: size_t) {
ptr::write_bytes(dst as *mut u8, 0, n);
}
#[no_mangle]
pub unsafe extern "C" fn explicit_bzero(s: *mut c_void, n: size_t) {
for i in 0..n {
*(s as *mut u8).add(i) = 0 as u8;
}
arch::asm!("");
}
#[no_mangle]
pub extern "C" fn ffs(i: c_int) -> c_int {
if i == 0 {
+4
View File
@@ -40,4 +40,8 @@ int main(void) {
char* str = "hihih";
assert(index(str, 'i') == str + 1);
assert(rindex(str, 'i') == str + 3);
char buf[] = "password";
explicit_bzero(buf, sizeof(buf));
assert(buf[0] == 0);
}