Skip to content

Commit fd4f8c5

Browse files
committed
Merge branch 'main' into unsafe-use-of-this-query
2 parents 2e6a3cd + 14aa642 commit fd4f8c5

File tree

11 files changed

+12600
-12433
lines changed

11 files changed

+12600
-12433
lines changed

cpp/ql/src/semmle/code/cpp/Element.qll

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,10 @@ class ElementBase extends @element {
6565
* which they belong; for example, `AddExpr` is a primary class, but
6666
* `BinaryOperation` is not.
6767
*
68-
* This predicate always has a result. If no primary class can be
69-
* determined, the result is `"???"`. If multiple primary classes match,
70-
* this predicate can have multiple results.
68+
* This predicate can have multiple results if multiple primary classes match.
69+
* For some elements, this predicate may not have a result.
7170
*/
72-
string getAPrimaryQlClass() { result = "???" }
71+
string getAPrimaryQlClass() { none() }
7372
}
7473

7574
/**

cpp/ql/src/semmle/code/cpp/PrintAST.qll

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ private newtype TPrintASTNode =
9191
TDeclarationEntryNode(DeclStmt stmt, DeclarationEntry entry) {
9292
// We create a unique node for each pair of (stmt, entry), to avoid having one node with
9393
// multiple parents due to extractor bug CPP-413.
94-
stmt.getADeclarationEntry() = entry
94+
stmt.getADeclarationEntry() = entry and
95+
shouldPrintFunction(stmt.getEnclosingFunction())
9596
} or
9697
TParametersNode(Function func) { shouldPrintFunction(func) } or
9798
TConstructorInitializersNode(Constructor ctor) {
@@ -234,11 +235,27 @@ class PrintASTNode extends TPrintASTNode {
234235
private Function getEnclosingFunction() { result = getParent*().(FunctionNode).getFunction() }
235236
}
236237

238+
/**
239+
* Class that restricts the elements that we compute `qlClass` for.
240+
*/
241+
private class PrintableElement extends Element {
242+
PrintableElement() {
243+
exists(TASTNode(this))
244+
or
245+
exists(TDeclarationEntryNode(_, this))
246+
or
247+
this instanceof Type
248+
}
249+
250+
pragma[noinline]
251+
string getAPrimaryQlClass0() { result = getAPrimaryQlClass() }
252+
}
253+
237254
/**
238255
* Retrieves the canonical QL class(es) for entity `el`
239256
*/
240-
private string qlClass(ElementBase el) {
241-
result = "[" + concat(el.getAPrimaryQlClass(), ",") + "] "
257+
private string qlClass(PrintableElement el) {
258+
result = "[" + concat(el.getAPrimaryQlClass0(), ",") + "] "
242259
// Alternative implementation -- do not delete. It is useful for QL class discovery.
243260
//result = "["+ concat(el.getAQlClass(), ",") + "] "
244261
}

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasedSSA.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,9 @@ private Overlap getVariableMemoryLocationOverlap(
566566
use.getEndBitOffset())
567567
}
568568

569+
bindingset[result, b]
570+
private boolean unbindBool(boolean b) { result != b.booleanNot() }
571+
569572
MemoryLocation getResultMemoryLocation(Instruction instr) {
570573
exists(MemoryAccessKind kind, boolean isMayAccess |
571574
kind = instr.getResultMemoryAccess() and
@@ -578,15 +581,16 @@ MemoryLocation getResultMemoryLocation(Instruction instr) {
578581
exists(Allocation var, IRType type, IntValue startBitOffset, IntValue endBitOffset |
579582
hasResultMemoryAccess(instr, var, type, _, startBitOffset, endBitOffset, isMayAccess) and
580583
result =
581-
TVariableMemoryLocation(var, type, _, startBitOffset, endBitOffset, isMayAccess)
584+
TVariableMemoryLocation(var, type, _, startBitOffset, endBitOffset,
585+
unbindBool(isMayAccess))
582586
)
583587
else result = TUnknownMemoryLocation(instr.getEnclosingIRFunction(), isMayAccess)
584588
)
585589
or
586590
kind instanceof EntireAllocationMemoryAccess and
587591
result =
588592
TEntireAllocationMemoryLocation(getAddressOperandAllocation(instr.getResultAddressOperand()),
589-
isMayAccess)
593+
unbindBool(isMayAccess))
590594
or
591595
kind instanceof EscapedMemoryAccess and
592596
result = TAllAliasedMemory(instr.getEnclosingIRFunction(), isMayAccess, false)

csharp/ql/src/semmle/code/cil/DataFlow.qll

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,16 @@ module DefUse {
165165
(
166166
exists(int last | last = max(refRank(bb, _, v, _)) | defReachesRank(bb, vu, last, v))
167167
or
168-
exists(BasicBlock pred |
169-
pred = bb.getAPredecessor() and
170-
defReachesEndOfBlock(pred, vu, v) and
171-
not exists(refRank(bb, _, v, Write()))
172-
)
168+
defReachesStartOfBlock(bb, vu, v) and
169+
not exists(refRank(bb, _, v, Write()))
173170
)
174171
}
175172

173+
pragma[noinline]
174+
private predicate defReachesStartOfBlock(BasicBlock bb, VariableUpdate vu, StackVariable v) {
175+
defReachesEndOfBlock(bb.getAPredecessor(), vu, v)
176+
}
177+
176178
/**
177179
* Holds if the variable update `vu` of stack variable `v` reaches `read` in the
178180
* same basic block without crossing another update of `v`.

csharp/ql/src/semmle/code/csharp/dataflow/SSA.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ module Ssa {
11301130
exists(Expr mid | reachesDelegateCall(mid) | delegateFlowStep(e, mid))
11311131
}
11321132

1133-
pragma[noinline]
1133+
pragma[nomagic]
11341134
private predicate delegateFlowStepReaches(Expr pred, Expr succ) {
11351135
delegateFlowStep(pred, succ) and
11361136
reachesDelegateCall(succ)

0 commit comments

Comments
 (0)