Skip to content

Commit d90d895

Browse files
authored
Merge pull request github#12323 from MathiasVP/fix-enclosing-callable
C++: Fix missing enclosing callables
2 parents a5bb093 + 2a9133a commit d90d895

File tree

4 files changed

+9
-21
lines changed

4 files changed

+9
-21
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ class PostFieldUpdateNode extends TPostFieldUpdateNode, PartialDefinitionNode {
461461

462462
PostFieldUpdateNode() { this = TPostFieldUpdateNode(fieldAddress, indirectionIndex) }
463463

464-
override Function getFunction() { result = fieldAddress.getUse().getEnclosingFunction() }
464+
override Declaration getFunction() { result = fieldAddress.getUse().getEnclosingFunction() }
465465

466466
override Declaration getEnclosingCallable() { result = this.getFunction() }
467467

@@ -543,7 +543,7 @@ class SideEffectOperandNode extends Node, IndirectOperand {
543543

544544
override Declaration getEnclosingCallable() { result = this.getFunction() }
545545

546-
override Function getFunction() { result = call.getEnclosingFunction() }
546+
override Declaration getFunction() { result = call.getEnclosingFunction() }
547547

548548
Expr getArgument() { result = call.getArgument(argumentIndex).getUnconvertedResultExpression() }
549549
}
@@ -629,7 +629,7 @@ class IndirectParameterNode extends Node, IndirectInstruction {
629629

630630
override Declaration getEnclosingCallable() { result = this.getFunction() }
631631

632-
override Function getFunction() { result = this.getInstruction().getEnclosingFunction() }
632+
override Declaration getFunction() { result = this.getInstruction().getEnclosingFunction() }
633633

634634
override string toStringImpl() {
635635
result = this.getParameter().toString() + " indirection"
@@ -702,7 +702,7 @@ class IndirectArgumentOutNode extends Node, TIndirectArgumentOutNode, PartialDef
702702

703703
override Declaration getEnclosingCallable() { result = this.getFunction() }
704704

705-
override Function getFunction() { result = this.getCallInstruction().getEnclosingFunction() }
705+
override Declaration getFunction() { result = this.getCallInstruction().getEnclosingFunction() }
706706

707707
override Node getPreUpdateNode() { hasOperandAndIndex(result, operand, indirectionIndex) }
708708

@@ -847,7 +847,7 @@ class RawIndirectOperand extends Node, TRawIndirectOperand {
847847
/** Gets the underlying indirection index. */
848848
int getIndirectionIndex() { result = indirectionIndex }
849849

850-
override Function getFunction() { result = this.getOperand().getDef().getEnclosingFunction() }
850+
override Declaration getFunction() { result = this.getOperand().getDef().getEnclosingFunction() }
851851

852852
override Declaration getEnclosingCallable() { result = this.getFunction() }
853853

@@ -888,7 +888,7 @@ class FinalParameterNode extends Node, TFinalParameterNode {
888888
/** Gets the argument index associated with this final use. */
889889
final int getArgumentIndex() { result = p.getIndex() }
890890

891-
override Function getFunction() { result = p.getFunction() }
891+
override Declaration getFunction() { result = p.getFunction() }
892892

893893
override Declaration getEnclosingCallable() { result = this.getFunction() }
894894

@@ -945,7 +945,7 @@ class RawIndirectInstruction extends Node, TRawIndirectInstruction {
945945
/** Gets the underlying indirection index. */
946946
int getIndirectionIndex() { result = indirectionIndex }
947947

948-
override Function getFunction() { result = this.getInstruction().getEnclosingFunction() }
948+
override Declaration getFunction() { result = this.getInstruction().getEnclosingFunction() }
949949

950950
override Declaration getEnclosingCallable() { result = this.getFunction() }
951951

cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-ir-consistency.expected

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
uniqueEnclosingCallable
2-
| globals.cpp:9:5:9:19 | flowTestGlobal1 indirection | Node should have one enclosing callable but has 0. |
3-
| globals.cpp:9:5:9:19 | flowTestGlobal1 indirection | Node should have one enclosing callable but has 0. |
4-
| globals.cpp:16:12:16:26 | flowTestGlobal2 indirection | Node should have one enclosing callable but has 0. |
5-
| globals.cpp:16:12:16:26 | flowTestGlobal2 indirection | Node should have one enclosing callable but has 0. |
62
uniqueType
73
uniqueNodeLocation
84
missingLocation

cpp/ql/test/library-tests/syntax-zoo/dataflow-ir-consistency.expected

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
uniqueEnclosingCallable
2-
| cpp11.cpp:36:5:36:14 | global_int indirection | Node should have one enclosing callable but has 0. |
3-
| cpp11.cpp:36:5:36:14 | global_int indirection | Node should have one enclosing callable but has 0. |
4-
| misc.c:10:5:10:13 | topLevel1 indirection | Node should have one enclosing callable but has 0. |
5-
| misc.c:10:5:10:13 | topLevel1 indirection | Node should have one enclosing callable but has 0. |
6-
| misc.c:11:5:11:13 | topLevel2 indirection | Node should have one enclosing callable but has 0. |
7-
| misc.c:11:5:11:13 | topLevel2 indirection | Node should have one enclosing callable but has 0. |
8-
| misc.c:210:5:210:20 | global_with_init indirection | Node should have one enclosing callable but has 0. |
9-
| misc.c:210:5:210:20 | global_with_init indirection | Node should have one enclosing callable but has 0. |
102
uniqueType
113
uniqueNodeLocation
124
| allocators.cpp:14:5:14:8 | Phi | Node should have one location but has 4. |

cpp/ql/test/query-tests/Security/CWE/CWE-611/tests3.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void test3_2(InputSource &data) {
3535
SAX2XMLReader *p_3_3 = XMLReaderFactory::createXMLReader();
3636

3737
void test3_3(InputSource &data) {
38-
p_3_3->parse(data); // BAD (parser not correctly configured) [NOT DETECTED]
38+
p_3_3->parse(data); // BAD (parser not correctly configured)
3939
}
4040

4141
SAX2XMLReader *p_3_4 = XMLReaderFactory::createXMLReader();
@@ -53,7 +53,7 @@ void test3_5_init() {
5353

5454
void test3_5(InputSource &data) {
5555
test3_5_init();
56-
p_3_5->parse(data); // GOOD
56+
p_3_5->parse(data); // GOOD [FALSE POSITIVE]
5757
}
5858

5959
void test3_6(InputSource &data) {

0 commit comments

Comments
 (0)