File tree Expand file tree Collapse file tree 1 file changed +19
-12
lines changed Expand file tree Collapse file tree 1 file changed +19
-12
lines changed Original file line number Diff line number Diff line change @@ -1114,18 +1114,25 @@ impl TryFrom<CK_ATTRIBUTE> for Attribute {
11141114 Ok ( Attribute :: ValidationVersion ( Version :: new ( val[ 0 ] , val[ 1 ] ) ) )
11151115 }
11161116 AttributeType :: AllowedMechanisms => {
1117- let val = unsafe {
1118- std:: slice:: from_raw_parts (
1119- attribute. pValue as * const CK_MECHANISM_TYPE ,
1120- attribute. ulValueLen . try_into ( ) ?,
1121- )
1122- } ;
1123- let types: Vec < MechanismType > = val
1124- . iter ( )
1125- . copied ( )
1126- . map ( |t| t. try_into ( ) )
1127- . collect :: < Result < Vec < MechanismType > > > ( ) ?;
1128- Ok ( Attribute :: AllowedMechanisms ( types) )
1117+ if attribute. ulValueLen == 0 {
1118+ /* For zero-length attributes we are getting pointer
1119+ * to static buffer of length zero, which can not be to create slices.
1120+ * Short-circuit here to avoid crash (#324) */
1121+ Ok ( Attribute :: AllowedMechanisms ( Vec :: < MechanismType > :: new ( ) ) )
1122+ } else {
1123+ let val = unsafe {
1124+ std:: slice:: from_raw_parts (
1125+ attribute. pValue as * const CK_MECHANISM_TYPE ,
1126+ attribute. ulValueLen . try_into ( ) ?,
1127+ )
1128+ } ;
1129+ let types: Vec < MechanismType > = val
1130+ . iter ( )
1131+ . copied ( )
1132+ . map ( |t| t. try_into ( ) )
1133+ . collect :: < Result < Vec < MechanismType > > > ( ) ?;
1134+ Ok ( Attribute :: AllowedMechanisms ( types) )
1135+ }
11291136 }
11301137 AttributeType :: EndDate => {
11311138 if val. is_empty ( ) {
You can’t perform that action at this time.
0 commit comments