mirror of
https://github.com/Mbed-TLS/mbedtls-framework.git
synced 2026-07-28 14:57:46 +00:00
Complain about bad initialization of operation structures
In every existing test driver entry point that is the setup for a multipart
operation, check that the driver operation structure is all-bits-zero on
entry, as guaranteed by the driver specification.
There is a risk that this isn't the case, mostly, on platforms where
initializing a union to `{0}` initializes only the default member and not
all members.
Signed-off-by: Gilles Peskine <[email protected]>
This commit is contained in:
@@ -8,4 +8,10 @@
|
||||
|
||||
#include "mbedtls/build_info.h"
|
||||
|
||||
/** Error code that test drivers return when they detect that an input
|
||||
* parameter was not initialized properly. This normally indicates a
|
||||
* bug in the core.
|
||||
*/
|
||||
#define PSA_ERROR_TEST_DETECTED_BAD_INITIALIZATION ((psa_status_t)-0x0201)
|
||||
|
||||
#endif /* test_driver_common.h */
|
||||
|
||||
@@ -149,6 +149,9 @@ psa_status_t mbedtls_test_transparent_aead_encrypt_setup(
|
||||
if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
} else if (!MBEDTLS_TEST_OBJECT_IS_ALL_ZERO(operation)) {
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
PSA_ERROR_TEST_DETECTED_BAD_INITIALIZATION;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
@@ -186,6 +189,9 @@ psa_status_t mbedtls_test_transparent_aead_decrypt_setup(
|
||||
if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
} else if (!MBEDTLS_TEST_OBJECT_IS_ALL_ZERO(operation)) {
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
PSA_ERROR_TEST_DETECTED_BAD_INITIALIZATION;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
|
||||
@@ -139,16 +139,14 @@ psa_status_t mbedtls_test_transparent_cipher_encrypt_setup(
|
||||
{
|
||||
mbedtls_test_driver_cipher_hooks.hits++;
|
||||
|
||||
/* Wiping the entire struct here, instead of member-by-member. This is
|
||||
* useful for the test suite, since it gives a chance of catching memory
|
||||
* corruption errors should the core not have allocated (enough) memory for
|
||||
* our context struct. */
|
||||
memset(operation, 0, sizeof(*operation));
|
||||
|
||||
if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
|
||||
return mbedtls_test_driver_cipher_hooks.forced_status;
|
||||
}
|
||||
|
||||
if (!MBEDTLS_TEST_OBJECT_IS_ALL_ZERO(operation)) {
|
||||
return PSA_ERROR_TEST_DETECTED_BAD_INITIALIZATION;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
return libtestdriver1_mbedtls_psa_cipher_encrypt_setup(
|
||||
@@ -175,6 +173,10 @@ psa_status_t mbedtls_test_transparent_cipher_decrypt_setup(
|
||||
return mbedtls_test_driver_cipher_hooks.forced_status;
|
||||
}
|
||||
|
||||
if (!MBEDTLS_TEST_OBJECT_IS_ALL_ZERO(operation)) {
|
||||
return PSA_ERROR_TEST_DETECTED_BAD_INITIALIZATION;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
return libtestdriver1_mbedtls_psa_cipher_decrypt_setup(
|
||||
|
||||
@@ -83,6 +83,9 @@ psa_status_t mbedtls_test_transparent_mac_sign_setup(
|
||||
if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
} else if (!MBEDTLS_TEST_OBJECT_IS_ALL_ZERO(operation)) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
PSA_ERROR_TEST_DETECTED_BAD_INITIALIZATION;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
|
||||
@@ -120,6 +123,9 @@ psa_status_t mbedtls_test_transparent_mac_verify_setup(
|
||||
if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
} else if (!MBEDTLS_TEST_OBJECT_IS_ALL_ZERO(operation)) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
PSA_ERROR_TEST_DETECTED_BAD_INITIALIZATION;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
|
||||
@@ -309,6 +315,9 @@ psa_status_t mbedtls_test_opaque_mac_sign_setup(
|
||||
if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
} else if (!MBEDTLS_TEST_OBJECT_IS_ALL_ZERO(operation)) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
PSA_ERROR_TEST_DETECTED_BAD_INITIALIZATION;
|
||||
} else {
|
||||
(void) operation;
|
||||
(void) attributes;
|
||||
@@ -333,6 +342,9 @@ psa_status_t mbedtls_test_opaque_mac_verify_setup(
|
||||
if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
} else if (!MBEDTLS_TEST_OBJECT_IS_ALL_ZERO(operation)) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
PSA_ERROR_TEST_DETECTED_BAD_INITIALIZATION;
|
||||
} else {
|
||||
(void) operation;
|
||||
(void) attributes;
|
||||
|
||||
@@ -35,6 +35,9 @@ psa_status_t mbedtls_test_transparent_pake_setup(
|
||||
if (mbedtls_test_driver_pake_hooks.forced_setup_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_pake_hooks.driver_status =
|
||||
mbedtls_test_driver_pake_hooks.forced_setup_status;
|
||||
} else if (!MBEDTLS_TEST_OBJECT_IS_ALL_ZERO(operation)) {
|
||||
mbedtls_test_driver_pake_hooks.driver_status =
|
||||
PSA_ERROR_TEST_DETECTED_BAD_INITIALIZATION;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_PAKE)
|
||||
|
||||
Reference in New Issue
Block a user