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 ```
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "alloc-util.h"
|
||||
#include "glob-util.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "memory-util.h"
|
||||
#include "path-util.h"
|
||||
#include "special.h"
|
||||
#include "string-util.h"
|
||||
@@ -797,3 +798,26 @@ bool slice_name_is_valid(const char *name) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool unit_name_prefix_equal(const char *a, const char *b) {
|
||||
const char *p, *q;
|
||||
|
||||
assert(a);
|
||||
assert(b);
|
||||
|
||||
if (!unit_name_is_valid(a, UNIT_NAME_ANY) || !unit_name_is_valid(b, UNIT_NAME_ANY))
|
||||
return false;
|
||||
|
||||
p = strchr(a, '@');
|
||||
if (!p)
|
||||
p = strrchr(a, '.');
|
||||
|
||||
q = strchr(b, '@');
|
||||
if (!q)
|
||||
q = strrchr(b, '.');
|
||||
|
||||
assert(p);
|
||||
assert(q);
|
||||
|
||||
return memcmp_nn(a, p - a, b, q - b) == 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user