File tree Expand file tree Collapse file tree 2 files changed +11
-0
lines changed
include/aws/cryptosdk/private Expand file tree Collapse file tree 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(
147147 uint8_t * tag , /* out */
148148 int body_frame_type );
149149
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.
150154int aws_cryptosdk_genrandom (uint8_t * buf , size_t len );
151155
152156// TODO: Footer
Original file line number Diff line number Diff line change @@ -805,12 +805,19 @@ int aws_cryptosdk_decrypt_body(
805805 }
806806}
807807
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.
808812int aws_cryptosdk_genrandom (uint8_t * buf , size_t len ) {
809813 AWS_FATAL_PRECONDITION (AWS_MEM_IS_WRITABLE (buf , len ));
810814
811815 if (len == 0 ) {
812816 return 0 ;
813817 }
818+ if (len > INT_MAX ) {
819+ return aws_raise_error (AWS_CRYPTOSDK_ERR_LIMIT_EXCEEDED );
820+ }
814821 int rc = RAND_bytes (buf , len );
815822
816823 if (rc != 1 ) {
You can’t perform that action at this time.
0 commit comments