Merge pull request #1871 from cesanta/straddr

Fix mg_straddr() stack overwrite
This commit is contained in:
Sergey Lyubka 2022-11-21 07:00:23 +00:00 committed by GitHub
commit db81c30d24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -3314,7 +3314,7 @@ size_t mg_printf(struct mg_connection *c, const char *fmt, ...) {
}
char *mg_straddr(struct mg_addr *a, char *buf, size_t len) {
char tmp[30];
char tmp[40];
const char *fmt = a->is_ip6 ? "[%s]:%d" : "%s:%d";
mg_ntoa(a, tmp, sizeof(tmp));
mg_snprintf(buf, len, fmt, tmp, (int) mg_ntohs(a->port));

View File

@ -21,7 +21,7 @@ size_t mg_printf(struct mg_connection *c, const char *fmt, ...) {
}
char *mg_straddr(struct mg_addr *a, char *buf, size_t len) {
char tmp[30];
char tmp[40];
const char *fmt = a->is_ip6 ? "[%s]:%d" : "%s:%d";
mg_ntoa(a, tmp, sizeof(tmp));
mg_snprintf(buf, len, fmt, tmp, (int) mg_ntohs(a->port));