Compare commits

...
1 Commits
Author SHA1 Message Date
Sergio R. Caprile 0f157bd23b don't use strncpy on a mg_str 2026-11-16 15:48:16 -03:00
2 changed files with 4 additions and 4 deletions

No files matched your search

+2 -2
View File
@@ -21153,8 +21153,8 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
mg_error(c, "hostname too long"); mg_error(c, "hostname too long");
return; return;
} }
strncpy((char *) tls->hostname, opts->name.buf, sizeof(tls->hostname) - 1); memcpy(tls->hostname, opts->name.buf, opts->name.len);
tls->hostname[opts->name.len] = 0; tls->hostname[opts->name.len] = '\0';
} }
// server CA certificate; parse PEM [bundle] or DER // server CA certificate; parse PEM [bundle] or DER
+2 -2
View File
@@ -2748,8 +2748,8 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
mg_error(c, "hostname too long"); mg_error(c, "hostname too long");
return; return;
} }
strncpy((char *) tls->hostname, opts->name.buf, sizeof(tls->hostname) - 1); memcpy(tls->hostname, opts->name.buf, opts->name.len);
tls->hostname[opts->name.len] = 0; tls->hostname[opts->name.len] = '\0';
} }
// server CA certificate; parse PEM [bundle] or DER // server CA certificate; parse PEM [bundle] or DER