result: make copy of locations

to ensure its not modified by reference after we expect it to be
This commit is contained in:
Willi Ballenthin
2025-01-16 12:49:29 +00:00
committed by Willi Ballenthin
parent 8329abd3c8
commit 4896ff01d8
2 changed files with 9 additions and 5 deletions

View File

@@ -92,7 +92,7 @@ class Result:
self.success = success
self.statement = statement
self.children = children
self.locations = locations if locations is not None else set()
self.locations = frozenset(locations) if locations is not None else frozenset()
def __eq__(self, other):
if isinstance(other, bool):
@@ -194,7 +194,11 @@ class Feature(abc.ABC): # noqa: B024
def evaluate(self, features: "capa.engine.FeatureSet", short_circuit=True) -> Result:
capa.perf.counters["evaluate.feature"] += 1
capa.perf.counters["evaluate.feature." + self.name] += 1
return Result(self in features, self, [], locations=features.get(self, set()))
success = self in features
if success:
return Result(True, self, [], locations=features[self])
else:
return Result(False, self, [], locations=None)
class MatchedRule(Feature):

View File

@@ -853,18 +853,18 @@ class Rule:
def __repr__(self):
return f"Rule(scope={self.scopes}, name={self.name})"
def get_dependencies(self, namespaces):
def get_dependencies(self, namespaces: dict[str, list["Rule"]]) -> set[str]:
"""
fetch the names of rules this rule relies upon.
these are only the direct dependencies; a user must
compute the transitive dependency graph themself, if they want it.
Args:
namespaces(dict[str, list[Rule]]): mapping from namespace name to rules in it.
namespaces: mapping from namespace name to rules in it.
see `index_rules_by_namespace`.
Returns:
list[str]: names of rules upon which this rule depends.
set[str]: names of rules upon which this rule depends.
"""
deps: set[str] = set()