Add a helper function for resetting SSL_get_error state.
We repeat this in a bunch of places.
Change-Id: Iee2c95a13e1645453f101d8be4be9ac78d520387
Reviewed-on: https://boringssl-review.googlesource.com/13051
Reviewed-by: David Benjamin <davidben@google.com>
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
index 806bdba..2e9f4a6 100644
--- a/ssl/ssl_lib.c
+++ b/ssl/ssl_lib.c
@@ -612,11 +612,16 @@
return ssl->wbio;
}
-int SSL_do_handshake(SSL *ssl) {
+void ssl_reset_error_state(SSL *ssl) {
+ /* Functions which use |SSL_get_error| must reset I/O and error state on
+ * entry. */
ssl->rwstate = SSL_NOTHING;
- /* Functions which use SSL_get_error must clear the error queue on entry. */
ERR_clear_error();
ERR_clear_system_error();
+}
+
+int SSL_do_handshake(SSL *ssl) {
+ ssl_reset_error_state(ssl);
if (ssl->handshake_func == NULL) {
OPENSSL_PUT_ERROR(SSL, SSL_R_CONNECTION_TYPE_NOT_SET);
@@ -735,10 +740,7 @@
}
static int ssl_read_impl(SSL *ssl, void *buf, int num, int peek) {
- ssl->rwstate = SSL_NOTHING;
- /* Functions which use SSL_get_error must clear the error queue on entry. */
- ERR_clear_error();
- ERR_clear_system_error();
+ ssl_reset_error_state(ssl);
if (ssl->handshake_func == NULL) {
OPENSSL_PUT_ERROR(SSL, SSL_R_UNINITIALIZED);
@@ -784,10 +786,7 @@
}
int SSL_write(SSL *ssl, const void *buf, int num) {
- ssl->rwstate = SSL_NOTHING;
- /* Functions which use SSL_get_error must clear the error queue on entry. */
- ERR_clear_error();
- ERR_clear_system_error();
+ ssl_reset_error_state(ssl);
if (ssl->handshake_func == NULL) {
OPENSSL_PUT_ERROR(SSL, SSL_R_UNINITIALIZED);
@@ -815,10 +814,7 @@
}
int SSL_shutdown(SSL *ssl) {
- ssl->rwstate = SSL_NOTHING;
- /* Functions which use SSL_get_error must clear the error queue on entry. */
- ERR_clear_error();
- ERR_clear_system_error();
+ ssl_reset_error_state(ssl);
if (ssl->handshake_func == NULL) {
OPENSSL_PUT_ERROR(SSL, SSL_R_UNINITIALIZED);