ClusterFuzz found a real OpenSSL API contract violation in curl's graceful TLS shutdown path. This is not an AddressSanitizer memory-corruption report: the final ABRT is deliberately raised by curl-fuzzer's OpenSSL contract shim at the first forbidden call.
During IMAP connection-cache cleanup, curl does this:
SSL_shutdown()returns-1.SSL_get_error()classifies that result asSSL_ERROR_SYSCALL.- curl handles only
SSL_ERROR_WANT_WRITEat that point. - Every other classification falls through to
SSL_read()on the sameSSL *. - The contract shim aborts before that read reaches OpenSSL.
OpenSSL documents both SSL_ERROR_SYSCALL and SSL_ERROR_SSL as fatal: no further I/O may be performed on the connection, and SSL_shutdown() must not be called again.
- Failing curl source: https://github.com/curl/curl/blob/1ee6ccab10521c8015c86c263a0f08865d575ec2/lib/vtls/openssl.c#L1907-L1928
- OpenSSL
SSL_get_error()contract: https://docs.openssl.org/master/man3/SSL_get_error/ - OpenSSL shutdown lifecycle: https://docs.openssl.org/3.6/man3/SSL_shutdown/
- Contract shim: https://github.com/curl/curl-fuzzer/blob/92495ed59e1b5c7daddfcd01a1909965351c6361/openssl_contract_shim.cc#L199-L248
- IMAP cleanup path: https://github.com/curl/curl-fuzzer/blob/92495ed59e1b5c7daddfcd01a1909965351c6361/proto_fuzzer/pingpong_mock_server.cc#L403-L422
OpenSSL contract assertion failed: SSL_read called on SSL ...
after SSL_shutdown returned -1 and SSL_get_error classified it as
SSL_ERROR_SYSCALL; no further I/O or SSL_shutdown is allowed
__wrap_SSL_read
ossl_shutdown lib/vtls/openssl.c:1928
ssl_cf_shutdown lib/vtls/vtls.c:1189
cshutdn_try_once_idx lib/cshutdn.c:162
cpool_discard_conn lib/conncache.c:226
Curl_cpool_destroy lib/conncache.c:279
curl_multi_cleanup lib/multi.c:3041
PingpongMockServer::HandleDetachedMulti
PingpongMockServer::HandleDetachedMulti() merely exposes the problem while destroying the multi handle and its connection cache. A peer may close incorrectly or an underlying write may fail; curl still has to obey OpenSSL's terminal-error contract.
The shim records a failed operation by SSL *, then poisons that connection only when the matching SSL_get_error() call returns SSL_ERROR_SSL or SSL_ERROR_SYSCALL.
It deliberately treats SSL_shutdown() == 0 as nonfatal. OpenSSL defines zero as an in-progress shutdown, and its documentation warns that passing zero to SSL_get_error() can misleadingly look fatal. The reported operation returned -1, not zero.
The shim's focused tests pass and cover both the zero-result exception and aborts after genuinely fatal classifications.
ossl_shutdown() should distinguish the three SSL_shutdown() result classes before deciding whether to read:
rc = SSL_shutdown(ssl)
rc == 1:
shutdown completed
rc == 0:
shutdown is still in progress; do not call SSL_get_error()
reading for the peer close_notify remains legal
rc < 0:
error = SSL_get_error(ssl, rc)
WANT_WRITE -> wait for send readiness
WANT_READ -> wait for/read the peer close_notify
SSL or SYSCALL -> stop immediately; do not call any more TLS I/O
For SSL_ERROR_SSL and SSL_ERROR_SYSCALL, the connection is already being discarded. The minimal behavior-preserving fix is therefore to log the shutdown error, set *done = TRUE, and leave ossl_shutdown() with CURLE_OK. That matches the function's existing treatment of a peer that closes without a usable close_notify, while removing the forbidden follow-up call.
In C, the important shape is:
rc = SSL_shutdown(octx->ssl);
if(rc == 1) {
*done = TRUE;
goto out;
}
if(rc < 0) {
err = SSL_get_error(octx->ssl, rc);
if(err == SSL_ERROR_WANT_WRITE) {
connssl->io_need = CURL_SSL_IO_NEED_SEND;
goto out;
}
if(err != SSL_ERROR_WANT_READ) {
/* Trace the terminal shutdown classification here. */
*done = TRUE;
goto out;
}
}
/* rc == 0 or SSL_ERROR_WANT_READ may continue to the existing read path. */The final patch should retain the existing trace messages and record the fatal classification before returning.
Add a shutdown test that forces this sequence:
SSL_shutdown()returns-1.SSL_get_error()returnsSSL_ERROR_SYSCALL(and separatelySSL_ERROR_SSL).- Verify that curl performs no subsequent
SSL_read(),SSL_write(), orSSL_shutdown()on that object. - Verify that
SSL_shutdown() == 0,SSL_ERROR_WANT_READ, andSSL_ERROR_WANT_WRITEretain their existing nonblocking behavior.
Once the ClusterFuzz input is available, minimize and keep it as a curl-fuzzer regression corpus entry as an integration check. The upstream curl test should not depend solely on that fuzzer artifact.
The reported curl revision, 1ee6ccab10521c8015c86c263a0f08865d575ec2, changes only tests/data/test20; it did not introduce this bug. The faulty shutdown fallthrough predates that revision and is still present on curl master at a5023857679007a9f0abeb5ad279612bff53836c (2026-10-30).
The original ClusterFuzz testcase was not available locally. A matching local libFuzzer build ran 31,566 IMAP mutations with the reported seed without rediscovering it, so the exact protobuf fields and underlying errno remain unknown. Those details are not needed to establish the contract violation: the supplied trace already records the fatal SSL_shutdown() result, its matching classification, and the forbidden next call.