summaryrefslogtreecommitdiff
path: root/src/test/test-unit-name.c
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2021-09-01 11:21:28 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2021-10-28 11:42:21 +0100
commit88022148c4769f7d39a9ef3cc41cef3f3479eaad (patch)
treebf75b3380bb7710d61f0f17476b757b937ecb037 /src/test/test-unit-name.c
parent11e9347bc63364ba6c8934c20e288e5664254024 (diff)
downloadsystemd-88022148c4769f7d39a9ef3cc41cef3f3479eaad.tar.gz
core: Try to prevent infinite recursive template instantiation
To prevent situations like in #17602 from happening, let's drop direct recursive template dependencies. These will almost certainly lead to infinite recursion so let's drop them immediately to avoid instantiating potentially thousands of irrelevant units. Example of a template that would lead to infinite recursion which is caught by this check: notify@.service: ``` [Unit] Wants=notify@%n.service ```
Diffstat (limited to 'src/test/test-unit-name.c')
-rw-r--r--src/test/test-unit-name.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c
index 0077c4c5e3..665e7b7933 100644
--- a/src/test/test-unit-name.c
+++ b/src/test/test-unit-name.c
@@ -870,6 +870,22 @@ static void test_unit_name_from_dbus_path(void) {
test_unit_name_from_dbus_path_one("/org/freedesktop/systemd1/unit/wpa_5fsupplicant_2eservice", 0, "wpa_supplicant.service");
}
+static void test_unit_name_prefix_equal(void) {
+ log_info("/* %s */", __func__);
+
+ assert_se(unit_name_prefix_equal("a.service", "a.service"));
+ assert_se(unit_name_prefix_equal("a.service", "a.mount"));
+ assert_se(unit_name_prefix_equal("a@b.service", "a.service"));
+ assert_se(unit_name_prefix_equal("a@b.service", "a@c.service"));
+
+ assert_se(!unit_name_prefix_equal("a.service", "b.service"));
+ assert_se(!unit_name_prefix_equal("a.service", "b.mount"));
+ assert_se(!unit_name_prefix_equal("a@a.service", "b.service"));
+ assert_se(!unit_name_prefix_equal("a@a.service", "b@a.service"));
+ assert_se(!unit_name_prefix_equal("a", "b"));
+ assert_se(!unit_name_prefix_equal("a", "a"));
+}
+
int main(int argc, char* argv[]) {
_cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
int r, rc = 0;
@@ -902,6 +918,7 @@ int main(int argc, char* argv[]) {
test_unit_name_path_unescape();
test_unit_name_to_prefix();
test_unit_name_from_dbus_path();
+ test_unit_name_prefix_equal();
return rc;
}