diff --git a/common/argv.c b/common/argv.c index 30bb13cbe2..af004d2667 100644 --- a/common/argv.c +++ b/common/argv.c @@ -57,7 +57,13 @@ oe_result_t oe_argv_to_buffer( if (buf_size < required_size) { *buf_size_out = required_size; - OE_RAISE(OE_BUFFER_TOO_SMALL); + + if (buf_out) + OE_RAISE(OE_BUFFER_TOO_SMALL); + /* If buf_out is null, this call is intented to get the correct buf_size + * so no need to trace OE_BUFFER_TOO_SMALL */ + else + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } /* Copy the strings onto the allocated buffer. */ diff --git a/common/cert.c b/common/cert.c index 734f950012..814888c354 100644 --- a/common/cert.c +++ b/common/cert.c @@ -203,7 +203,13 @@ oe_result_t oe_get_crl_distribution_points( if (offset > *buffer_size) { *buffer_size = offset; - OE_RAISE(OE_BUFFER_TOO_SMALL); + + if (buffer) + OE_RAISE(OE_BUFFER_TOO_SMALL); + /* If buffer is null, this call is intented to get the correct + * buffer_size so no need to trace OE_BUFFER_TOO_SMALL */ + else + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } *buffer_size = offset; diff --git a/enclave/crypto/ec.c b/enclave/crypto/ec.c index b5d5cf77b8..e73fc0a88f 100644 --- a/enclave/crypto/ec.c +++ b/enclave/crypto/ec.c @@ -468,7 +468,13 @@ oe_result_t oe_ecdsa_signature_write_der( if (len > *signature_size) { *signature_size = len; - OE_RAISE(OE_BUFFER_TOO_SMALL); + + if (signature) + OE_RAISE(OE_BUFFER_TOO_SMALL); + /* If signature is null, this call is intented to get the correct + * signature_size so no need to trace OE_BUFFER_TOO_SMALL */ + else + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } OE_CHECK(oe_memcpy_s(signature, *signature_size, p, len)); diff --git a/enclave/crypto/key.c b/enclave/crypto/key.c index 5401322d10..e7d1f609e2 100644 --- a/enclave/crypto/key.c +++ b/enclave/crypto/key.c @@ -379,7 +379,13 @@ oe_result_t oe_private_key_sign( if (*signature_size < buffer_size) { *signature_size = buffer_size; - OE_RAISE(OE_BUFFER_TOO_SMALL); + + if (signature) + OE_RAISE(OE_BUFFER_TOO_SMALL); + /* If signature is null, this call is intented to get the correct + * signature_size so no need to trace OE_BUFFER_TOO_SMALL */ + else + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } /* Copy result to output buffer */ diff --git a/enclave/crypto/rsa.c b/enclave/crypto/rsa.c index 5765c037a3..923a4d18a6 100644 --- a/enclave/crypto/rsa.c +++ b/enclave/crypto/rsa.c @@ -108,11 +108,17 @@ static oe_result_t _get_public_key_modulus_or_exponent( /* Determine the required size in bytes */ required_size = mbedtls_mpi_size(mpi); - /* If buffer is null or not big enough */ - if (!buffer || (*buffer_size < required_size)) + /* If buffer is not big enough */ + if (*buffer_size < required_size) { *buffer_size = required_size; - OE_RAISE(OE_BUFFER_TOO_SMALL); + + if (buffer) + OE_RAISE(OE_BUFFER_TOO_SMALL); + /* If buffer is null, this call is intented to get the correct + * buffer_size so no need to trace OE_BUFFER_TOO_SMALL */ + else + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } /* Copy key bytes to the caller's buffer */ diff --git a/host/crypto/bcrypt/cert.c b/host/crypto/bcrypt/cert.c index 7ce2dae801..bd23070135 100644 --- a/host/crypto/bcrypt/cert.c +++ b/host/crypto/bcrypt/cert.c @@ -1043,7 +1043,13 @@ oe_result_t oe_get_crl_distribution_points( if (*buffer_size < required_size) { *buffer_size = required_size; - OE_RAISE(OE_BUFFER_TOO_SMALL); + + if (buffer) + OE_RAISE(OE_BUFFER_TOO_SMALL); + /* If buffer is null, this call is intented to get the correct + * buffer_size so no need to trace OE_BUFFER_TOO_SMALL */ + else + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } /* Copy the URLs array and pack the URL strings into buffer */ @@ -1281,7 +1287,13 @@ oe_result_t oe_cert_find_extension( if (extension->Value.cbData > *data_size) { *data_size = extension->Value.cbData; - OE_RAISE(OE_BUFFER_TOO_SMALL); + + if (data) + OE_RAISE(OE_BUFFER_TOO_SMALL); + /* If data is null, this call is intented to get the correct + * data_size so no need to trace OE_BUFFER_TOO_SMALL */ + else + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } if (data) diff --git a/host/crypto/bcrypt/ec.c b/host/crypto/bcrypt/ec.c index 14695ecff6..7f143be67f 100644 --- a/host/crypto/bcrypt/ec.c +++ b/host/crypto/bcrypt/ec.c @@ -591,7 +591,7 @@ oe_result_t oe_ec_private_key_sign( if (!signature) { *signature_size = max_encoded_size; - OE_RAISE(OE_BUFFER_TOO_SMALL); + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } OE_CHECK(oe_private_key_sign( @@ -621,7 +621,10 @@ oe_result_t oe_ec_private_key_sign( assert(*signature_size <= max_encoded_size); *signature_size = max_encoded_size; } - OE_CHECK(encode_result); + if (!signature && encode_result == OE_BUFFER_TOO_SMALL) + OE_CHECK_NO_TRACE(encode_result); + else + OE_CHECK(encode_result); } } @@ -1036,7 +1039,13 @@ oe_result_t oe_ecdsa_signature_write_der( if (encoded_size > *signature_size) { *signature_size = (size_t)encoded_size; - OE_RAISE(OE_BUFFER_TOO_SMALL); + + if (signature) + OE_RAISE(OE_BUFFER_TOO_SMALL); + /* If signature is null, this call is intented to get the correct + * signature_size so no need to trace OE_BUFFER_TOO_SMALL */ + else + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } if (!success) diff --git a/host/crypto/bcrypt/key.c b/host/crypto/bcrypt/key.c index 2a285075c7..6c440d69b4 100644 --- a/host/crypto/bcrypt/key.c +++ b/host/crypto/bcrypt/key.c @@ -516,7 +516,13 @@ oe_result_t oe_private_key_sign( if (required_size > *signature_size) { *signature_size = required_size; - OE_RAISE(OE_BUFFER_TOO_SMALL); + + if (signature) + OE_RAISE(OE_BUFFER_TOO_SMALL); + /* If buf_out is null, this call is intented to get the correct + * signature_size so no need to trace OE_BUFFER_TOO_SMALL */ + else + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } status = BCryptSignHash( diff --git a/host/crypto/bcrypt/rsa.c b/host/crypto/bcrypt/rsa.c index 03e4419824..eb2bf14113 100644 --- a/host/crypto/bcrypt/rsa.c +++ b/host/crypto/bcrypt/rsa.c @@ -344,7 +344,13 @@ oe_result_t oe_rsa_public_key_get_modulus( if (keyblob->cbModulus > *modulus_size) { *modulus_size = keyblob->cbModulus; - OE_RAISE(OE_BUFFER_TOO_SMALL); + + if (modulus) + OE_RAISE(OE_BUFFER_TOO_SMALL); + /* If modulus is null, this call is intented to get the correct + * modulus_size so no need to trace OE_BUFFER_TOO_SMALL */ + else + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } /* @@ -404,7 +410,13 @@ oe_result_t oe_rsa_public_key_get_exponent( if (keyblob->cbPublicExp > *exponent_size) { *exponent_size = keyblob->cbPublicExp; - OE_RAISE(OE_BUFFER_TOO_SMALL); + + if (exponent) + OE_RAISE(OE_BUFFER_TOO_SMALL); + /* If exponent is null, this call is intented to get the correct + * exponent_size so no need to trace OE_BUFFER_TOO_SMALL */ + else + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } /* diff --git a/host/crypto/openssl/cert.c b/host/crypto/openssl/cert.c index fb3855c568..90e79160e4 100644 --- a/host/crypto/openssl/cert.c +++ b/host/crypto/openssl/cert.c @@ -953,7 +953,13 @@ oe_result_t oe_cert_find_extension( if ((size_t)str->length > *size) { *size = (size_t)str->length; - OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); + + if (data) + OE_RAISE(OE_BUFFER_TOO_SMALL); + /* If data is null, this call is intented to get the correct + * size so no need to trace OE_BUFFER_TOO_SMALL */ + else + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } if (data) diff --git a/host/crypto/openssl/ec.c b/host/crypto/openssl/ec.c index d88bc7f928..ef3bcae09b 100644 --- a/host/crypto/openssl/ec.c +++ b/host/crypto/openssl/ec.c @@ -494,7 +494,13 @@ oe_result_t oe_ecdsa_signature_write_der( if ((size_t)sig_len > *signature_size) { *signature_size = (size_t)sig_len; - OE_RAISE(OE_BUFFER_TOO_SMALL); + + if (signature) + OE_RAISE(OE_BUFFER_TOO_SMALL); + /* If signature is null, this call is intented to get the correct + * signature_size so no need to trace OE_BUFFER_TOO_SMALL */ + else + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } /* Set the size of the output buffer */ diff --git a/host/crypto/openssl/key.c b/host/crypto/openssl/key.c index e3de19f407..0ae6784f9b 100644 --- a/host/crypto/openssl/key.c +++ b/host/crypto/openssl/key.c @@ -347,7 +347,13 @@ oe_result_t oe_public_key_write_pem( if (*size < mem->length) { *size = mem->length; - OE_RAISE(OE_BUFFER_TOO_SMALL); + + if (data) + OE_RAISE(OE_BUFFER_TOO_SMALL); + /* If data is null, this call is intented to get the correct + * size so no need to trace OE_BUFFER_TOO_SMALL */ + else + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } /* Copy result to output buffer */ @@ -468,7 +474,13 @@ oe_result_t oe_private_key_sign( if (size > *signature_size) { *signature_size = size; - OE_RAISE(OE_BUFFER_TOO_SMALL); + + if (signature) + OE_RAISE(OE_BUFFER_TOO_SMALL); + /* If buf_out is null, this call is intented to get the correct + * signature_size so no need to trace OE_BUFFER_TOO_SMALL */ + else + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } *signature_size = size; diff --git a/host/crypto/openssl/rsa.c b/host/crypto/openssl/rsa.c index c682ac3cd2..1ca00beaf4 100644 --- a/host/crypto/openssl/rsa.c +++ b/host/crypto/openssl/rsa.c @@ -128,7 +128,13 @@ static oe_result_t _get_public_key_get_modulus_or_exponent( if (!buffer || (*buffer_size < required_size)) { *buffer_size = required_size; - OE_RAISE(OE_BUFFER_TOO_SMALL); + + if (buffer) + OE_RAISE(OE_BUFFER_TOO_SMALL); + /* If buffer is null, this call is intented to get the correct + * buffer_size so no need to trace OE_BUFFER_TOO_SMALL */ + else + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } /* Copy key bytes to the caller's buffer */ diff --git a/host/sgx/sgxquote.c b/host/sgx/sgxquote.c index 214576fbe3..bbc680abda 100644 --- a/host/sgx/sgxquote.c +++ b/host/sgx/sgxquote.c @@ -578,7 +578,13 @@ oe_result_t oe_sgx_get_supported_attester_format_ids( (!format_ids || *format_ids_size < sizeof(oe_uuid_t) * count)) { *format_ids_size = sizeof(oe_uuid_t) * count; - OE_RAISE(OE_BUFFER_TOO_SMALL); + + if (format_ids) + OE_RAISE(OE_BUFFER_TOO_SMALL); + /* If format_ids is null, this call is intented to get the correct + * format_ids_size so no need to trace OE_BUFFER_TOO_SMALL */ + else + OE_RAISE_NO_TRACE(OE_BUFFER_TOO_SMALL); } for (size_t i = 0; i < _quote_ex_library.key_id_count; i++)