mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-28 07:28:13 +08:00
Merge pull request #2787 from cesanta/nicer
play nicer to intermediate OOMs in OpenSSL
This commit is contained in:
commit
8fd7e87333
25
mongoose.c
25
mongoose.c
@ -12497,13 +12497,23 @@ static void ssl_keylog_cb(const SSL *ssl, const char *line) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void mg_tls_free(struct mg_connection *c) {
|
||||||
|
struct mg_tls *tls = (struct mg_tls *) c->tls;
|
||||||
|
if (tls == NULL) return;
|
||||||
|
SSL_free(tls->ssl);
|
||||||
|
SSL_CTX_free(tls->ctx);
|
||||||
|
BIO_meth_free(tls->bm);
|
||||||
|
free(tls);
|
||||||
|
c->tls = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
|
void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
|
||||||
struct mg_tls *tls = (struct mg_tls *) calloc(1, sizeof(*tls));
|
struct mg_tls *tls = (struct mg_tls *) calloc(1, sizeof(*tls));
|
||||||
const char *id = "mongoose";
|
const char *id = "mongoose";
|
||||||
static unsigned char s_initialised = 0;
|
static unsigned char s_initialised = 0;
|
||||||
BIO *bio = NULL;
|
BIO *bio = NULL;
|
||||||
int rc;
|
int rc;
|
||||||
|
c->tls = tls;
|
||||||
if (tls == NULL) {
|
if (tls == NULL) {
|
||||||
mg_error(c, "TLS OOM");
|
mg_error(c, "TLS OOM");
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -12603,7 +12613,6 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
|
|||||||
BIO_set_data(bio, c);
|
BIO_set_data(bio, c);
|
||||||
SSL_set_bio(tls->ssl, bio, bio);
|
SSL_set_bio(tls->ssl, bio, bio);
|
||||||
|
|
||||||
c->tls = tls;
|
|
||||||
c->is_tls = 1;
|
c->is_tls = 1;
|
||||||
c->is_tls_hs = 1;
|
c->is_tls_hs = 1;
|
||||||
if (c->is_client && c->is_resolving == 0 && c->is_connecting == 0) {
|
if (c->is_client && c->is_resolving == 0 && c->is_connecting == 0) {
|
||||||
@ -12612,7 +12621,7 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
|
|||||||
MG_DEBUG(("%lu SSL %s OK", c->id, c->is_accepted ? "accept" : "client"));
|
MG_DEBUG(("%lu SSL %s OK", c->id, c->is_accepted ? "accept" : "client"));
|
||||||
return;
|
return;
|
||||||
fail:
|
fail:
|
||||||
free(tls);
|
mg_tls_free(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mg_tls_handshake(struct mg_connection *c) {
|
void mg_tls_handshake(struct mg_connection *c) {
|
||||||
@ -12628,16 +12637,6 @@ void mg_tls_handshake(struct mg_connection *c) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mg_tls_free(struct mg_connection *c) {
|
|
||||||
struct mg_tls *tls = (struct mg_tls *) c->tls;
|
|
||||||
if (tls == NULL) return;
|
|
||||||
SSL_free(tls->ssl);
|
|
||||||
SSL_CTX_free(tls->ctx);
|
|
||||||
BIO_meth_free(tls->bm);
|
|
||||||
free(tls);
|
|
||||||
c->tls = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t mg_tls_pending(struct mg_connection *c) {
|
size_t mg_tls_pending(struct mg_connection *c) {
|
||||||
struct mg_tls *tls = (struct mg_tls *) c->tls;
|
struct mg_tls *tls = (struct mg_tls *) c->tls;
|
||||||
return tls == NULL ? 0 : (size_t) SSL_pending(tls->ssl);
|
return tls == NULL ? 0 : (size_t) SSL_pending(tls->ssl);
|
||||||
|
@ -106,13 +106,23 @@ static void ssl_keylog_cb(const SSL *ssl, const char *line) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void mg_tls_free(struct mg_connection *c) {
|
||||||
|
struct mg_tls *tls = (struct mg_tls *) c->tls;
|
||||||
|
if (tls == NULL) return;
|
||||||
|
SSL_free(tls->ssl);
|
||||||
|
SSL_CTX_free(tls->ctx);
|
||||||
|
BIO_meth_free(tls->bm);
|
||||||
|
free(tls);
|
||||||
|
c->tls = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
|
void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
|
||||||
struct mg_tls *tls = (struct mg_tls *) calloc(1, sizeof(*tls));
|
struct mg_tls *tls = (struct mg_tls *) calloc(1, sizeof(*tls));
|
||||||
const char *id = "mongoose";
|
const char *id = "mongoose";
|
||||||
static unsigned char s_initialised = 0;
|
static unsigned char s_initialised = 0;
|
||||||
BIO *bio = NULL;
|
BIO *bio = NULL;
|
||||||
int rc;
|
int rc;
|
||||||
|
c->tls = tls;
|
||||||
if (tls == NULL) {
|
if (tls == NULL) {
|
||||||
mg_error(c, "TLS OOM");
|
mg_error(c, "TLS OOM");
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -212,7 +222,6 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
|
|||||||
BIO_set_data(bio, c);
|
BIO_set_data(bio, c);
|
||||||
SSL_set_bio(tls->ssl, bio, bio);
|
SSL_set_bio(tls->ssl, bio, bio);
|
||||||
|
|
||||||
c->tls = tls;
|
|
||||||
c->is_tls = 1;
|
c->is_tls = 1;
|
||||||
c->is_tls_hs = 1;
|
c->is_tls_hs = 1;
|
||||||
if (c->is_client && c->is_resolving == 0 && c->is_connecting == 0) {
|
if (c->is_client && c->is_resolving == 0 && c->is_connecting == 0) {
|
||||||
@ -221,7 +230,7 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
|
|||||||
MG_DEBUG(("%lu SSL %s OK", c->id, c->is_accepted ? "accept" : "client"));
|
MG_DEBUG(("%lu SSL %s OK", c->id, c->is_accepted ? "accept" : "client"));
|
||||||
return;
|
return;
|
||||||
fail:
|
fail:
|
||||||
free(tls);
|
mg_tls_free(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mg_tls_handshake(struct mg_connection *c) {
|
void mg_tls_handshake(struct mg_connection *c) {
|
||||||
@ -237,16 +246,6 @@ void mg_tls_handshake(struct mg_connection *c) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mg_tls_free(struct mg_connection *c) {
|
|
||||||
struct mg_tls *tls = (struct mg_tls *) c->tls;
|
|
||||||
if (tls == NULL) return;
|
|
||||||
SSL_free(tls->ssl);
|
|
||||||
SSL_CTX_free(tls->ctx);
|
|
||||||
BIO_meth_free(tls->bm);
|
|
||||||
free(tls);
|
|
||||||
c->tls = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t mg_tls_pending(struct mg_connection *c) {
|
size_t mg_tls_pending(struct mg_connection *c) {
|
||||||
struct mg_tls *tls = (struct mg_tls *) c->tls;
|
struct mg_tls *tls = (struct mg_tls *) c->tls;
|
||||||
return tls == NULL ? 0 : (size_t) SSL_pending(tls->ssl);
|
return tls == NULL ? 0 : (size_t) SSL_pending(tls->ssl);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user