Skip to content

Error handling in c-utility/adapters/tlsio_mbedtls.c #2673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ASeidelt opened this issue Mar 26, 2025 · 1 comment
Open

Error handling in c-utility/adapters/tlsio_mbedtls.c #2673

ASeidelt opened this issue Mar 26, 2025 · 1 comment
Assignees
Labels

Comments

@ASeidelt
Copy link

Hi,

when updating mbedTLS to v3.6.3 because of the mbedtls_ssl_set_hostname() bug we noticed that the function mbedtls_init() in c-utility/adapters/tlsio_mbedtls.c does not check the return values of any of the invoked mbedTLS functions.

The following functions can return errors during connection setup (e.g. because of memory allocation errors):

  • mbedtls_ctr_drbg_seed()
  • mbedtls_ssl_config_defaults()
  • mbedtls_ssl_set_hostname()
  • mbedtls_ssl_set_session()
  • mbedtls_ssl_setup()

Because all errors are ignored, the state of the tls_io_instance is always set to TLS_STATE_INITIALIZED.

To me it seems the (potentially) uninitialized structures are then used for further IO operations?

Wouldn't it be more feasible to make mbedtls_init() return an error (NULL that is) which is then propagated via tlsio_mbedtls_create() to the caller of the tlsio_mbedtls.c instance?

At least tlsio_wolfssl.c seems to do it that way if initialization fails.

regards
Andre

@ewertons ewertons self-assigned this Apr 9, 2025
@ASeidelt
Copy link
Author

ASeidelt commented May 6, 2025

Additional ignored return values:

In tlsio_mbedtls_open() the functions mbedtls_ssl_session_reset() can return an error.

In tlsio_mbedtls_close() the functions mbedtls_ssl_session_reset() can return an error.
The function mbedtls_ssl_close_notify() can return MBEDTLS_ERR_SSL_WANT_WRITE which should be handled in a do-while-loop according to the mbedTLS examples.

In decode_ssl_received_bytes() the function mbedtls_ssl_read() might return an error that is not propagated by indicate_error() and therefore only handled by timeouts. Please note that is can also return MBEDTLS_ERR_SSL_WANT_READ which is not an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants