]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
machined: validate machine names at more places
authorLennart Poettering <lennart@poettering.net>
Sun, 23 Aug 2015 12:33:50 +0000 (14:33 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 24 Aug 2015 20:46:45 +0000 (22:46 +0200)
When enumerating machines from /run, and when accepting machine names
for operations, be more strict and always validate.

Note that these checks are strictly speaking unnecessary, since
enumeration happens only on the trusted /run...

src/basic/util.c
src/libsystemd/sd-login/sd-login.c
src/machine/machined.c

index deff68073c14301371dd287748ffda7311589c98..f752595ca1187423caf3e1402a1fbc85d6e1c567 100644 (file)
@@ -4913,6 +4913,9 @@ int container_get_leader(const char *machine, pid_t *pid) {
         assert(machine);
         assert(pid);
 
+        if (!machine_name_is_valid(machine))
+                return -EINVAL;
+
         p = strjoina("/run/systemd/machines/", machine);
         r = parse_env_file(p, NEWLINE, "LEADER", &s, "CLASS", &class, NULL);
         if (r == -ENOENT)
index 5f290573cb3930dc387e67918b951e68e1b63466..0eadc8c747ab6a0031c10f2250cc85d6ff44c12b 100644 (file)
@@ -791,7 +791,7 @@ _public_ int sd_get_machine_names(char ***machines) {
 
                 /* Filter out the unit: symlinks */
                 for (a = l, b = l; *a; a++) {
-                        if (startswith(*a, "unit:"))
+                        if (startswith(*a, "unit:") || !machine_name_is_valid(*a))
                                 free(*a);
                         else {
                                 *b = *a;
index 109bab76c5159669400e95b8ad87704b7a90123a..9b9a33483874435d8ffcf729992aac716accae6b 100644 (file)
@@ -118,6 +118,9 @@ int manager_enumerate_machines(Manager *m) {
                 if (startswith(de->d_name, "unit:"))
                         continue;
 
+                if (!machine_name_is_valid(de->d_name))
+                        continue;
+
                 k = manager_add_machine(m, de->d_name, &machine);
                 if (k < 0) {
                         log_error_errno(k, "Failed to add machine by file name %s: %m", de->d_name);