summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2023-08-06 23:18:51 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2023-08-06 23:18:51 (GMT)
commitfa2ac321528fbba5fa9eb15ee6ae87803fb54bb3 (patch)
treebad1ba1bfce03ba0d5f478ea298cb6ae08350681
parent453825b9435ec5740fcada42cebe246325a07c37 (diff)
Reject calls on non callable expressions softly (and fix a little coding mistake).
-rw-r--r--src/analysis/scan/exprs/call.c16
-rw-r--r--tests/analysis/scan/fuzzing.py15
2 files changed, 27 insertions, 4 deletions
diff --git a/src/analysis/scan/exprs/call.c b/src/analysis/scan/exprs/call.c
index 2fd1ff1..83aff85 100644
--- a/src/analysis/scan/exprs/call.c
+++ b/src/analysis/scan/exprs/call.c
@@ -378,18 +378,24 @@ static ScanReductionState g_scan_pending_call_reduce(GScanPendingCall *expr, GSc
*/
if (!G_IS_REGISTERED_ITEM(final))
{
- assert(access->next == NULL);
+ if (access->next != NULL)
+ result = SRS_UNRESOLVABLE;
- *out = G_SCAN_EXPRESSION(final);
+ else
+ {
+ *out = G_SCAN_EXPRESSION(final);
+ g_object_ref(G_OBJECT(final));
+
+ result = SRS_REDUCED;
- result = SRS_REDUCED;
+ }
}
else
{
assert(access->next != NULL);
- new_next = g_scan_named_access_duplicate(access->next, resolved);
+ new_next = g_scan_named_access_duplicate(access->next, G_REGISTERED_ITEM(final));
result = g_scan_expression_reduce(new_next, ctx, scope, out);
@@ -402,6 +408,8 @@ static ScanReductionState g_scan_pending_call_reduce(GScanPendingCall *expr, GSc
else
result = SRS_UNRESOLVABLE;
+ g_clear_object(&final);
+
}
/* Libération locale des arguments reconstruits */
diff --git a/tests/analysis/scan/fuzzing.py b/tests/analysis/scan/fuzzing.py
index 6eecac9..d5fce4b 100644
--- a/tests/analysis/scan/fuzzing.py
+++ b/tests/analysis/scan/fuzzing.py
@@ -78,3 +78,18 @@ rule test {
'''
self.check_rule_failure(rule)
+
+
+ def testCallOnNonCallable(self):
+ """Reject calls on non callable expressions softly."""
+
+ rule = '''
+rule test {
+
+ condition:
+ console.log().log()
+
+}
+'''
+
+ self.check_rule_failure(rule)