diff options
author | David Benjamin <davidben@chromium.org> | 2014-11-30 10:01:26 +0300 |
---|---|---|
committer | Adam Langley <agl@google.com> | 2014-12-02 22:34:49 +0300 |
commit | f34a0098341852db0e17ef3ac39f2ff2ee4a23ad (patch) | |
tree | fbcc2f508bd2dadd8cddad2f726346e8bf0a0892 /ssl/ssl_lib.c | |
parent | 63246e8a9990aa11696c0d2f9f04ac3f04bc9442 (diff) |
Don't set s->state and s->server before the side is known.
If SSL_clear is called before SSL_set_{connect,accept}_state (as SSL_new does
internally), s->state will get set prematurely. Likewise, s->server is set
based on the method's ssl_accept hook, but client SSL's may be initialized from
a generic SSL_METHOD too.
Since we can't easily get rid of the generic SSL_METHODs, defer s->state and
s->server initialization until the side is known.
Change-Id: I0972e17083df22a3c09f6f087011b54c699a22e7
Reviewed-on: https://boringssl-review.googlesource.com/2439
Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'ssl/ssl_lib.c')
-rw-r--r-- | ssl/ssl_lib.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 80a8c2b6..783e8aef 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -210,7 +210,20 @@ int SSL_clear(SSL *s) } #endif - s->state=SSL_ST_BEFORE|((s->server)?SSL_ST_ACCEPT:SSL_ST_CONNECT); + /* SSL_clear may be called before or after the |s| is initialized in + * either accept or connect state. In the latter case, SSL_clear should + * preserve the half and reset |s->state| accordingly. */ + if (s->handshake_func != NULL) + { + if (s->server) + SSL_set_accept_state(s); + else + SSL_set_connect_state(s); + } + else + { + assert(s->state == 0); + } s->version=s->method->version; s->client_version=s->version; @@ -369,7 +382,6 @@ SSL *SSL_new(SSL_CTX *ctx) goto err; s->references=1; - s->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1; SSL_clear(s); |