Skip to content

Commit 5959aa2

Browse files
Rust wrapper: ed448: add check for context buffers too long
Fix F-1064
1 parent 4f42ba9 commit 5959aa2

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

  • wrapper/rust/wolfssl-wolfcrypt/src

wrapper/rust/wolfssl-wolfcrypt/src/ed448.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,9 @@ impl Ed448 {
675675
let mut context_size = 0u8;
676676
if let Some(context) = context {
677677
context_ptr = context.as_ptr();
678+
if context.len() > 255 {
679+
return Err(sys::wolfCrypt_ErrorCodes_BAD_FUNC_ARG);
680+
}
678681
context_size = context.len() as u8;
679682
}
680683
let mut signature_size = signature.len() as u32;
@@ -737,6 +740,9 @@ impl Ed448 {
737740
let mut context_size = 0u8;
738741
if let Some(context) = context {
739742
context_ptr = context.as_ptr();
743+
if context.len() > 255 {
744+
return Err(sys::wolfCrypt_ErrorCodes_BAD_FUNC_ARG);
745+
}
740746
context_size = context.len() as u8;
741747
}
742748
let mut signature_size = signature.len() as u32;
@@ -790,6 +796,9 @@ impl Ed448 {
790796
let mut context_size = 0u8;
791797
if let Some(context) = context {
792798
context_ptr = context.as_ptr();
799+
if context.len() > 255 {
800+
return Err(sys::wolfCrypt_ErrorCodes_BAD_FUNC_ARG);
801+
}
793802
context_size = context.len() as u8;
794803
}
795804
let mut signature_size = signature.len() as u32;
@@ -843,6 +852,9 @@ impl Ed448 {
843852
let mut context_size = 0u8;
844853
if let Some(context) = context {
845854
context_ptr = context.as_ptr();
855+
if context.len() > 255 {
856+
return Err(sys::wolfCrypt_ErrorCodes_BAD_FUNC_ARG);
857+
}
846858
context_size = context.len() as u8;
847859
}
848860
let mut signature_size = signature.len() as u32;
@@ -897,6 +909,9 @@ impl Ed448 {
897909
let mut context_size = 0u8;
898910
if let Some(context) = context {
899911
context_ptr = context.as_ptr();
912+
if context.len() > 255 {
913+
return Err(sys::wolfCrypt_ErrorCodes_BAD_FUNC_ARG);
914+
}
900915
context_size = context.len() as u8;
901916
}
902917
let mut res = 0i32;
@@ -962,6 +977,9 @@ impl Ed448 {
962977
let mut context_size = 0u8;
963978
if let Some(context) = context {
964979
context_ptr = context.as_ptr();
980+
if context.len() > 255 {
981+
return Err(sys::wolfCrypt_ErrorCodes_BAD_FUNC_ARG);
982+
}
965983
context_size = context.len() as u8;
966984
}
967985
let mut res = 0i32;
@@ -1017,6 +1035,9 @@ impl Ed448 {
10171035
let mut context_size = 0u8;
10181036
if let Some(context) = context {
10191037
context_ptr = context.as_ptr();
1038+
if context.len() > 255 {
1039+
return Err(sys::wolfCrypt_ErrorCodes_BAD_FUNC_ARG);
1040+
}
10201041
context_size = context.len() as u8;
10211042
}
10221043
let mut res = 0i32;
@@ -1072,6 +1093,9 @@ impl Ed448 {
10721093
let mut context_size = 0u8;
10731094
if let Some(context) = context {
10741095
context_ptr = context.as_ptr();
1096+
if context.len() > 255 {
1097+
return Err(sys::wolfCrypt_ErrorCodes_BAD_FUNC_ARG);
1098+
}
10751099
context_size = context.len() as u8;
10761100
}
10771101
let mut res = 0i32;
@@ -1126,6 +1150,9 @@ impl Ed448 {
11261150
let mut context_size = 0u8;
11271151
if let Some(context) = context {
11281152
context_ptr = context.as_ptr();
1153+
if context.len() > 255 {
1154+
return Err(sys::wolfCrypt_ErrorCodes_BAD_FUNC_ARG);
1155+
}
11291156
context_size = context.len() as u8;
11301157
}
11311158
let rc = unsafe {

0 commit comments

Comments
 (0)