Skip to content

fix: initialize s2n_cert fields in s2n_connection_get_peer_cert_chain - #6045

Open
jouho wants to merge 1 commit into
aws:mainfrom
jouho:fix/peer-cert-chain-uninit-memory
Open

fix: initialize s2n_cert fields in s2n_connection_get_peer_cert_chain#6045
jouho wants to merge 1 commit into
aws:mainfrom
jouho:fix/peer-cert-chain-uninit-memory

Conversation

@jouho

@jouho jouho commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Goal

Ensure s2n_connection_get_peer_cert_chain() returns fully-initialized s2n_cert nodes.

Why

The function allocated each s2n_cert node with s2n_alloc (which does not zero memory) and only set the raw and next fields. The pkey_type, public_key, and info fields were left as uninitialized heap bytes. Callers reading those fields (e.g. via s2n_cert_chain_and_key_get_pkey_type()) could leak heap residue or act on a garbage key type. The correct pattern was already used in s2n_create_cert_chain_from_stuffer().

How

  • Zero each node after allocation with s2n_blob_zero(), so all fields have a defined value.
  • Populate info for every cert, and pkey_type/public_key for the leaf cert, from the parsed X509, mirroring s2n_cert_chain_and_key_load().

Callouts

An unknown leaf key type now fails with S2N_ERR_CERT_TYPE_UNSUPPORTED, matching s2n_cert_chain_and_key_load().

Testing

Existing s2n_certificate_test (covers s2n_connection_get_peer_cert_chain success/failure paths) and s2n_cert_validation_callback_test pass.

Related

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions Bot added the s2n-core team label Aug 17, 2026
@jouho
jouho marked this pull request as ready for review August 18, 2026 17:36
@jouho
jouho requested review from alexw91 and kaukabrizvi August 18, 2026 17:37
@jouho
jouho enabled auto-merge August 19, 2026 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants