Skip to content

Commit

Permalink
Remove misleading buffer too small messages
Browse files Browse the repository at this point in the history
Signed-off-by: Qiucheng Wang <[email protected]>
  • Loading branch information
qiucwang committed Oct 1, 2020
1 parent 98b71a4 commit b6b6f5c
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 21 deletions.
8 changes: 7 additions & 1 deletion common/argv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
8 changes: 7 additions & 1 deletion common/cert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion enclave/crypto/ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
8 changes: 7 additions & 1 deletion enclave/crypto/key.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
12 changes: 9 additions & 3 deletions enclave/crypto/rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
16 changes: 14 additions & 2 deletions host/crypto/bcrypt/cert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 12 additions & 3 deletions host/crypto/bcrypt/ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion host/crypto/bcrypt/key.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 14 additions & 2 deletions host/crypto/bcrypt/rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/*
Expand Down Expand Up @@ -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);
}

/*
Expand Down
8 changes: 7 additions & 1 deletion host/crypto/openssl/cert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion host/crypto/openssl/ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
16 changes: 14 additions & 2 deletions host/crypto/openssl/key.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion host/crypto/openssl/rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
8 changes: 7 additions & 1 deletion host/sgx/sgxquote.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down

0 comments on commit b6b6f5c

Please sign in to comment.