Skip to content

Commit

Permalink
fix: unsafe code
Browse files Browse the repository at this point in the history
  • Loading branch information
nponsard committed Sep 25, 2023
1 parent 95f21ec commit 51a534c
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 19 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pkcs11/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ env_logger = { default-features = false, version = "0.10.0", features = [
"auto-color",
"humantime",
] }
libc = { default-features = false, version = "0.2.80" }
cryptoki-sys = "0.1.6"
log = "0.4.19"
merge = { features = [
Expand Down
8 changes: 0 additions & 8 deletions pkcs11/src/api/generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,6 @@ pub extern "C" fn C_GenerateKeyPair(
)
};

public_template.iter().for_each(|attr| {
trace!(
"Public template: {:?}, {:?}",
attr.type_(),
attr.val_bytes()
);
});

let keys = match session.generate_key(&private_template, Some(&public_template), &mech) {
Ok(keys) => keys,
Err(e) => {
Expand Down
10 changes: 4 additions & 6 deletions pkcs11/src/api/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,11 @@ pub extern "C" fn C_FindObjects(
};
trace!("C_FindObjects() objects: {:?}", objects);

let returned_count = objects.len();

unsafe {
std::ptr::copy_nonoverlapping(
objects.as_ptr(),
phObject,
objects.len().min(ulMaxObjectCount as usize),
);
std::ptr::write(pulObjectCount, objects.len() as CK_ULONG);
std::ptr::copy_nonoverlapping(objects.as_ptr(), phObject, returned_count);
std::ptr::write(pulObjectCount, returned_count as CK_ULONG);
}

cryptoki_sys::CKR_OK
Expand Down
2 changes: 1 addition & 1 deletion pkcs11/src/api/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub extern "C" fn C_OpenSession(
trace!("C_OpenSession() created session: {:?}", session);

unsafe {
*phSession = session;
std::ptr::write(phSession, session);
}

cryptoki_sys::CKR_OK
Expand Down
3 changes: 1 addition & 2 deletions pkcs11/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ lazy_static! {
pub static ref DEVICE: Device = match config::initialization::initialize_configuration() {
Ok(config) => config,
Err(e) => {
eprintln!("Error initializing configuration: {:?}", e);
unsafe { libc::exit(1) }
panic!("Error initializing configuration: {:?}", e);
}
};
pub static ref SESSION_MANAGER : Arc<Mutex<SessionManager>> = Arc::new(Mutex::new(SessionManager::new()));
Expand Down

0 comments on commit 51a534c

Please sign in to comment.