File tree 2 files changed +11
-0
lines changed
include/aws/cryptosdk/private
2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,10 @@ int aws_cryptosdk_encrypt_body(
147
147
uint8_t * tag , /* out */
148
148
int body_frame_type );
149
149
150
+ // Even though `len` is of type `size_t`, this function is limited
151
+ // by the underlying OpenSSL function, which takes an `int`
152
+ // and so aws_cryptosdk_genrandom will return an error if asked for
153
+ // more than INT_MAX (2 billion) bytes of randomness.
150
154
int aws_cryptosdk_genrandom (uint8_t * buf , size_t len );
151
155
152
156
// TODO: Footer
Original file line number Diff line number Diff line change @@ -805,12 +805,19 @@ int aws_cryptosdk_decrypt_body(
805
805
}
806
806
}
807
807
808
+ // Even though `len` is of type `size_t`, this function is limited
809
+ // by the underlying OpenSSL function, which takes an `int`
810
+ // and so aws_cryptosdk_genrandom will return an error if asked for
811
+ // more than INT_MAX (2 billion) bytes of randomness.
808
812
int aws_cryptosdk_genrandom (uint8_t * buf , size_t len ) {
809
813
AWS_FATAL_PRECONDITION (AWS_MEM_IS_WRITABLE (buf , len ));
810
814
811
815
if (len == 0 ) {
812
816
return 0 ;
813
817
}
818
+ if (len > INT_MAX ) {
819
+ return aws_raise_error (AWS_CRYPTOSDK_ERR_LIMIT_EXCEEDED );
820
+ }
814
821
int rc = RAND_bytes (buf , len );
815
822
816
823
if (rc != 1 ) {
You can’t perform that action at this time.
0 commit comments