Skip to content

Commit 9e300a9

Browse files
authored
Merge branch 'main' into redsun82/fix-cmake-bazel-version
2 parents 819fc52 + 25a1b05 commit 9e300a9

File tree

7 files changed

+95
-232
lines changed

7 files changed

+95
-232
lines changed

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ private import semmle.code.cpp.ir.internal.IRCppLanguage
66
private import SsaInternals as Ssa
77
private import DataFlowImplCommon as DataFlowImplCommon
88
private import codeql.util.Unit
9+
private import Node0ToString
910

1011
cached
1112
private module Cached {
@@ -138,11 +139,7 @@ abstract class InstructionNode0 extends Node0Impl {
138139

139140
override DataFlowType getType() { result = getInstructionType(instr, _) }
140141

141-
override string toStringImpl() {
142-
if instr.(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable
143-
then result = "this"
144-
else result = instr.getAst().toString()
145-
}
142+
override string toStringImpl() { result = instructionToString(instr) }
146143

147144
override Location getLocationImpl() {
148145
if exists(instr.getAst().getLocation())
@@ -187,11 +184,7 @@ abstract class OperandNode0 extends Node0Impl {
187184

188185
override DataFlowType getType() { result = getOperandType(op, _) }
189186

190-
override string toStringImpl() {
191-
if op.getDef().(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable
192-
then result = "this"
193-
else result = op.getDef().getAst().toString()
194-
}
187+
override string toStringImpl() { result = operandToString(op) }
195188

196189
override Location getLocationImpl() {
197190
if exists(op.getDef().getAst().getLocation())

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ private import ModelUtil
1515
private import SsaInternals as Ssa
1616
private import DataFlowImplCommon as DataFlowImplCommon
1717
private import codeql.util.Unit
18+
private import Node0ToString
1819

1920
/**
2021
* The IR dataflow graph consists of the following nodes:
@@ -486,10 +487,13 @@ class Node extends TIRDataFlowNode {
486487
}
487488

488489
private string toExprString(Node n) {
489-
result = n.asExpr(0).toString()
490-
or
491-
not exists(n.asExpr()) and
492-
result = n.asIndirectExpr(0, 1).toString() + " indirection"
490+
not isDebugMode() and
491+
(
492+
result = n.asExpr(0).toString()
493+
or
494+
not exists(n.asExpr()) and
495+
result = n.asIndirectExpr(0, 1).toString() + " indirection"
496+
)
493497
}
494498

495499
/**
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* This file activates debugging mode for dataflow node printing.
3+
*/
4+
5+
private import Node0ToString
6+
7+
private class DebugNode0ToString extends Node0ToString {
8+
final override predicate isDebugMode() { any() }
9+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* This file contains the abstract class that serves as the base class for
3+
* dataflow node printing.
4+
*
5+
* By default, a non-debug string is produced. However, a debug-friendly
6+
* string can be produced by importing `DebugPrinting.qll`.
7+
*/
8+
9+
private import semmle.code.cpp.ir.IR
10+
private import codeql.util.Unit
11+
12+
/**
13+
* A class to control whether a debugging version of instructions and operands
14+
* should be printed as part of the `toString` output of dataflow nodes.
15+
*
16+
* To enable debug printing import the `DebugPrinting.ql` file. By default,
17+
* non-debug output will be used.
18+
*/
19+
class Node0ToString extends Unit {
20+
abstract predicate isDebugMode();
21+
22+
private string normalInstructionToString(Instruction i) {
23+
not this.isDebugMode() and
24+
if i.(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable
25+
then result = "this"
26+
else result = i.getAst().toString()
27+
}
28+
29+
private string normalOperandToString(Operand op) {
30+
not this.isDebugMode() and
31+
if op.getDef().(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable
32+
then result = "this"
33+
else result = op.getDef().getAst().toString()
34+
}
35+
36+
/**
37+
* Gets the string that should be used by `InstructionNode.toString`
38+
*/
39+
string instructionToString(Instruction i) {
40+
if this.isDebugMode()
41+
then result = i.getDumpString()
42+
else result = this.normalInstructionToString(i)
43+
}
44+
45+
/**
46+
* Gets the string that should be used by `OperandNode.toString`.
47+
*/
48+
string operandToString(Operand op) {
49+
if this.isDebugMode()
50+
then result = op.getDumpString() + " @ " + op.getUse().getResultId()
51+
else result = this.normalOperandToString(op)
52+
}
53+
}
54+
55+
private class NoDebugNode0ToString extends Node0ToString {
56+
final override predicate isDebugMode() { none() }
57+
}
58+
59+
/**
60+
* Gets the string that should be used by `OperandNode.toString`.
61+
*/
62+
string operandToString(Operand op) { result = any(Node0ToString nts).operandToString(op) }
63+
64+
/**
65+
* Gets the string that should be used by `InstructionNode.toString`
66+
*/
67+
string instructionToString(Instruction i) { result = any(Node0ToString nts).instructionToString(i) }
68+
69+
/**
70+
* Holds if debugging mode is enabled.
71+
*
72+
* In debug mode the `toString` on dataflow nodes is more expensive to compute,
73+
* but gives more precise information about the different dataflow nodes.
74+
*/
75+
predicate isDebugMode() { any(Node0ToString nts).isDebugMode() }

swift/ql/test/query-tests/Security/CWE-327/BrokenCryptoAlgorithm.expected

Whitespace-only changes.

swift/ql/test/query-tests/Security/CWE-327/BrokenCryptoAlgorithm.qlref.disabled

Lines changed: 0 additions & 1 deletion
This file was deleted.

swift/ql/test/query-tests/Security/CWE-327/test_commoncrypto.swift

Lines changed: 0 additions & 217 deletions
This file was deleted.

0 commit comments

Comments
 (0)