From b65574bef233474e915fdf18614aa211e31cc6c2 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 5 Jun 2014 17:05:12 +0000 Subject: [PATCH] Stratum: extract_sockaddr: Truncate overlong addresses rather than stack overflow Thanks to Mick Ayzenberg for finding this! --- util.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/util.c b/util.c index 16aa98a4..77f20431 100644 --- a/util.c +++ b/util.c @@ -1219,6 +1219,13 @@ bool extract_sockaddr(char *url, char **sockaddr_url, char **sockaddr_port) if (url_len < 1) return false; + + if (url_len >= sizeof(url_address)) + { + applog(LOG_WARNING, "%s: Truncating overflowed address '%.*s'", + __func__, url_len, url_begin); + url_len = sizeof(url_address) - 1; + } sprintf(url_address, "%.*s", url_len, url_begin);