hostname-util: do not allow empty machine spec

Follow-up for 2ae32e9d8f

Let's not open this up even further and rather disallow
--machine="".
This commit is contained in:
Mike Yuan
2025-06-17 01:39:56 +02:00
parent 75e638671c
commit d2e727bf68
2 changed files with 14 additions and 5 deletions
+12 -4
View File
@@ -179,6 +179,8 @@ int split_user_at_host(const char *s, char **ret_user, char **ret_host) {
/* Splits a user@host expression (one of those we accept on --machine= and similar). Returns NULL in
* each of the two return parameters if that part was left empty. */
assert(s);
const char *rhs = strchr(s, '@');
if (rhs) {
if (ret_user && rhs > s) {
@@ -192,10 +194,16 @@ int split_user_at_host(const char *s, char **ret_user, char **ret_host) {
if (!h)
return -ENOMEM;
}
} else if (!isempty(s) && ret_host) {
h = strdup(s);
if (!h)
return -ENOMEM;
} else {
if (isempty(s))
return -EINVAL;
if (ret_host) {
h = strdup(s);
if (!h)
return -ENOMEM;
}
}
if (ret_user)