Commit 48057977 authored by Marko Mikulicic's avatar Marko Mikulicic Committed by Cesanta Bot

Fix hexdump memory overflow

PUBLISHED_FROM=a6f3f33432ce43b6d4462de623ba61a53e7f18df
parent 4c038508
......@@ -8667,6 +8667,9 @@ int mg_hexdump(const void *buf, int len, char *dst, int dst_len) {
if (i > 0) n += snprintf(dst + n, dst_len - n, " %s\n", ascii);
n += snprintf(dst + n, dst_len - n, "%04x ", i);
}
if (dst_len - n < 0) {
return n;
}
n += snprintf(dst + n, dst_len - n, " %02x", p[i]);
ascii[idx] = p[i] < 0x20 || p[i] > 0x7e ? '.' : p[i];
ascii[idx + 1] = '\0';
......@@ -10787,7 +10790,8 @@ void mg_tun_log_frame(struct mg_tun_frame *frame) {
#if MG_ENABLE_HEXDUMP
{
char hex[512];
mg_hexdump(frame->body.p, frame->body.len, hex, sizeof(hex));
mg_hexdump(frame->body.p, frame->body.len, hex, sizeof(hex) - 1);
hex[sizeof(hex) - 1] = '\0';
LOG(LL_DEBUG, ("body:\n%s", hex));
}
#else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment