Skip to content

Commit 4c7b3a1

Browse files
committed
keyutils-raw: move capacity computation outside the unsafe block
1 parent 8c1f5c8 commit 4c7b3a1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

keyutils-raw/src/functions.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ pub fn keyctl_setperm(id: KeyringSerial, perm: KeyPermissions) -> Result<()> {
214214
}
215215

216216
pub fn keyctl_describe(id: KeyringSerial, mut buffer: Option<Out<[u8]>>) -> Result<usize> {
217+
let capacity = buffer.as_mut().map_or(0, |b| b.len());
217218
unsafe {
218-
let capacity = buffer.as_mut().map_or(0, |b| b.len());
219219
keyctl!(
220220
libc::KEYCTL_DESCRIBE,
221221
id.get(),
@@ -259,8 +259,8 @@ pub fn keyctl_search(
259259
}
260260

261261
pub fn keyctl_read(id: KeyringSerial, mut buffer: Option<Out<[u8]>>) -> Result<usize> {
262+
let capacity = buffer.as_mut().map_or(0, |b| b.len());
262263
unsafe {
263-
let capacity = buffer.as_mut().map_or(0, |b| b.len());
264264
keyctl!(
265265
libc::KEYCTL_READ,
266266
id.get(),
@@ -317,8 +317,8 @@ pub fn keyctl_assume_authority(key: Option<KeyringSerial>) -> Result<()> {
317317
}
318318

319319
pub fn keyctl_get_security(key: KeyringSerial, mut buffer: Option<Out<[u8]>>) -> Result<usize> {
320+
let capacity = buffer.as_mut().map_or(0, |b| b.len());
320321
unsafe {
321-
let capacity = buffer.as_mut().map_or(0, |b| b.len());
322322
keyctl!(
323323
libc::KEYCTL_GET_SECURITY,
324324
key.get(),
@@ -365,8 +365,8 @@ pub fn keyctl_dh_compute(
365365
base: KeyringSerial,
366366
mut buffer: Option<Out<[u8]>>,
367367
) -> Result<usize> {
368+
let capacity = buffer.as_mut().map_or(0, |b| b.len());
368369
unsafe {
369-
let capacity = buffer.as_mut().map_or(0, |b| b.len());
370370
keyctl!(
371371
libc::KEYCTL_DH_COMPUTE,
372372
private.get(),

0 commit comments

Comments
 (0)