From 0f157bd23b7fe7306f7eb777b3d45966e650c473 Mon Sep 17 00:00:00 2001 From: "Sergio R. Caprile" Date: Mon, 16 Nov 2026 15:48:16 -0300 Subject: [PATCH] don't use strncpy on a mg_str --- mongoose.c | 4 ++-- src/tls_builtin.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mongoose.c b/mongoose.c index 4abdf2fc..45a24966 100644 --- a/mongoose.c +++ b/mongoose.c @@ -21153,8 +21153,8 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) { mg_error(c, "hostname too long"); return; } - strncpy((char *) tls->hostname, opts->name.buf, sizeof(tls->hostname) - 1); - tls->hostname[opts->name.len] = 0; + memcpy(tls->hostname, opts->name.buf, opts->name.len); + tls->hostname[opts->name.len] = '\0'; } // server CA certificate; parse PEM [bundle] or DER diff --git a/src/tls_builtin.c b/src/tls_builtin.c index 65acd2a4..815096b8 100644 --- a/src/tls_builtin.c +++ b/src/tls_builtin.c @@ -2748,8 +2748,8 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) { mg_error(c, "hostname too long"); return; } - strncpy((char *) tls->hostname, opts->name.buf, sizeof(tls->hostname) - 1); - tls->hostname[opts->name.len] = 0; + memcpy(tls->hostname, opts->name.buf, opts->name.len); + tls->hostname[opts->name.len] = '\0'; } // server CA certificate; parse PEM [bundle] or DER