Skip to content

Commit 1213eba

Browse files
authored
Merge branch 'main' into post-release-prep/codeql-cli-2.14.2
2 parents 432c21d + 5161cd1 commit 1213eba

File tree

264 files changed

+8330
-5795
lines changed

Some content is hidden

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

264 files changed

+8330
-5795
lines changed

config/identical-files.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowImpl5.qll",
2323
"go/ql/lib/semmle/go/dataflow/internal/DataFlowImpl1.qll",
2424
"go/ql/lib/semmle/go/dataflow/internal/DataFlowImpl2.qll",
25-
"go/ql/lib/semmle/go/dataflow/internal/DataFlowImplForStringsNewReplacer.qll",
2625
"python/ql/lib/semmle/python/dataflow/new/internal/DataFlowImpl1.qll",
2726
"python/ql/lib/semmle/python/dataflow/new/internal/DataFlowImpl2.qll",
2827
"python/ql/lib/semmle/python/dataflow/new/internal/DataFlowImpl3.qll",
@@ -572,4 +571,4 @@
572571
"python/ql/lib/semmle/python/security/internal/EncryptionKeySizes.qll",
573572
"java/ql/lib/semmle/code/java/security/internal/EncryptionKeySizes.qll"
574573
]
575-
}
574+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ private IRVariable getIRVariableForParameterNode(ParameterNode p) {
10781078

10791079
/** Holds if `v` is the source variable corresponding to the parameter represented by `p`. */
10801080
pragma[nomagic]
1081-
private predicate parameterNodeHasSourceVariable(ParameterNode p, Ssa::SourceIRVariable v) {
1081+
private predicate parameterNodeHasSourceVariable(ParameterNode p, Ssa::SourceVariable v) {
10821082
v.getIRVariable() = getIRVariableForParameterNode(p) and
10831083
exists(Position pos | p.isParameterOf(_, pos) |
10841084
pos instanceof DirectPosition and

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -781,26 +781,12 @@ class IndirectArgumentOutNode extends Node, TIndirectArgumentOutNode, PartialDef
781781
override Expr getDefinedExpr() { result = operand.getDef().getUnconvertedResultExpression() }
782782
}
783783

784-
pragma[nomagic]
785-
predicate indirectReturnOutNodeOperand0(CallInstruction call, Operand operand, int indirectionIndex) {
786-
Ssa::hasRawIndirectInstruction(call, indirectionIndex) and
787-
operandForFullyConvertedCall(operand, call)
788-
}
789-
790-
pragma[nomagic]
791-
predicate indirectReturnOutNodeInstruction0(
792-
CallInstruction call, Instruction instr, int indirectionIndex
793-
) {
794-
Ssa::hasRawIndirectInstruction(call, indirectionIndex) and
795-
instructionForFullyConvertedCall(instr, call)
796-
}
797-
798784
/**
799785
* Holds if `node` is an indirect operand with columns `(operand, indirectionIndex)`, and
800786
* `operand` represents a use of the fully converted value of `call`.
801787
*/
802788
private predicate hasOperand(Node node, CallInstruction call, int indirectionIndex, Operand operand) {
803-
indirectReturnOutNodeOperand0(call, operand, indirectionIndex) and
789+
operandForFullyConvertedCall(operand, call) and
804790
hasOperandAndIndex(node, operand, indirectionIndex)
805791
}
806792

@@ -813,7 +799,7 @@ private predicate hasOperand(Node node, CallInstruction call, int indirectionInd
813799
private predicate hasInstruction(
814800
Node node, CallInstruction call, int indirectionIndex, Instruction instr
815801
) {
816-
indirectReturnOutNodeInstruction0(call, instr, indirectionIndex) and
802+
instructionForFullyConvertedCall(instr, call) and
817803
hasInstructionAndIndex(node, instr, indirectionIndex)
818804
}
819805

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

Lines changed: 62 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -10,99 +10,56 @@ private import ssa0.SsaInternals as SsaInternals0
1010
import SsaInternalsCommon
1111

1212
private module SourceVariables {
13-
int getMaxIndirectionForIRVariable(IRVariable var) {
14-
exists(Type type, boolean isGLValue |
15-
var.getLanguageType().hasType(type, isGLValue) and
16-
if isGLValue = true
17-
then result = 1 + getMaxIndirectionsForType(type)
18-
else result = getMaxIndirectionsForType(type)
19-
)
20-
}
21-
2213
cached
2314
private newtype TSourceVariable =
24-
TSourceIRVariable(BaseIRVariable baseVar, int ind) {
25-
ind = [0 .. getMaxIndirectionForIRVariable(baseVar.getIRVariable())]
26-
} or
27-
TCallVariable(AllocationInstruction call, int ind) {
28-
ind = [0 .. countIndirectionsForCppType(getResultLanguageType(call))]
15+
TMkSourceVariable(SsaInternals0::SourceVariable base, int ind) {
16+
ind = [0 .. countIndirectionsForCppType(base.getLanguageType()) + 1]
2917
}
3018

31-
abstract class SourceVariable extends TSourceVariable {
19+
class SourceVariable extends TSourceVariable {
20+
SsaInternals0::SourceVariable base;
3221
int ind;
3322

34-
bindingset[ind]
35-
SourceVariable() { any() }
23+
SourceVariable() { this = TMkSourceVariable(base, ind) }
24+
25+
/** Gets the IR variable associated with this `SourceVariable`, if any. */
26+
IRVariable getIRVariable() { result = base.(BaseIRVariable).getIRVariable() }
27+
28+
/**
29+
* Gets the base source variable (i.e., the variable without any
30+
* indirections) of this source variable.
31+
*/
32+
SsaInternals0::SourceVariable getBaseVariable() { result = base }
3633

3734
/** Gets a textual representation of this element. */
38-
abstract string toString();
35+
string toString() {
36+
ind = 0 and
37+
result = this.getBaseVariable().toString()
38+
or
39+
ind > 0 and
40+
result = this.getBaseVariable().toString() + " indirection"
41+
}
3942

4043
/**
4144
* Gets the number of loads performed on the base source variable
4245
* to reach the value of this source variable.
4346
*/
4447
int getIndirection() { result = ind }
4548

46-
/**
47-
* Gets the base source variable (i.e., the variable without any
48-
* indirections) of this source variable.
49-
*/
50-
abstract BaseSourceVariable getBaseVariable();
51-
5249
/** Holds if this variable is a glvalue. */
53-
predicate isGLValue() { none() }
50+
predicate isGLValue() { ind = 0 }
5451

5552
/**
5653
* Gets the type of this source variable. If `isGLValue()` holds, then
5754
* the type of this source variable should be thought of as "pointer
5855
* to `getType()`".
5956
*/
60-
abstract DataFlowType getType();
61-
}
62-
63-
class SourceIRVariable extends SourceVariable, TSourceIRVariable {
64-
BaseIRVariable var;
65-
66-
SourceIRVariable() { this = TSourceIRVariable(var, ind) }
67-
68-
IRVariable getIRVariable() { result = var.getIRVariable() }
69-
70-
override BaseIRVariable getBaseVariable() { result.getIRVariable() = this.getIRVariable() }
71-
72-
override string toString() {
73-
ind = 0 and
74-
result = this.getIRVariable().toString()
75-
or
76-
ind > 0 and
77-
result = this.getIRVariable().toString() + " indirection"
78-
}
79-
80-
override predicate isGLValue() { ind = 0 }
81-
82-
override DataFlowType getType() {
83-
if ind = 0 then result = var.getType() else result = getTypeImpl(var.getType(), ind - 1)
57+
DataFlowType getType() {
58+
if this.isGLValue()
59+
then result = base.getType()
60+
else result = getTypeImpl(base.getType(), ind - 1)
8461
}
8562
}
86-
87-
class CallVariable extends SourceVariable, TCallVariable {
88-
AllocationInstruction call;
89-
90-
CallVariable() { this = TCallVariable(call, ind) }
91-
92-
AllocationInstruction getCall() { result = call }
93-
94-
override BaseCallVariable getBaseVariable() { result.getCallInstruction() = call }
95-
96-
override string toString() {
97-
ind = 0 and
98-
result = "Call"
99-
or
100-
ind > 0 and
101-
result = "Call indirection"
102-
}
103-
104-
override DataFlowType getType() { result = getTypeImpl(call.getResultType(), ind) }
105-
}
10663
}
10764

10865
import SourceVariables
@@ -137,8 +94,9 @@ predicate hasRawIndirectInstruction(Instruction instr, int indirectionIndex) {
13794

13895
cached
13996
private newtype TDefOrUseImpl =
140-
TDefImpl(Operand address, int indirectionIndex) {
141-
exists(Instruction base | isDef(_, _, address, base, _, indirectionIndex) |
97+
TDefImpl(BaseSourceVariableInstruction base, Operand address, int indirectionIndex) {
98+
isDef(_, _, address, base, _, indirectionIndex) and
99+
(
142100
// We only include the definition if the SSA pruning stage
143101
// concluded that the definition is live after the write.
144102
any(SsaInternals0::Def def).getAddressOperand() = address
@@ -148,8 +106,8 @@ private newtype TDefOrUseImpl =
148106
base.(VariableAddressInstruction).getAstVariable() instanceof GlobalLikeVariable
149107
)
150108
} or
151-
TUseImpl(Operand operand, int indirectionIndex) {
152-
isUse(_, operand, _, _, indirectionIndex) and
109+
TUseImpl(BaseSourceVariableInstruction base, Operand operand, int indirectionIndex) {
110+
isUse(_, operand, base, _, indirectionIndex) and
153111
not isDef(_, _, operand, _, _, _)
154112
} or
155113
TGlobalUse(GlobalLikeVariable v, IRFunction f, int indirectionIndex) {
@@ -236,7 +194,7 @@ abstract private class DefOrUseImpl extends TDefOrUseImpl {
236194

237195
/**
238196
* Gets the instruction that computes the base of this definition or use.
239-
* This is always a `VariableAddressInstruction` or an `AllocationInstruction`.
197+
* This is always a `VariableAddressInstruction` or an `CallInstruction`.
240198
*/
241199
abstract BaseSourceVariableInstruction getBase();
242200

@@ -308,15 +266,17 @@ abstract class DefImpl extends DefOrUseImpl {
308266
}
309267

310268
private class DirectDef extends DefImpl, TDefImpl {
311-
DirectDef() { this = TDefImpl(address, ind) }
269+
BaseSourceVariableInstruction base;
270+
271+
DirectDef() { this = TDefImpl(base, address, ind) }
312272

313-
override BaseSourceVariableInstruction getBase() { isDef(_, _, address, result, _, _) }
273+
override BaseSourceVariableInstruction getBase() { result = base }
314274

315-
override int getIndirection() { isDef(_, _, address, _, result, ind) }
275+
override int getIndirection() { isDef(_, _, address, base, result, ind) }
316276

317-
override Node0Impl getValue() { isDef(_, result, address, _, _, _) }
277+
override Node0Impl getValue() { isDef(_, result, address, base, _, _) }
318278

319-
override predicate isCertain() { isDef(true, _, address, _, _, ind) }
279+
override predicate isCertain() { isDef(true, _, address, base, _, ind) }
320280
}
321281

322282
private class IteratorDef extends DefImpl, TIteratorDef {
@@ -359,57 +319,52 @@ abstract class UseImpl extends DefOrUseImpl {
359319

360320
abstract private class OperandBasedUse extends UseImpl {
361321
Operand operand;
322+
BaseSourceVariableInstruction base;
362323

363324
bindingset[ind]
364325
OperandBasedUse() { any() }
365326

366327
final override predicate hasIndexInBlock(IRBlock block, int index) {
367328
// See the comment in `ssa0`'s `OperandBasedUse` for an explanation of this
368329
// predicate's implementation.
369-
exists(BaseSourceVariableInstruction base | base = this.getBase() |
370-
if base.getAst() = any(Cpp::PostfixCrementOperation c).getOperand()
371-
then
372-
exists(Operand op, int indirectionIndex, int indirection |
373-
indirectionIndex = this.getIndirectionIndex() and
374-
indirection = this.getIndirection() and
375-
op =
376-
min(Operand cand, int i |
377-
isUse(_, cand, base, indirection, indirectionIndex) and
378-
block.getInstruction(i) = cand.getUse()
379-
|
380-
cand order by i
381-
) and
382-
block.getInstruction(index) = op.getUse()
383-
)
384-
else operand.getUse() = block.getInstruction(index)
385-
)
330+
if base.getAst() = any(Cpp::PostfixCrementOperation c).getOperand()
331+
then
332+
exists(Operand op, int indirectionIndex, int indirection |
333+
indirectionIndex = this.getIndirectionIndex() and
334+
indirection = this.getIndirection() and
335+
op =
336+
min(Operand cand, int i |
337+
isUse(_, cand, base, indirection, indirectionIndex) and
338+
block.getInstruction(i) = cand.getUse()
339+
|
340+
cand order by i
341+
) and
342+
block.getInstruction(index) = op.getUse()
343+
)
344+
else operand.getUse() = block.getInstruction(index)
386345
}
387346

347+
final override BaseSourceVariableInstruction getBase() { result = base }
348+
388349
final Operand getOperand() { result = operand }
389350

390351
final override Cpp::Location getLocation() { result = operand.getLocation() }
391352
}
392353

393354
private class DirectUse extends OperandBasedUse, TUseImpl {
394-
DirectUse() { this = TUseImpl(operand, ind) }
395-
396-
override int getIndirection() { isUse(_, operand, _, result, ind) }
355+
DirectUse() { this = TUseImpl(base, operand, ind) }
397356

398-
override BaseSourceVariableInstruction getBase() { isUse(_, operand, result, _, ind) }
357+
override int getIndirection() { isUse(_, operand, base, result, ind) }
399358

400-
override predicate isCertain() { isUse(true, operand, _, _, ind) }
359+
override predicate isCertain() { isUse(true, operand, base, _, ind) }
401360

402361
override Node getNode() { nodeHasOperand(result, operand, ind) }
403362
}
404363

405364
private class IteratorUse extends OperandBasedUse, TIteratorUse {
406-
BaseSourceVariableInstruction container;
365+
IteratorUse() { this = TIteratorUse(operand, base, ind) }
407366

408-
IteratorUse() { this = TIteratorUse(operand, container, ind) }
409-
410-
override int getIndirection() { isIteratorUse(container, operand, result, ind) }
411-
412-
override BaseSourceVariableInstruction getBase() { result = container }
367+
override int getIndirection() { isIteratorUse(base, operand, result, ind) }
413368

414369
override predicate isCertain() { none() }
415370

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

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,6 @@ int countIndirectionsForCppType(LanguageType langType) {
146146
)
147147
}
148148

149-
/**
150-
* A `CallInstruction` that calls an allocation function such
151-
* as `malloc` or `operator new`.
152-
*/
153-
class AllocationInstruction extends CallInstruction {
154-
AllocationInstruction() { this.getStaticCallTarget() instanceof Cpp::AllocationFunction }
155-
}
156-
157149
private predicate isIndirectionType(Type t) { t instanceof Indirection }
158150

159151
private predicate hasUnspecifiedBaseType(Indirection t, Type base) {
@@ -368,17 +360,22 @@ newtype TBaseSourceVariable =
368360
// Each IR variable gets its own source variable
369361
TBaseIRVariable(IRVariable var) or
370362
// Each allocation gets its own source variable
371-
TBaseCallVariable(AllocationInstruction call)
363+
TBaseCallVariable(CallInstruction call) { not call.getResultIRType() instanceof IRVoidType }
372364

373-
abstract class BaseSourceVariable extends TBaseSourceVariable {
365+
abstract private class AbstractBaseSourceVariable extends TBaseSourceVariable {
374366
/** Gets a textual representation of this element. */
375367
abstract string toString();
376368

377369
/** Gets the type of this base source variable. */
378-
abstract DataFlowType getType();
370+
final DataFlowType getType() { this.getLanguageType().hasUnspecifiedType(result, _) }
371+
372+
/** Gets the `CppType` of this base source variable. */
373+
abstract CppType getLanguageType();
379374
}
380375

381-
class BaseIRVariable extends BaseSourceVariable, TBaseIRVariable {
376+
final class BaseSourceVariable = AbstractBaseSourceVariable;
377+
378+
class BaseIRVariable extends AbstractBaseSourceVariable, TBaseIRVariable {
382379
IRVariable var;
383380

384381
IRVariable getIRVariable() { result = var }
@@ -387,19 +384,19 @@ class BaseIRVariable extends BaseSourceVariable, TBaseIRVariable {
387384

388385
override string toString() { result = var.toString() }
389386

390-
override DataFlowType getType() { result = var.getType() }
387+
override CppType getLanguageType() { result = var.getLanguageType() }
391388
}
392389

393-
class BaseCallVariable extends BaseSourceVariable, TBaseCallVariable {
394-
AllocationInstruction call;
390+
class BaseCallVariable extends AbstractBaseSourceVariable, TBaseCallVariable {
391+
CallInstruction call;
395392

396393
BaseCallVariable() { this = TBaseCallVariable(call) }
397394

398-
AllocationInstruction getCallInstruction() { result = call }
395+
CallInstruction getCallInstruction() { result = call }
399396

400397
override string toString() { result = call.toString() }
401398

402-
override DataFlowType getType() { result = call.getResultType() }
399+
override CppType getLanguageType() { result = getResultLanguageType(call) }
403400
}
404401

405402
/**
@@ -499,8 +496,7 @@ private class BaseIRVariableInstruction extends BaseSourceVariableInstruction,
499496
override BaseIRVariable getBaseSourceVariable() { result.getIRVariable() = this.getIRVariable() }
500497
}
501498

502-
private class BaseAllocationInstruction extends BaseSourceVariableInstruction, AllocationInstruction
503-
{
499+
private class BaseCallInstruction extends BaseSourceVariableInstruction, CallInstruction {
504500
override BaseCallVariable getBaseSourceVariable() { result.getCallInstruction() = this }
505501
}
506502

0 commit comments

Comments
 (0)