CVE-2024-5991 Overview
CVE-2024-5991 is an out-of-bounds read vulnerability in wolfSSL through version 5.7.0. The flaw resides in the MatchDomainName() function, which is invoked by X509_check_host() during certificate hostname validation. The function treats the user-supplied str parameter as a NULL-terminated string, even though the caller passes an explicit length and the buffer is not required to be NULL-terminated. When an application validates a hostname using a non-terminated buffer, MatchDomainName() reads past the end of the input until it encounters a NULL byte, exposing adjacent memory contents.
Critical Impact
Network-reachable attackers can trigger out-of-bounds memory reads during TLS certificate validation, potentially leaking sensitive process memory or crashing the host application.
Affected Products
- wolfSSL versions up to and including 5.7.0
- Applications linking wolfSSL and calling X509_check_host() with non-NULL-terminated buffers
- Embedded and IoT firmware bundling vulnerable wolfSSL builds
Discovery Timeline
- 2024-08-27 - CVE-2024-5991 published to the National Vulnerability Database
- 2026-06-17 - Last updated in NVD database
Technical Details for CVE-2024-5991
Vulnerability Analysis
The vulnerability is classified as an out-of-bounds read [CWE-125] in the wolfSSL TLS library. X509_check_host() accepts a hostname pointer and an explicit length argument, mirroring the OpenSSL API contract that allows callers to pass arbitrary byte buffers. Internally, however, the routine delegates string comparison to MatchDomainName(), which iterates over the input using NULL-terminator semantics rather than honoring the provided length. The mismatch in assumptions between the public API and the internal helper produces the boundary error. An attacker controlling the certificate or the input being matched can influence which memory regions are scanned, since the read continues until a NULL byte appears in adjacent memory.
Root Cause
The root cause is improper handling of buffer boundaries in MatchDomainName(). The helper assumes str ends with a \0 byte, yet X509_check_host() does not enforce or insert termination on caller-supplied buffers. Length parameters are ignored at the comparison loop, producing the classic length-versus-terminator confusion that drives out-of-bounds reads.
Attack Vector
Exploitation occurs over the network during TLS certificate validation. An application that calls X509_check_host() against a hostname stored in a non-NULL-terminated buffer becomes vulnerable when processing attacker-influenced certificates or hostname inputs. The read overrun may leak adjacent heap or stack memory, including TLS session secrets or other process state, or trigger a segmentation fault leading to denial of service. The wolfSSL maintainers addressed the defect in wolfSSL pull request 7604.
Detection Methods for CVE-2024-5991
Indicators of Compromise
- Unexpected segmentation faults or crashes in processes linked against wolfSSL during TLS handshakes
- Anomalous TLS certificate validation errors logged by applications using X509_check_host()
- Memory access violations recorded by host instrumentation when processing certificates with unusual Subject Alternative Name entries
Detection Strategies
- Inventory binaries and firmware for wolfSSL versions at or below 5.7.0 using software composition analysis
- Audit application source for calls to X509_check_host() and verify whether hostname buffers are NULL-terminated
- Enable AddressSanitizer or Valgrind in test environments to surface out-of-bounds reads in MatchDomainName()
Monitoring Recommendations
- Monitor process crash telemetry on systems running wolfSSL-dependent services and correlate with TLS connection logs
- Track TLS handshake failure rates from edge devices and IoT fleets that historically run static wolfSSL builds
- Alert on outbound connections from embedded devices that terminate abnormally during certificate validation phases
How to Mitigate CVE-2024-5991
Immediate Actions Required
- Upgrade wolfSSL to a release that includes the fix from pull request 7604, beyond version 5.7.0
- Rebuild and redeploy all applications, firmware images, and containers that statically link wolfSSL
- Review application code to ensure hostname buffers passed to X509_check_host() are explicitly NULL-terminated as a defense-in-depth measure
Patch Information
The wolfSSL project corrected MatchDomainName() to respect the caller-provided length rather than scanning for a NULL terminator. The patch is published in wolfSSL pull request 7604. Vendors shipping wolfSSL in firmware should issue updated images to downstream customers.
Workarounds
- Wrap calls to X509_check_host() so that hostname buffers are copied into a sized, NULL-terminated stack buffer before invocation
- Restrict TLS certificate sources to trusted issuers to reduce attacker control over inputs feeding MatchDomainName()
- Where upgrades are not yet possible, disable code paths that perform hostname verification on untrusted, externally supplied buffers
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

