Repository navigation
mbedtls: fix missing rsa_init when loading key from memory - #1822
Merged
Merged
Conversation
This adds the missing mbedtls_rsa_init() call in _libssh2_mbedtls_rsa_new_private_frommemory, which caused MBEDTLS_ERR_THREADING_BAD_INPUT_DATA when attempting to sign data due to an uninitialized mutex.
Contributor
Author
|
How long it takes to a maintainer to read our PRs? |
Contributor
|
Nobody is paid to work on libssh2, so reviews have to wait to fit into life. |
Member
|
@P81000 Thanks for the fix! |
vszakats
added a commit
that referenced
this pull request
Jun 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a critical threading issue in the mbedTLS backend when loading RSA private keys from memory. It resolves the fatal error
LIBSSH2_ERROR_CALLBACK_RETURNED_ERROR(-19) that occurs during the authentication phase.Root Cause Analysis
While debugging the
_libssh2_mbedtls_rsa_sha2_signfunction, I identified that the underlying mbedTLS call was failing with error code-0x001C(MBEDTLS_ERR_THREADING_BAD_INPUT_DATA).The issue originates in
_libssh2_mbedtls_rsa_new_private_frommemory:mbedtls_calloc, which zero-initializes the structure.mbedtls_rsa_contextcontains a mutex that must be initialized viambedtls_rsa_init.mbedtls_rsa_pkcs1_signis eventually called, it attempts to lock this uninitialized mutex, leading to the threading error and the subsequent-19callback failure in libssh2.Changes
mbedtls_rsa_init()call in_libssh2_mbedtls_rsa_new_private_frommemoryright after allocation._libssh2_mbedtls_rsa_new_private), which is already correctly initialized.Testing