Skip to content

Uninitialized mbedtls_test_handshake_test_options when SSL tests fail early #10250

Open
@gilles-peskine-arm

Description

@gilles-peskine-arm

In test_suite_ssl.function, we have the variants of the following pattern many times:

    mbedtls_test_handshake_test_options options;
    PSA_INIT(); // or other setup code that can fail
    ret = mbedtls_test_ssl_do_handshake_with_endpoints(&server_ep, &client_ep, &options, proto);
…
exit:
    mbedtls_test_free_handshake_options(&options);

If the setup code such as PSA_INIT() fails, we call mbedtls_test_free_handshake_options() on an uninitialized mbedtls_test_handshake_test_options object.

We should initialize mbedtls_test_handshake_test_options objects as soon as they're declared. However, there's a subtlety: we can't just call mbedtls_test_init_handshake_options() indiscriminately. The reason is that this function allocates an auxiliary object, and you call it twice, the first allocation is lost. mbedtls_test_ssl_do_handshake_with_endpoints() calls mbedtls_test_init_handshake_options(), so in cases like the one above, calling mbedtls_test_init_handshake_options() would cause a memory leak.

Some possible solutions:

  • Change mbedtls_test_init_handshake_options() to not allocate memory. (I have no idea why it does.)
  • Start with memset(&options, 0, sizeof(options)), which is good enough for mbedtls_test_free_handshake_options()`.

(Related: #10249 fixes a similar problem with mbedtls_test_ssl_endpoint objects, where double-init is not a problem.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions