Skip to content

Commit 579038f

Browse files
Merge branch 'github:main' into main-1
2 parents d17ae16 + ff36d19 commit 579038f

File tree

118 files changed

+2111
-1510
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+2111
-1510
lines changed

cpp/ql/lib/semmle/code/cpp/Location.qll

+4-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ class Location extends @location {
7575

7676
/** Holds if `this` comes on a line strictly before `l`. */
7777
pragma[inline]
78-
predicate isBefore(Location l) { this.isBefore(l, false) }
78+
predicate isBefore(Location l) {
79+
this.getFile() = l.getFile() and
80+
this.getEndLine() < l.getStartLine()
81+
}
7982

8083
/**
8184
* Holds if `this` comes strictly before `l`. The boolean `sameLine` is

cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll

+5-6
Original file line numberDiff line numberDiff line change
@@ -869,12 +869,11 @@ private predicate elementSpecMatchesSignature(
869869
bindingset[nameWithoutArgs]
870870
pragma[inline_late]
871871
private Class getClassAndNameImpl(Function method, string nameWithoutArgs) {
872-
exists(string memberName | result = method.getClassAndName(memberName) |
873-
nameWithoutArgs = "operator " + method.(ConversionOperator).getDestType()
874-
or
875-
not method instanceof ConversionOperator and
876-
memberName = nameWithoutArgs
877-
)
872+
result = method.getDeclaringType() and
873+
nameWithoutArgs = "operator " + method.(ConversionOperator).getDestType()
874+
or
875+
result = method.getClassAndName(nameWithoutArgs) and
876+
not method instanceof ConversionOperator
878877
}
879878

880879
/**

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll

+17-62
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ module LocalFlow {
664664
ssaDef.getADefinition() = def and
665665
ssaDef.getControlFlowNode() = cfn and
666666
nodeFrom = TAssignableDefinitionNode(def, cfn) and
667-
nodeTo.(SsaDefinitionExtNode).getDefinitionExt() = ssaDef
667+
nodeTo.(SsaDefinitionNode).getDefinition() = ssaDef
668668
)
669669
}
670670

@@ -1269,78 +1269,33 @@ predicate nodeIsHidden(Node n) {
12691269
}
12701270

12711271
/** An SSA node. */
1272-
abstract class SsaNode extends NodeImpl, TSsaNode {
1272+
class SsaNode extends NodeImpl, TSsaNode {
12731273
SsaImpl::DataFlowIntegration::SsaNode node;
1274-
SsaImpl::DefinitionExt def;
12751274

1276-
SsaNode() {
1277-
this = TSsaNode(node) and
1278-
def = node.getDefinitionExt()
1279-
}
1280-
1281-
SsaImpl::DefinitionExt getDefinitionExt() { result = def }
1275+
SsaNode() { this = TSsaNode(node) }
12821276

12831277
override DataFlowCallable getEnclosingCallableImpl() {
1284-
result.getAControlFlowNode().getBasicBlock() = def.getBasicBlock()
1278+
result.getAControlFlowNode().getBasicBlock() = node.getBasicBlock()
12851279
}
12861280

1287-
override Type getTypeImpl() { result = def.getSourceVariable().getType() }
1281+
override Type getTypeImpl() { result = node.getSourceVariable().getType() }
12881282

1289-
override ControlFlow::Node getControlFlowNodeImpl() {
1290-
result = def.(Ssa::Definition).getControlFlowNode()
1291-
}
1283+
override ControlFlow::Node getControlFlowNodeImpl() { none() }
12921284

12931285
override Location getLocationImpl() { result = node.getLocation() }
12941286

12951287
override string toStringImpl() { result = node.toString() }
12961288
}
12971289

1298-
/** An (extended) SSA definition, viewed as a node in a data flow graph. */
1299-
class SsaDefinitionExtNode extends SsaNode {
1300-
override SsaImpl::DataFlowIntegration::SsaDefinitionExtNode node;
1301-
}
1290+
/** An SSA definition, viewed as a node in a data flow graph. */
1291+
class SsaDefinitionNode extends SsaNode {
1292+
override SsaImpl::DataFlowIntegration::SsaDefinitionNode node;
13021293

1303-
/**
1304-
* A node that represents an input to an SSA phi (read) definition.
1305-
*
1306-
* This allows for barrier guards to filter input to phi nodes. For example, in
1307-
*
1308-
* ```csharp
1309-
* var x = taint;
1310-
* if (x != "safe")
1311-
* {
1312-
* x = "safe";
1313-
* }
1314-
* sink(x);
1315-
* ```
1316-
*
1317-
* the `false` edge out of `x != "safe"` guards the input from `x = taint` into the
1318-
* `phi` node after the condition.
1319-
*
1320-
* It is also relevant to filter input into phi read nodes:
1321-
*
1322-
* ```csharp
1323-
* var x = taint;
1324-
* if (b)
1325-
* {
1326-
* if (x != "safe1")
1327-
* {
1328-
* return;
1329-
* }
1330-
* } else {
1331-
* if (x != "safe2")
1332-
* {
1333-
* return;
1334-
* }
1335-
* }
1336-
*
1337-
* sink(x);
1338-
* ```
1339-
*
1340-
* both inputs into the phi read node after the outer condition are guarded.
1341-
*/
1342-
class SsaInputNode extends SsaNode {
1343-
override SsaImpl::DataFlowIntegration::SsaInputNode node;
1294+
Ssa::Definition getDefinition() { result = node.getDefinition() }
1295+
1296+
override ControlFlow::Node getControlFlowNodeImpl() {
1297+
result = this.getDefinition().getControlFlowNode()
1298+
}
13441299
}
13451300

13461301
/** A definition, viewed as a node in a data flow graph. */
@@ -1728,12 +1683,12 @@ private module ReturnNodes {
17281683
* A data-flow node that represents an assignment to an `out` or a `ref`
17291684
* parameter.
17301685
*/
1731-
class OutRefReturnNode extends ReturnNode, SsaDefinitionExtNode {
1686+
class OutRefReturnNode extends ReturnNode, SsaDefinitionNode {
17321687
OutRefReturnKind kind;
17331688

17341689
OutRefReturnNode() {
17351690
exists(Parameter p |
1736-
this.getDefinitionExt().(Ssa::Definition).isLiveOutRefParameterDefinition(p) and
1691+
this.getDefinition().isLiveOutRefParameterDefinition(p) and
17371692
kind.getPosition() = p.getPosition()
17381693
|
17391694
p.isOut() and kind instanceof OutReturnKind
@@ -2464,7 +2419,7 @@ private predicate readContentStep(Node node1, Content c, Node node2) {
24642419
exists(ForeachStmt fs, Ssa::ExplicitDefinition def |
24652420
x.hasDefPath(fs.getIterableExpr(), node1.getControlFlowNode(), def.getADefinition(),
24662421
def.getControlFlowNode()) and
2467-
node2.(SsaDefinitionExtNode).getDefinitionExt() = def and
2422+
node2.(SsaDefinitionNode).getDefinition() = def and
24682423
c instanceof ElementContent
24692424
)
24702425
or

csharp/ql/src/Useless code/DefaultToStringQuery.qll

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ private predicate alwaysInvokesToString(ParameterRead pr) {
4646
* method from `System.Object` or `System.ValueType`.
4747
*/
4848
predicate alwaysDefaultToString(ValueOrRefType t) {
49+
not t instanceof TupleType and
4950
exists(ToStringMethod m | t.hasMethod(m) |
5051
m.getDeclaringType() instanceof SystemObjectClass or
5152
m.getDeclaringType() instanceof SystemValueTypeClass
@@ -55,6 +56,11 @@ predicate alwaysDefaultToString(ValueOrRefType t) {
5556
overriding.getABaseType+() = t
5657
) and
5758
((t.isAbstract() or t instanceof Interface) implies not t.isEffectivelyPublic())
59+
or
60+
exists(ValueOrRefType elem |
61+
elem = t.(TupleType).getElementType(_) and
62+
alwaysDefaultToString(elem)
63+
)
5864
}
5965

6066
class DefaultToStringType extends ValueOrRefType {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* C#: Improve precision of the query `cs/call-to-object-tostring` for value tuples.
+9-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
[]
1+
- queries: .
2+
- include:
3+
id:
4+
- cs/index-out-of-bounds
5+
- cs/test-for-negative-container-size
6+
- cs/unchecked-cast-in-equals
7+
- cs/reference-equality-on-valuetypes
8+
- cs/self-assignment
9+
- cs/inefficient-containskey

0 commit comments

Comments
 (0)