From: Aki Tuomi Date: Sun, 19 Jul 2020 15:06:14 +0000 (+0300) Subject: misc.cc: Resize hostname to final size in getCarbonHostname() X-Git-Tag: dnsdist-1.5.0~6^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57f8ac68b4fa7063fd2cac4d5b77045e0255c770;p=thirdparty%2Fpdns.git misc.cc: Resize hostname to final size in getCarbonHostname() In 5c21b47fbc35ddcb8d939eb8541c6c3bad1080a8 we change how hostname is allocated. We allocate getMaxHostNameSize for string, then give the raw buffer for gethostname function, but forget to resize the string into actual result length, causing the carbon output to include trailing NUL bytes after hostname. --- diff --git a/pdns/misc.cc b/pdns/misc.cc index 0215e8e42c..ef743a8e75 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -1589,6 +1589,7 @@ std::string getCarbonHostName() } boost::replace_all(hostname, ".", "_"); + hostname.resize(strlen(hostname.c_str())); return hostname; }