]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Slighly change SSL_shutdown() err handling
authorMichal Rakowski <michal.rakowski@baculasystems.com>
Mon, 28 Jun 2021 09:24:12 +0000 (11:24 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:02 +0000 (09:03 +0100)
Description:
Following the docs:
https://www.openssl.org/docs/manmaster/man3/SSL_shutdown.html

(...)
RETURN VALUES
The following return values can occur:

0
The shutdown is not yet finished: the close_notify was sent but the peer
did not send it back yet. Call SSL_read() to do a bidirectional
shutdown.

Unlike most other function, returning 0 does not indicate an error.
SSL_get_error(3) should not get called, it may misleadingly indicate an
error even though no error occurred.
(..)

Which means that SSL_get_error() should not be called straight after
SSL_shutdown() returned 0.

bacula/src/lib/tls.c

index a112c15420af7453d67f4c4f59cea9350ebfe7b9..84b62fbfe0c0ad17a38c28e79b250f730e612950 100644 (file)
@@ -823,20 +823,19 @@ void tls_bsock_shutdown(BSOCKCORE *bsock)
       tid = start_bsock_timer(bsock, 60 * 2);
       err = SSL_shutdown(bsock->tls->openssl);
       stop_bsock_timer(tid);
-   }
-
 
-   switch (SSL_get_error(bsock->tls->openssl, err)) {
-   case SSL_ERROR_NONE:
-      break;
-   case SSL_ERROR_ZERO_RETURN:
-      /* TLS connection was shut down on us via a TLS protocol-level closure */
-      openssl_post_errors(bsock->get_jcr(), M_ERROR, _("TLS shutdown failure."));
-      break;
-   default:
-      /* Socket Error Occurred */
-      openssl_post_errors(bsock->get_jcr(), M_ERROR, _("TLS shutdown failure."));
-      break;
+      switch (SSL_get_error(bsock->tls->openssl, err)) {
+         case SSL_ERROR_NONE:
+            break;
+         case SSL_ERROR_ZERO_RETURN:
+            /* TLS connection was shut down on us via a TLS protocol-level closure */
+            openssl_post_errors(bsock->get_jcr(), M_ERROR, _("TLS shutdown failure."));
+            break;
+         default:
+            /* Socket Error Occurred */
+            openssl_post_errors(bsock->get_jcr(), M_ERROR, _("TLS shutdown failure."));
+            break;
+      }
    }
 }