From 39ede7cc377dcb057411c80509e5fde8901f20fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 11 Dec 2020 16:52:30 +0100 Subject: [PATCH] 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(). --- src/shared/hostname-setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/hostname-setup.c b/src/shared/hostname-setup.c index 42a8ada144..19e528604b 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))