Skip to content

Commit f68c203

Browse files
committed
object: Avoid crashing on zero-length AllowedMechanisms attribute
As returned by SoftHSM: softhsm/SoftHSMv2#825 Fixes: #323 Signed-off-by: Jakub Jelen <[email protected]>
1 parent 2702bba commit f68c203

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

cryptoki/src/object.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,9 @@ impl TryFrom<CK_ATTRIBUTE> for Attribute {
11141114
Ok(Attribute::ValidationVersion(Version::new(val[0], val[1])))
11151115
}
11161116
AttributeType::AllowedMechanisms => {
1117+
if attribute.ulValueLen == 0 {
1118+
return Ok(Attribute::AllowedMechanisms(Vec::<MechanismType>::new()));
1119+
}
11171120
let val = unsafe {
11181121
std::slice::from_raw_parts(
11191122
attribute.pValue as *const CK_MECHANISM_TYPE,

0 commit comments

Comments
 (0)