]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/hostname-util: do truncation last when cleaning up 10897/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 5 Dec 2018 11:27:29 +0000 (12:27 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 10 Dec 2018 08:56:56 +0000 (09:56 +0100)
This allows more of the original name to be used if there are invalid
chars in the beginning.

src/basic/hostname-util.c
src/test/test-hostname-util.c

index 0230821d22a727fdf96b6181aea2610a7a88c200..5bfa028b39306b48a2482fd51d6217a77eafe063 100644 (file)
@@ -143,9 +143,7 @@ char* hostname_cleanup(char *s) {
 
         assert(s);
 
-        strshorten(s, HOST_NAME_MAX);
-
-        for (p = s, d = s, dot = hyphen = true; *p; p++)
+        for (p = s, d = s, dot = hyphen = true; *p && d - s < HOST_NAME_MAX; p++)
                 if (*p == '.') {
                         if (dot || hyphen)
                                 continue;
index 596830f5f2acd16a6904b8ead41d0b3c8801c2ad..4126a24ceb9fd10444e59a759c56b24309d7f781 100644 (file)
@@ -85,6 +85,8 @@ static void test_hostname_cleanup(void) {
         assert_se(streq(hostname_cleanup(s), "foo.bar"));
         s = strdupa("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
         assert_se(streq(hostname_cleanup(s), "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
+        s = strdupa("xxxx........xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
+        assert_se(streq(hostname_cleanup(s), "xxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
 }
 
 static void test_read_etc_hostname(void) {