Skip to content

mbedtls: pass null-terminator in ssh2_ecdsa_new_private() for PEM-formatted keys - #2275

Closed
vszakats wants to merge 2 commits into
libssh2:masterfrom
vszakats:mbed-ecdsa-load-from-file-null-term
Closed

vszakats wants to merge 2 commits into
libssh2:masterfrom
vszakats:mbed-ecdsa-load-from-file-null-term

Conversation

@vszakats

@vszakats vszakats commented Jul 12, 2026 •

Copy link
Copy Markdown
Member

When loading ECDSA key from an EC/PEM-formatted private key file, as
required by mbedtls_pk_parse_key().

Follow-up to b101ce0 #1878

@vszakats
vszakats requested a review from Copilot July 12, 2026 05:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the mbedTLS backend’s ECDSA private-key loader to ensure the file buffer is NUL-terminated (and the passed length includes that terminator) so it satisfies mbedtls_pk_parse_key()’s input requirements.

Changes:

  • Allocate data_len + 1 bytes when reading an ECDSA private key file.
  • Append a NUL terminator at data[data_len].
  • Call mbed_parse_eckey() with data_len + 1.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/mbedtls.c Resolved
Comment thread src/mbedtls.c

if(mbed_parse_eckey(ec_ctx, &pkey, data, data_len, passphrase) == 0)
data[data_len] = 0; /* for mbedtls_pk_parse_key() */
if(mbed_parse_eckey(ec_ctx, &pkey, data, data_len + 1, passphrase) == 0)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, lots of key formats are not tested. I'd be surprised if all combinations would be supported universally (and work as expected). Also the way they are tested ATM do not scale (separate test app binary for each format!).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@vszakats vszakats changed the title mbedtls: pass null-terminator in ssh2_ecdsa_new_private() mbedtls: pass null-terminator in ssh2_ecdsa_new_private() for PEM-formatted keys Jul 12, 2026
@vszakats vszakats closed this in bce5593 Jul 12, 2026
@vszakats
vszakats deleted the mbed-ecdsa-load-from-file-null-term branch July 12, 2026 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants