From 6ce2e48dd31643b8c2dad68cb87957ca40708e84 Mon Sep 17 00:00:00 2001 From: Mark Cottrell Date: Tue, 6 Apr 2021 11:07:15 -0700 Subject: [PATCH] fixed msvc errors around VLAs --- mongoose.c | 10 ++++++---- src/tls.c | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/mongoose.c b/mongoose.c index f3cf64d1..e8776910 100644 --- a/mongoose.c +++ b/mongoose.c @@ -3593,9 +3593,10 @@ int mg_tls_init(struct mg_connection *c, struct mg_tls_opts *opts) { mbedtls_ssl_conf_ca_chain(&tls->conf, &tls->ca, NULL); #endif if (opts->srvname.len > 0) { - char buf[opts->srvname.len + 1]; - sprintf(buf, "%.*s", (int) opts->srvname.len, opts->srvname.ptr); + char mem[128], *buf = mem; + mg_asprintf(&buf, sizeof(mem), "%.*s", (int) opts->srvname.len, opts->srvname.ptr); mbedtls_ssl_set_hostname(&tls->ssl, buf); + if (buf != mem) free(buf); } mbedtls_ssl_conf_authmode(&tls->conf, MBEDTLS_SSL_VERIFY_REQUIRED); } @@ -3768,9 +3769,10 @@ int mg_tls_init(struct mg_connection *c, struct mg_tls_opts *opts) { } if (opts->ciphers != NULL) SSL_set_cipher_list(tls->ssl, opts->ciphers); if (opts->srvname.len > 0) { - char buf[opts->srvname.len + 1]; - sprintf(buf, "%.*s", (int) opts->srvname.len, opts->srvname.ptr); + char mem[128], *buf = mem; + mg_asprintf(&buf, sizeof(mem), "%.*s", (int) opts->srvname.len, opts->srvname.ptr); SSL_set_tlsext_host_name(tls->ssl, buf); + if (buf != mem) free(buf); } c->tls = tls; c->is_tls = 1; diff --git a/src/tls.c b/src/tls.c index 7aa0fa6f..81f67f52 100644 --- a/src/tls.c +++ b/src/tls.c @@ -117,9 +117,10 @@ int mg_tls_init(struct mg_connection *c, struct mg_tls_opts *opts) { mbedtls_ssl_conf_ca_chain(&tls->conf, &tls->ca, NULL); #endif if (opts->srvname.len > 0) { - char buf[opts->srvname.len + 1]; - sprintf(buf, "%.*s", (int) opts->srvname.len, opts->srvname.ptr); + char mem[128], *buf = mem; + mg_asprintf(&buf, sizeof(mem), "%.*s", (int) opts->srvname.len, opts->srvname.ptr); mbedtls_ssl_set_hostname(&tls->ssl, buf); + if (buf != mem) free(buf); } mbedtls_ssl_conf_authmode(&tls->conf, MBEDTLS_SSL_VERIFY_REQUIRED); } @@ -292,9 +293,10 @@ int mg_tls_init(struct mg_connection *c, struct mg_tls_opts *opts) { } if (opts->ciphers != NULL) SSL_set_cipher_list(tls->ssl, opts->ciphers); if (opts->srvname.len > 0) { - char buf[opts->srvname.len + 1]; - sprintf(buf, "%.*s", (int) opts->srvname.len, opts->srvname.ptr); + char mem[128], *buf = mem; + mg_asprintf(&buf, sizeof(mem), "%.*s", (int) opts->srvname.len, opts->srvname.ptr); SSL_set_tlsext_host_name(tls->ssl, buf); + if (buf != mem) free(buf); } c->tls = tls; c->is_tls = 1;