]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/hostname-setup: leave the terminator byte alone
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 11 Dec 2020 15:52:30 +0000 (16:52 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 16 Dec 2020 10:02:17 +0000 (11:02 +0100)
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

index 42a8ada14475bfae7af0c1f7af49a38ba3fac132..19e528604bdfd59b67e296e480bfd431b2a60615 100644 (file)
@@ -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))