summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2022-02-06 16:11:58 +0000
committerjsing <>2022-02-06 16:11:58 +0000
commit0ba161420113135230ceb9d4dd293ec8d325cf59 (patch)
treec1756e060f5a880913a7e1d305d10b5e65e78627
parentfde80c97b7537c9c34662547ba47a934cb8bab59 (diff)
downloadopenbsd-0ba161420113135230ceb9d4dd293ec8d325cf59.tar.gz
openbsd-0ba161420113135230ceb9d4dd293ec8d325cf59.tar.bz2
openbsd-0ba161420113135230ceb9d4dd293ec8d325cf59.zip
Remove i <= 0 checks from SSL_get_error()
In order for SSL_get_error() to work with SSL_read_ex() and SSL_write_ex() the error handling needs to be performed without checking i <= 0. This is effectively part of OpenSSL 8051ab2b6f8 and should bring the behaviour of SSL_get_error() largely inline with OpenSSL 1.1. Issue reported by Johannes Nixdorf. ok inoguchi@ tb@
-rw-r--r--src/lib/libssl/ssl_lib.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c
index ad7fe4d575..86142fa46f 100644
--- a/src/lib/libssl/ssl_lib.c
+++ b/src/lib/libssl/ssl_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_lib.c,v 1.288 2022/02/05 14:54:10 jsing Exp $ */ 1/* $OpenBSD: ssl_lib.c,v 1.289 2022/02/06 16:11:58 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -2487,15 +2487,17 @@ SSL_set_ssl_method(SSL *s, const SSL_METHOD *method)
2487int 2487int
2488SSL_get_error(const SSL *s, int i) 2488SSL_get_error(const SSL *s, int i)
2489{ 2489{
2490 int reason; 2490 unsigned long l;
2491 unsigned long l; 2491 int reason;
2492 BIO *bio; 2492 BIO *bio;
2493 2493
2494 if (i > 0) 2494 if (i > 0)
2495 return (SSL_ERROR_NONE); 2495 return (SSL_ERROR_NONE);
2496 2496
2497 /* Make things return SSL_ERROR_SYSCALL when doing SSL_do_handshake 2497 /*
2498 * etc, where we do encode the error */ 2498 * Make things return SSL_ERROR_SYSCALL when doing SSL_do_handshake
2499 * etc, where we do encode the error.
2500 */
2499 if ((l = ERR_peek_error()) != 0) { 2501 if ((l = ERR_peek_error()) != 0) {
2500 if (ERR_GET_LIB(l) == ERR_LIB_SYS) 2502 if (ERR_GET_LIB(l) == ERR_LIB_SYS)
2501 return (SSL_ERROR_SYSCALL); 2503 return (SSL_ERROR_SYSCALL);
@@ -2503,7 +2505,7 @@ SSL_get_error(const SSL *s, int i)
2503 return (SSL_ERROR_SSL); 2505 return (SSL_ERROR_SSL);
2504 } 2506 }
2505 2507
2506 if ((i < 0) && SSL_want_read(s)) { 2508 if (SSL_want_read(s)) {
2507 bio = SSL_get_rbio(s); 2509 bio = SSL_get_rbio(s);
2508 if (BIO_should_read(bio)) { 2510 if (BIO_should_read(bio)) {
2509 return (SSL_ERROR_WANT_READ); 2511 return (SSL_ERROR_WANT_READ);
@@ -2530,7 +2532,7 @@ SSL_get_error(const SSL *s, int i)
2530 } 2532 }
2531 } 2533 }
2532 2534
2533 if ((i < 0) && SSL_want_write(s)) { 2535 if (SSL_want_write(s)) {
2534 bio = SSL_get_wbio(s); 2536 bio = SSL_get_wbio(s);
2535 if (BIO_should_write(bio)) { 2537 if (BIO_should_write(bio)) {
2536 return (SSL_ERROR_WANT_WRITE); 2538 return (SSL_ERROR_WANT_WRITE);
@@ -2550,15 +2552,14 @@ SSL_get_error(const SSL *s, int i)
2550 return (SSL_ERROR_SYSCALL); 2552 return (SSL_ERROR_SYSCALL);
2551 } 2553 }
2552 } 2554 }
2553 if ((i < 0) && SSL_want_x509_lookup(s)) { 2555
2556 if (SSL_want_x509_lookup(s))
2554 return (SSL_ERROR_WANT_X509_LOOKUP); 2557 return (SSL_ERROR_WANT_X509_LOOKUP);
2555 }
2556 2558
2557 if (i == 0) { 2559 if ((s->internal->shutdown & SSL_RECEIVED_SHUTDOWN) &&
2558 if ((s->internal->shutdown & SSL_RECEIVED_SHUTDOWN) && 2560 (s->s3->warn_alert == SSL_AD_CLOSE_NOTIFY))
2559 (s->s3->warn_alert == SSL_AD_CLOSE_NOTIFY)) 2561 return (SSL_ERROR_ZERO_RETURN);
2560 return (SSL_ERROR_ZERO_RETURN); 2562
2561 }
2562 return (SSL_ERROR_SYSCALL); 2563 return (SSL_ERROR_SYSCALL);
2563} 2564}
2564 2565