提交 f6483fc2 编写于 作者: R Richard Levitte

BIO_s_connect: add an error state and use it

If no connection could be made, addr_iter will eventually end up being
NULL, and if the user didn't check the returned error value, the
BIO_CONN_S_CONNECT code will be performed again and will crash.

So instead, we add a state BIO_CONN_S_CONNECT_ERROR that we enter into
when we run out of addresses to try.  That state will just simply say
"error" back, until the user does something better with the BIO, such
as free it or reset it.
Reviewed-by: NMatt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/10333)
上级 7bb50cbc
...@@ -54,6 +54,7 @@ void BIO_CONNECT_free(BIO_CONNECT *a); ...@@ -54,6 +54,7 @@ void BIO_CONNECT_free(BIO_CONNECT *a);
#define BIO_CONN_S_CONNECT 4 #define BIO_CONN_S_CONNECT 4
#define BIO_CONN_S_OK 5 #define BIO_CONN_S_OK 5
#define BIO_CONN_S_BLOCKED_CONNECT 6 #define BIO_CONN_S_BLOCKED_CONNECT 6
#define BIO_CONN_S_CONNECT_ERROR 7
static const BIO_METHOD methods_connectp = { static const BIO_METHOD methods_connectp = {
BIO_TYPE_CONNECT, BIO_TYPE_CONNECT,
...@@ -174,7 +175,8 @@ static int conn_state(BIO *b, BIO_CONNECT *c) ...@@ -174,7 +175,8 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
ERR_add_error_data(4, ERR_add_error_data(4,
"hostname=", c->param_hostname, "hostname=", c->param_hostname,
" service=", c->param_service); " service=", c->param_service);
BIOerr(BIO_F_CONN_STATE, BIO_R_CONNECT_ERROR); c->state = BIO_CONN_S_CONNECT_ERROR;
break;
} }
goto exit_loop; goto exit_loop;
} else { } else {
...@@ -197,6 +199,11 @@ static int conn_state(BIO *b, BIO_CONNECT *c) ...@@ -197,6 +199,11 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
c->state = BIO_CONN_S_OK; c->state = BIO_CONN_S_OK;
break; break;
case BIO_CONN_S_CONNECT_ERROR:
BIOerr(BIO_F_CONN_STATE, BIO_R_CONNECT_ERROR);
ret = 0;
goto exit_loop;
case BIO_CONN_S_OK: case BIO_CONN_S_OK:
ret = 1; ret = 1;
goto exit_loop; goto exit_loop;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册