Skip to content

x509: read the ASN.1 tag after the length check, not before - #413

Open
tinic wants to merge 1 commit into
eclipse-threadx:masterfrom
tinic:amiga-x509-tlv-tag-overread
Open

x509: read the ASN.1 tag after the length check, not before#413
tinic wants to merge 1 commit into
eclipse-threadx:masterfrom
tinic:amiga-x509-tlv-tag-overread

Conversation

@tinic

@tinic tinic commented Jul 31, 2026

Copy link
Copy Markdown

_nx_secure_x509_asn1_tlv_block_parse() loaded buffer[0] into current_tag one statement before testing *buffer_length < 1, so every caller that runs out of data read one byte past the end of the buffer it was given.

It is reachable from the wire. A certificate two bytes long reaches it through _nx_secure_x509_certificate_parse(), and so does the issuer walk in the certificate store, which calls the parser repeatedly as it consumes a chain and hands it whatever remains.

Found by a fuzz driver over _nx_secure_tls_process_remote_certificate() with a real DER corpus, and confirmed under AddressSanitizer.

The read is moved below the guard. The guard already returned the right status; only the load was in the wrong place.

_nx_secure_x509_asn1_tlv_block_parse() loaded buffer[0] into current_tag
one statement before testing *buffer_length < 1, so every caller that runs
out of data read one byte past the end of the buffer it was given.

It is reachable from the wire. A certificate two bytes long reaches it
through _nx_secure_x509_certificate_parse(), and so does the issuer walk
in the certificate store, which calls the parser repeatedly as it consumes
a chain and hands it whatever remains.

Found by a fuzz driver over _nx_secure_tls_process_remote_certificate()
with a real DER corpus, and confirmed under AddressSanitizer.

The read is moved below the guard. The guard already returned the right
status; only the load was in the wrong place.
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.

1 participant