hostname-util: don't allow machine tags to begin/end with '-' or '.'
This commit is contained in:
committed by
Luca Boccassi
parent
7602d82407
commit
95c7dc3308
@@ -259,6 +259,12 @@ bool machine_tag_is_valid(const char *s) {
|
||||
if (n <= 0 || n >= 256)
|
||||
return false;
|
||||
|
||||
/* Don't allow "-" and "." as first or last char. (This is load-bearing, we want that "+"/"-" can be
|
||||
* used as prefix for adding/removing tags from the list). */
|
||||
if (strchr("-.", s[0]) ||
|
||||
strchr("-.", s[n-1]))
|
||||
return false;
|
||||
|
||||
return in_charset(s, ALPHANUMERICAL "-.");
|
||||
}
|
||||
|
||||
|
||||
@@ -132,6 +132,10 @@ TEST(machine_tag_is_valid) {
|
||||
assert_se(!machine_tag_is_valid("fööbar")); /* non-ASCII */
|
||||
assert_se(!machine_tag_is_valid("foo/bar"));
|
||||
assert_se(!machine_tag_is_valid("foo_bar"));
|
||||
assert_se(!machine_tag_is_valid("-foo"));
|
||||
assert_se(!machine_tag_is_valid("foo-"));
|
||||
assert_se(!machine_tag_is_valid(".foo"));
|
||||
assert_se(!machine_tag_is_valid("foo."));
|
||||
|
||||
/* Length boundary: 255 characters is fine, 256 is too long */
|
||||
_cleanup_free_ char *max = strrep("a", 255), *over = strrep("a", 256);
|
||||
|
||||
Reference in New Issue
Block a user