Skip to content

Commit 0eb0bf9

Browse files
committed
CPP: Fix for virtual method calls.
1 parent 7107cec commit 0eb0bf9

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

cpp/ql/src/jsf/4.10 Classes/AV Rule 79.ql

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,19 @@ private predicate exprReleases(Expr e, Expr released, string kind) {
9696
) or exists(Function f, int arg |
9797
// `e` is a call to a function that releases one of it's parameters,
9898
// and `released` is the corresponding argument
99-
e.(FunctionCall).getTarget() = f and
99+
(
100+
e.(FunctionCall).getTarget() = f or
101+
e.(FunctionCall).getTarget().(MemberFunction).getAnOverridingFunction*() = f
102+
) and
100103
e.(FunctionCall).getArgument(arg) = released and
101104
exprReleases(_, exprOrDereference(f.getParameter(arg).getAnAccess()), kind)
102105
) or exists(Function f, ThisExpr innerThis |
103106
// `e` is a call to a method that releases `this`, and `released`
104107
// is the object that is called
105-
e.(FunctionCall).getTarget() = f and
108+
(
109+
e.(FunctionCall).getTarget() = f or
110+
e.(FunctionCall).getTarget().(MemberFunction).getAnOverridingFunction*() = f
111+
) and
106112
e.(FunctionCall).getQualifier() = exprOrDereference(released) and
107113
innerThis.getEnclosingFunction() = f and
108114
exprReleases(_, innerThis, kind)

cpp/ql/test/query-tests/jsf/4.10 Classes/AV Rule 79/AV Rule 79.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
| DeleteThis.cpp:56:3:56:24 | ... = ... | Resource ptr10 is acquired by class MyClass3 but not released anywhere in this class. |
99
| DeleteThis.cpp:58:3:58:24 | ... = ... | Resource ptr12 is acquired by class MyClass3 but not released anywhere in this class. |
1010
| DeleteThis.cpp:60:3:60:24 | ... = ... | Resource ptr14 is acquired by class MyClass3 but not released anywhere in this class. |
11-
| DeleteThis.cpp:111:3:111:20 | ... = ... | Resource b is acquired by class MyClass7 but not released anywhere in this class. |
12-
| DeleteThis.cpp:112:3:112:20 | ... = ... | Resource c is acquired by class MyClass7 but not released anywhere in this class. |
1311
| ExternalOwners.cpp:49:3:49:20 | ... = ... | Resource a is acquired by class MyScreen but not released anywhere in this class. |
1412
| ListDelete.cpp:21:3:21:21 | ... = ... | Resource first is acquired by class MyThingColection but not released anywhere in this class. |
1513
| NoDestructor.cpp:23:3:23:20 | ... = ... | Resource n is acquired by class MyClass5 but not released anywhere in this class. |

cpp/ql/test/query-tests/jsf/4.10 Classes/AV Rule 79/DeleteThis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ class MyClass7
108108
MyClass7()
109109
{
110110
a = new MyClass5(); // GOOD
111-
b = new MyClass5(); // GOOD [FALSE POSITIVE]
112-
c = new MyClass6(); // GOOD [FALSE POSITIVE]
111+
b = new MyClass5(); // GOOD
112+
c = new MyClass6(); // GOOD
113113
}
114114

115115
~MyClass7()

0 commit comments

Comments
 (0)