mirror of
https://github.com/systemd/systemd.git
synced 2026-08-10 17:14:31 +00:00
hostname-util: strip all trailing separators in hostname_cleanup() (#43077)
Fixes #43054.
This commit is contained in:
@@ -132,7 +132,7 @@ char* hostname_cleanup(char *s) {
|
||||
hyphen = false;
|
||||
}
|
||||
|
||||
if (d > s && IN_SET(d[-1], '-', '.'))
|
||||
while (d > s && IN_SET(d[-1], '-', '.'))
|
||||
/* The dot can occur at most once, but we might have multiple
|
||||
* hyphens, hence the loop */
|
||||
d--;
|
||||
|
||||
@@ -85,6 +85,14 @@ TEST(hostname_cleanup) {
|
||||
ASSERT_STREQ(hostname_cleanup(s), "foo.bar");
|
||||
s = strdupa_safe("foo.bar..");
|
||||
ASSERT_STREQ(hostname_cleanup(s), "foo.bar");
|
||||
s = strdupa_safe("foobar--");
|
||||
ASSERT_STREQ(hostname_cleanup(s), "foobar");
|
||||
s = strdupa_safe("foobar-.");
|
||||
ASSERT_STREQ(hostname_cleanup(s), "foobar");
|
||||
s = strdupa_safe("foobar.-");
|
||||
ASSERT_STREQ(hostname_cleanup(s), "foobar");
|
||||
s = strdupa_safe("foobar-.-");
|
||||
ASSERT_STREQ(hostname_cleanup(s), "foobar");
|
||||
s = strdupa_safe("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
|
||||
ASSERT_STREQ(hostname_cleanup(s), "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
|
||||
s = strdupa_safe("xxxx........xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
|
||||
|
||||
Reference in New Issue
Block a user