hostname-util: don't allow machine tags to begin/end with '-' or '.'

This commit is contained in:
Lennart Poettering
2026-06-01 12:16:28 +01:00
committed by Luca Boccassi
parent 7602d82407
commit 95c7dc3308
2 changed files with 10 additions and 0 deletions
+6
View File
@@ -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 "-.");
}