]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: fix assert when AddDependencyUnitFiles is called with invalid parameter
authorLuca Boccassi <luca.boccassi@gmail.com>
Mon, 6 Jan 2025 18:16:29 +0000 (18:16 +0000)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 6 Jan 2025 21:38:55 +0000 (21:38 +0000)
unit_file_add_dependency() asserts, so check before calling it that the
type is expected, or return EINVAL to the caller.

root@localhost:~# busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager AddDependencyUnitFiles "asssbb" 0 uwhatm8 After 1 1

Broadcast message from systemd-journald@localhost (Mon 2025-01-06 18:12:14 UTC):

systemd[1]: Caught <ABRT>, from our own process.

Fixes https://github.com/systemd/systemd/issues/35882

src/core/dbus-manager.c

index 47d919a014dd88ba3af154d2ee50a29456f746e0..ed1f1241826a4f344460db5f8e40c857791acad2 100644 (file)
@@ -2674,7 +2674,7 @@ static int method_add_dependency_unit_files(sd_bus_message *message, void *userd
         flags = unit_file_bools_to_flags(runtime, force);
 
         dep = unit_dependency_from_string(type);
-        if (dep < 0)
+        if (dep < 0 || !IN_SET(dep, UNIT_WANTS, UNIT_REQUIRES))
                 return -EINVAL;
 
         r = unit_file_add_dependency(m->runtime_scope, flags, NULL, l, target, dep, &changes, &n_changes);