diff options
author | Tomas Mraz <tomas@openssl.org> | 2021-05-12 19:15:27 +0200 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2021-05-13 19:26:06 +0200 |
commit | afecd85db1359b5a62c037b8a507b928541c779c (patch) | |
tree | 26c1def792b0e9e80a8042ef87e9d5cfbc9093d1 /crypto/bio | |
parent | 2bdec3b037264540014120a02217fc67bf355f11 (diff) |
Replace some of the ERR_clear_error() calls with mark calls
Fixes #15219
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/15253)
Diffstat (limited to 'crypto/bio')
-rw-r--r-- | crypto/bio/bio_lib.c | 8 | ||||
-rw-r--r-- | crypto/bio/bss_conn.c | 8 |
2 files changed, 11 insertions, 5 deletions
diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c index 5cdd6d7cfd..575107634c 100644 --- a/crypto/bio/bio_lib.c +++ b/crypto/bio/bio_lib.c @@ -870,7 +870,8 @@ int BIO_do_connect_retry(BIO *bio, int timeout, int nap_milliseconds) BIO_set_nbio(bio, !blocking); retry: - rv = BIO_do_connect(bio); /* This may indirectly call ERR_clear_error(); */ + ERR_set_mark(); + rv = BIO_do_connect(bio); if (rv <= 0) { /* could be timeout or retryable error or fatal error */ int err = ERR_peek_last_error(); @@ -897,7 +898,7 @@ int BIO_do_connect_retry(BIO *bio, int timeout, int nap_milliseconds) } } if (timeout >= 0 && do_retry) { - ERR_clear_error(); /* using ERR_pop_to_mark() would be cleaner */ + ERR_pop_to_mark(); /* will not actually wait if timeout == 0 (i.e., blocking BIO): */ rv = bio_wait(bio, max_time, nap_milliseconds); if (rv > 0) @@ -905,11 +906,14 @@ int BIO_do_connect_retry(BIO *bio, int timeout, int nap_milliseconds) ERR_raise(ERR_LIB_BIO, rv == 0 ? BIO_R_CONNECT_TIMEOUT : BIO_R_CONNECT_ERROR); } else { + ERR_clear_last_mark(); rv = -1; if (err == 0) /* missing error queue entry */ /* workaround: general error */ ERR_raise(ERR_LIB_BIO, BIO_R_CONNECT_ERROR); } + } else { + ERR_clear_last_mark(); } return rv; diff --git a/crypto/bio/bss_conn.c b/crypto/bio/bss_conn.c index 7aaae65bc2..3ab2c0d4ba 100644 --- a/crypto/bio/bss_conn.c +++ b/crypto/bio/bss_conn.c @@ -155,6 +155,7 @@ static int conn_state(BIO *b, BIO_CONNECT *c) case BIO_CONN_S_CONNECT: BIO_clear_retry_flags(b); + ERR_set_mark(); ret = BIO_connect(b->num, BIO_ADDRINFO_address(c->addr_iter), BIO_SOCK_KEEPALIVE | c->connect_mode); b->retry_reason = 0; @@ -163,7 +164,7 @@ static int conn_state(BIO *b, BIO_CONNECT *c) BIO_set_retry_special(b); c->state = BIO_CONN_S_BLOCKED_CONNECT; b->retry_reason = BIO_RR_CONNECT; - ERR_clear_error(); + ERR_pop_to_mark(); } else if ((c->addr_iter = BIO_ADDRINFO_next(c->addr_iter)) != NULL) { /* @@ -171,9 +172,10 @@ static int conn_state(BIO *b, BIO_CONNECT *c) */ BIO_closesocket(b->num); c->state = BIO_CONN_S_CREATE_SOCKET; - ERR_clear_error(); + ERR_pop_to_mark(); break; } else { + ERR_clear_last_mark(); ERR_raise_data(ERR_LIB_SYS, get_last_socket_error(), "calling connect(%s, %s)", c->param_hostname, c->param_service); @@ -182,6 +184,7 @@ static int conn_state(BIO *b, BIO_CONNECT *c) } goto exit_loop; } else { + ERR_clear_last_mark(); c->state = BIO_CONN_S_OK; } break; @@ -196,7 +199,6 @@ static int conn_state(BIO *b, BIO_CONNECT *c) */ BIO_closesocket(b->num); c->state = BIO_CONN_S_CREATE_SOCKET; - ERR_clear_error(); break; } ERR_raise_data(ERR_LIB_SYS, i, |