mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-08 16:11:18 +00:00
Fix use-after-free
Free keys and cert before conf, not after PUBLISHED_FROM=5628f56eb6973a779179d641fb425d0f14db39cf
This commit is contained in:
1 parent
260229a4d1
commit
d6259332d4
1 file changed
+1
-2
+1
-2
@@ -4428,7 +4428,6 @@ static enum mg_ssl_if_result mg_ssl_if_mbed_err(struct mg_connection *nc,
|
|||||||
|
|
||||||
static void mg_ssl_if_mbed_free_certs_and_keys(struct mg_ssl_if_ctx *ctx) {
|
static void mg_ssl_if_mbed_free_certs_and_keys(struct mg_ssl_if_ctx *ctx) {
|
||||||
if (ctx->cert != NULL) {
|
if (ctx->cert != NULL) {
|
||||||
ctx->conf->key_cert = NULL;
|
|
||||||
mbedtls_x509_crt_free(ctx->cert);
|
mbedtls_x509_crt_free(ctx->cert);
|
||||||
MG_FREE(ctx->cert);
|
MG_FREE(ctx->cert);
|
||||||
ctx->cert = NULL;
|
ctx->cert = NULL;
|
||||||
@@ -4500,11 +4499,11 @@ void mg_ssl_if_conn_free(struct mg_connection *nc) {
|
|||||||
mbedtls_ssl_free(ctx->ssl);
|
mbedtls_ssl_free(ctx->ssl);
|
||||||
MG_FREE(ctx->ssl);
|
MG_FREE(ctx->ssl);
|
||||||
}
|
}
|
||||||
|
mg_ssl_if_mbed_free_certs_and_keys(ctx);
|
||||||
if (ctx->conf != NULL) {
|
if (ctx->conf != NULL) {
|
||||||
mbedtls_ssl_config_free(ctx->conf);
|
mbedtls_ssl_config_free(ctx->conf);
|
||||||
MG_FREE(ctx->conf);
|
MG_FREE(ctx->conf);
|
||||||
}
|
}
|
||||||
mg_ssl_if_mbed_free_certs_and_keys(ctx);
|
|
||||||
memset(ctx, 0, sizeof(*ctx));
|
memset(ctx, 0, sizeof(*ctx));
|
||||||
MG_FREE(ctx);
|
MG_FREE(ctx);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user