wolfSSL — Unchecked Port Truncation in wolfSSL_BIO_new_accept
wolfSSL_BIO_new_accept converts its port string with atoi and casts the result to a 16-bit field with no range check. A port string of "-1" becomes 65535 and "70000" becomes 4464, and wolfSSL_BIO_do_accept then binds that port and reports success.
- Advisory
- BYTERAY-2026-0499
- CWE
- CWE-20
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-28
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 (tested at master commit d95483f), builds with OPENSSL_EXTRA; the bind path also needs HAVE_HTTP_CLIENT and HAVE_SOCKADDR
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
wolfSSL_BIO_new_accept() creates an accept BIO from a port string supplied by the application. It converts the string with atoi() and casts the signed result straight into the BIO's 16-bit unsigned port field.
There is no range check before the cast. A negative value wraps and a value above 65535 is truncated: "-1" becomes 65535 and "70000" becomes 4464. When the BIO is later used to accept connections, the stored value goes to the socket bind routine. Its only guard, port < 1, sees the value after truncation and passes it.
The process listens on a port other than the one requested, and the caller is told the call succeeded. The input is the application's own argument, not remote data, so this is a fail-open robustness defect and not a remotely exploitable issue. The code is part of the OpenSSL compatibility layer, which a default build does not enable.
Affected Products and Versions
- Component:
src/bio.c,wolfSSL_BIO_new_accept(), with the sink inwolfSSL_BIO_do_accept()andwolfIO_TcpBind(). - Required build:
OPENSSL_EXTRA(the block atsrc/bio.c:2404-3481). Reaching the bind also requiresHAVE_HTTP_CLIENTandHAVE_SOCKADDR(src/bio.c:2679,src/bio.c:2713). - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default
./configurebuild does not defineOPENSSL_EXTRAand does not include this code. - Other releases were not checked.
Technical Details
The conversion is one statement at src/bio.c:2638:
bio->port = (word16)XATOI(portStr);
XATOI is the standard atoi() (wolfssl/wolfcrypt/types.h:1307). It returns a signed int with no range guarantee. bio->port is a word16.
- The application passes a port string to
wolfSSL_BIO_new_accept()(src/bio.c:2620). The only check is for a NULL pointer (src/bio.c:2625). portStraliases the argument (src/bio.c:2631). WithWOLFSSL_IPV6it can be moved past a closing bracket (src/bio.c:2633-2636).- The cast at
src/bio.c:2638narrows theatoi()result."-1"gives 65535."70000"gives 4464."65536"gives 0. wolfSSL_BIO_do_accept()passesb->porttowolfIO_TcpBind()(src/bio.c:2733).wolfIO_TcpBind()rejects onlyport < 1(src/wolfio.c:1613). The check runs on the truncated value, so 65535 and 4464 pass. The value 0 is rejected, but only by coincidence.- The socket is bound to
INADDR_ANYon the aliased port and success is returned (src/wolfio.c:1626-1627).
The connect-side function in the same file already validates the range. wolfSSL_BIO_new_connect() checks both bounds before the same cast, under the comment "Reject out-of-range ports instead of truncating to word16" (src/bio.c:2584-2587). The accept path has no equivalent.
Reachability and Preconditions
- Build with
OPENSSL_EXTRA,HAVE_HTTP_CLIENTandHAVE_SOCKADDR. - The application passes an out-of-range port string to
wolfSSL_BIO_new_accept(), from its own code, its configuration, its environment, or a value it forwards without validation, and then callswolfSSL_BIO_do_accept(). - No path in the library carries remote or network input into this argument. The only references are the public prototype (
wolfssl/ssl.h:2267) and the compatibility macro (wolfssl/openssl/ssl.h:959). - A bind to a privileged low port still fails for an unprivileged process.
Impact
The process listens on a port it was not asked to use. Connections to the requested port fail, the aliased port is open without anyone expecting it, and the success return hides the error. The consequences are loss of availability on the intended port, confusion in monitoring, and unintended exposure on the aliased port.
No privilege boundary is crossed, since the caller already holds the right to bind locally. There is no memory-safety impact.
ByteRay did not build a proof of concept for this issue. The analysis is from source review.
Remediation and Mitigation
ByteRay has not confirmed a fixed wolfSSL release for this issue as of 2026-12-03, and has not checked it against wolfSSL changes made after the tested commit.
The fix direction is the check the connect-side function already has: parse the port into a signed int and reject values outside 0 to 65535 before the narrowing cast. Failing closed, by returning NULL for an invalid port, makes a misconfiguration visible instead of silently binding another port. A range check inside wolfIO_TcpBind() would protect future callers as well.
Until then, applications should validate the port string themselves before calling wolfSSL_BIO_new_accept().
Timeline
- 2026-09-28 — Reported to wolfSSL.
- 2026-12-03 — Public disclosure.
Credits
Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.