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: rec-4.3.4~1^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03a75e14934603c880739e226b7b691ffd0e3902;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. (cherry picked from commit 57f8ac68b4fa7063fd2cac4d5b77045e0255c770) --- diff --git a/pdns/misc.cc b/pdns/misc.cc index 5cb4dbe812..332a7c2a9c 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -1597,6 +1597,7 @@ std::string getCarbonHostName() } boost::replace_all(hostname, ".", "_"); + hostname.resize(strlen(hostname.c_str())); return hostname; }