Skip to content

Fix crash when remote certificate is allocated uninitialized (#473) - #502

Open
Dev10-sys wants to merge 1 commit into
eclipse-threadx:devfrom
Dev10-sys:fix/remote-cert-allocate-uninitialized
Open

Dev10-sys wants to merge 1 commit into
eclipse-threadx:devfrom
Dev10-sys:fix/remote-cert-allocate-uninitialized

Conversation

@Dev10-sys

@Dev10-sys Dev10-sys commented Oct 22, 2026 •

Copy link
Copy Markdown

Fixes #473.

Passing an uninitialized certificate to nx_secure_tls_remote_certificate_allocate leaves garbage in the struct because it was never zeroed out. If the server sends an X.509 v1 certificate or one without extensions, the parser doesn't touch the extension fields, so the KeyUsage check tries to read a bad pointer and crashes.

This PR zeroes the certificate struct when allocated, resets optional extension fields in _nx_secure_x509_certificate_parse, and adds a null check in _nx_secure_x509_extension_find to prevent the crash. Tested locally with an uninitialized struct and an X.509 v1 cert.

@Dev10-sys Dev10-sys closed this Oct 22, 2026
@Dev10-sys Dev10-sys reopened this Oct 22, 2026
@Dev10-sys Dev10-sys changed the title Initialize remote certificate and optional extension fields (#473) Fix crash when remote certificate is allocated uninitialized (#473) Oct 22, 2026
@Dev10-sys
Dev10-sys force-pushed the fix/remote-cert-allocate-uninitialized branch from 75963ef to ee43925 Compare October 22, 2026 06:30
…e-threadx#473)

The documented API contract for nx_secure_tls_remote_certificate_allocate
states that caller passes an uninitialized NX_SECURE_X509_CERT structure
instance. However, nx_secure_tls_remote_certificate_allocate only assigned
the raw buffer pointers and user allocation flag without clearing the
certificate structure first. In addition, _nx_secure_x509_certificate_parse
did not clear optional fields (extensions data and unique identifiers) when
parsing certificates where those blocks are absent, such as X.509 v1 or v2
certificates or reused structures.

When an uninitialized or non-zeroed certificate was allocated,
nx_secure_x509_extensions_data and nx_secure_x509_extensions_data_length
retained uninitialized memory. During certificate verification of
self-signed certificates or issuer chains, _nx_secure_x509_key_usage_extension_parse
called _nx_secure_x509_extension_find, which attempted to parse ASN.1 TLV
blocks from the stale pointer in _nx_secure_x509_asn1_tlv_block_parse,
triggering a BusFault/segmentation fault.

This fix zeroes the certificate structure in
_nx_secure_tls_remote_certificate_allocate before populating fields,
explicitly initializes optional extension and identifier fields to NULL and
zero in _nx_secure_x509_certificate_parse, and guards
_nx_secure_x509_extension_find against NULL or zero-length extension data.
A test case in nx_secure_x509_parse_test verifies clean handling for
certificates without extensions and non-zeroed initial memory.

Signed-off-by: Dev10-sys <kalpanagola9897@gmail.com>
@Dev10-sys
Dev10-sys force-pushed the fix/remote-cert-allocate-uninitialized branch from ee43925 to d1d1e68 Compare October 22, 2026 19:16

This branch has not been deployed

No deployments
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