From: Zbigniew Jędrzejewski-Szmek Date: Fri, 11 Dec 2020 15:52:30 +0000 (+0100) Subject: shared/hostname-setup: leave the terminator byte alone X-Git-Tag: v248-rc1~491^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=39ede7cc377dcb057411c80509e5fde8901f20fb;p=thirdparty%2Fsystemd.git shared/hostname-setup: leave the terminator byte alone gethostname(3) says it's unspecified whether the string is properly terminated when the hostname is too long. We created a buffer with one extra byte, and it seems the intent was to let that byte serve as terminator even if we get an unterminated string from gethostname(). --- diff --git a/src/shared/hostname-setup.c b/src/shared/hostname-setup.c index 42a8ada1447..19e528604bd 100644 --- a/src/shared/hostname-setup.c +++ b/src/shared/hostname-setup.c @@ -22,7 +22,7 @@ static int sethostname_idempotent_full(const char *s, bool really) { assert(s); - if (gethostname(buf, sizeof(buf)) < 0) + if (gethostname(buf, sizeof(buf) - 1) < 0) return -errno; if (streq(buf, s))