Skip to content

Commit c03a62f

Browse files
rzikmCopilot
andcommitted
Preserve errno across the SSL_peek in CryptoNative_SslHandshake too
Mirror the errno guard just added to CryptoNative_SslDoHandshake in the buffered CryptoNative_SslHandshake shim, which is likewise P/Invoked with SetLastError=true and peeks before SSL_do_handshake. Keeps the two handshake entry points consistent so a peek can never leave a stale errno that misrepresents the handshake result. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 89084543-7d70-4562-8776-d4ca1baa3c7c
1 parent 9c125e0 commit c03a62f

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

  • src/native/libs/System.Security.Cryptography.Native

‎src/native/libs/System.Security.Cryptography.Native/pal_ssl.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,12 @@ int32_t CryptoNative_SslHandshake(
567567

568568
// this peek ensures that the SSL handshake state machine starts processing
569569
// renegotiation and post-handshake client cert requests
570+
// Guard errno the same way CryptoNative_SslDoHandshake does: this shim is also
571+
// P/Invoked with SetLastError=true, so save/restore errno around SSL_peek so the
572+
// last error reflects the SSL_do_handshake attempt rather than the peek.
573+
int peekErrno = errno;
570574
SSL_peek(ssl, NULL, 0);
575+
errno = peekErrno;
571576

572577
int32_t result = SSL_do_handshake(ssl);
573578
*errorCode = (result == 1) ? SSL_ERROR_NONE : CryptoNative_SslGetError(ssl, result);

0 commit comments

Comments
 (0)