Skip to content

Commit 0722867

Browse files
committed
Merge branch 'main' into aeisenberg/remove-upgrades
2 parents 83ceb82 + c45127f commit 0722867

File tree

216 files changed

+8445
-2010
lines changed

Some content is hidden

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

216 files changed

+8445
-2010
lines changed

.codeqlmanifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"cpp/ql/test/query-tests/Security/CWE/CWE-190/semmle/tainted/qlpack.yml",
88
"javascript/ql/experimental/adaptivethreatmodeling/lib/qlpack.yml",
99
"javascript/ql/experimental/adaptivethreatmodeling/src/qlpack.yml",
10+
"csharp/ql/campaigns/Solorigate/lib/qlpack.yml",
11+
"csharp/ql/campaigns/Solorigate/src/qlpack.yml",
12+
"csharp/ql/campaigns/Solorigate/test/qlpack.yml",
1013
"misc/legacy-support/*/qlpack.yml",
1114
"misc/suite-helpers/qlpack.yml",
1215
"ruby/extractor-pack/codeql-extractor.yml",

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# CodeQL
22

3-
This open source repository contains the standard CodeQL libraries and queries that power [LGTM](https://lgtm.com) and the other CodeQL products that [GitHub](https://github.com) makes available to its customers worldwide. For the queries, libraries, and extractor that power Go analysis, visit the [CodeQL for Go repository](https://github.com/github/codeql-go).
3+
This open source repository contains the standard CodeQL libraries and queries that power [GitHub Advanced Security](https://github.com/features/security/code) and the other application security products that [GitHub](https://github.com/features/security/) makes available to its customers worldwide. For the queries, libraries, and extractor that power Go analysis, visit the [CodeQL for Go repository](https://github.com/github/codeql-go).
44

55
## How do I learn CodeQL and run queries?
66

77
There is [extensive documentation](https://codeql.github.com/docs/) on getting started with writing CodeQL.
8-
You can use the [interactive query console](https://lgtm.com/help/lgtm/using-query-console) on LGTM.com or the [CodeQL for Visual Studio Code](https://codeql.github.com/docs/codeql-for-visual-studio-code/) extension to try out your queries on any open source project that's currently being analyzed.
8+
You can use the [CodeQL for Visual Studio Code](https://codeql.github.com/docs/codeql-for-visual-studio-code/) extension or the [interactive query console](https://lgtm.com/help/lgtm/using-query-console) on LGTM.com (Semmle Legacy product) to try out your queries on any open source project that's currently being analyzed.
99

1010
## Contributing
1111

1212
We welcome contributions to our standard library and standard checks. Do you have an idea for a new check, or how to improve an existing query? Then please go ahead and open a pull request! Before you do, though, please take the time to read our [contributing guidelines](CONTRIBUTING.md). You can also consult our [style guides](https://github.com/github/codeql/tree/main/docs) to learn how to format your code for consistency and clarity, how to write query metadata, and how to write query help documentation for your query.
1313

1414
## License
1515

16-
The code in this repository is licensed under the [MIT License](LICENSE) by [GitHub](https://github.com).
16+
The code in this repository is licensed under the [MIT License](LICENSE) by [GitHub](https://github.com). The use of CodeQL on open source code is licensed under specific [Terms & Conditions](https://securitylab.github.com/tools/codeql/license/) UNLESS you have a commercial license in place. If you'd like to use CodeQL with a commercial codebase, please [contact us](https://github.com/enterprise/contact) for further help.
1717

1818
## Visual Studio Code integration
1919

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private module VirtualDispatch {
6363
this.flowsFrom(other, allowOtherFromArg)
6464
|
6565
// Call argument
66-
exists(DataFlowCall call, int i |
66+
exists(DataFlowCall call, Position i |
6767
other
6868
.(DataFlow::ParameterNode)
6969
.isParameterOf(pragma[only_bind_into](call).getStaticCallTarget(), i) and
@@ -268,16 +268,6 @@ Function viableImplInCallContext(CallInstruction call, CallInstruction ctx) {
268268
)
269269
}
270270

271-
/** A parameter position represented by an integer. */
272-
class ParameterPosition extends int {
273-
ParameterPosition() { any(ParameterNode p).isParameterOf(_, this) }
274-
}
275-
276-
/** An argument position represented by an integer. */
277-
class ArgumentPosition extends int {
278-
ArgumentPosition() { any(ArgumentNode a).argumentOf(_, this) }
279-
}
280-
281271
/** Holds if arguments at position `apos` match parameters at position `ppos`. */
282272
pragma[inline]
283273
predicate parameterMatch(ParameterPosition ppos, ArgumentPosition apos) { ppos = apos }

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

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ abstract class ArgumentNode extends OperandNode {
2727
* Holds if this argument occurs at the given position in the given call.
2828
* The instance argument is considered to have index `-1`.
2929
*/
30-
abstract predicate argumentOf(DataFlowCall call, int pos);
30+
abstract predicate argumentOf(DataFlowCall call, ArgumentPosition pos);
3131

3232
/** Gets the call in which this node is an argument. */
3333
DataFlowCall getCall() { this.argumentOf(result, _) }
@@ -42,7 +42,9 @@ private class PrimaryArgumentNode extends ArgumentNode {
4242

4343
PrimaryArgumentNode() { exists(CallInstruction call | op = call.getAnArgumentOperand()) }
4444

45-
override predicate argumentOf(DataFlowCall call, int pos) { op = call.getArgumentOperand(pos) }
45+
override predicate argumentOf(DataFlowCall call, ArgumentPosition pos) {
46+
op = call.getArgumentOperand(pos.(DirectPosition).getIndex())
47+
}
4648

4749
override string toString() {
4850
exists(Expr unconverted |
@@ -71,9 +73,9 @@ private class SideEffectArgumentNode extends ArgumentNode {
7173

7274
SideEffectArgumentNode() { op = read.getSideEffectOperand() }
7375

74-
override predicate argumentOf(DataFlowCall call, int pos) {
76+
override predicate argumentOf(DataFlowCall call, ArgumentPosition pos) {
7577
read.getPrimaryInstruction() = call and
76-
pos = getArgumentPosOfSideEffect(read.getIndex())
78+
pos.(IndirectionPosition).getIndex() = read.getIndex()
7779
}
7880

7981
override string toString() {
@@ -90,6 +92,54 @@ private class SideEffectArgumentNode extends ArgumentNode {
9092
}
9193
}
9294

95+
/** A parameter position represented by an integer. */
96+
class ParameterPosition = Position;
97+
98+
/** An argument position represented by an integer. */
99+
class ArgumentPosition = Position;
100+
101+
class Position extends TPosition {
102+
abstract string toString();
103+
}
104+
105+
class DirectPosition extends TDirectPosition {
106+
int index;
107+
108+
DirectPosition() { this = TDirectPosition(index) }
109+
110+
string toString() {
111+
index = -1 and
112+
result = "this"
113+
or
114+
index != -1 and
115+
result = index.toString()
116+
}
117+
118+
int getIndex() { result = index }
119+
}
120+
121+
class IndirectionPosition extends TIndirectionPosition {
122+
int index;
123+
124+
IndirectionPosition() { this = TIndirectionPosition(index) }
125+
126+
string toString() {
127+
index = -1 and
128+
result = "this"
129+
or
130+
index != -1 and
131+
result = index.toString()
132+
}
133+
134+
int getIndex() { result = index }
135+
}
136+
137+
newtype TPosition =
138+
TDirectPosition(int index) { exists(any(CallInstruction c).getArgument(index)) } or
139+
TIndirectionPosition(int index) {
140+
exists(ReadSideEffectInstruction instr | instr.getIndex() = index)
141+
}
142+
93143
private newtype TReturnKind =
94144
TNormalReturnKind() or
95145
TIndirectReturnKind(ParameterIndex index)

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

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -490,19 +490,6 @@ class ExprNode extends InstructionNode {
490490
override string toString() { result = this.asConvertedExpr().toString() }
491491
}
492492

493-
/**
494-
* INTERNAL: do not use. Translates a parameter/argument index into a negative
495-
* number that denotes the index of its side effect (pointer indirection).
496-
*/
497-
bindingset[index]
498-
int getArgumentPosOfSideEffect(int index) {
499-
// -1 -> -2
500-
// 0 -> -3
501-
// 1 -> -4
502-
// ...
503-
result = -3 - index
504-
}
505-
506493
/**
507494
* The value of a parameter at function entry, viewed as a node in a data
508495
* flow graph. This includes both explicit parameters such as `x` in `f(x)`
@@ -525,7 +512,7 @@ class ParameterNode extends InstructionNode {
525512
* implicit `this` parameter is considered to have position `-1`, and
526513
* pointer-indirection parameters are at further negative positions.
527514
*/
528-
predicate isParameterOf(Function f, int pos) { none() } // overridden by subclasses
515+
predicate isParameterOf(Function f, ParameterPosition pos) { none() } // overridden by subclasses
529516
}
530517

531518
/** An explicit positional parameter, not including `this` or `...`. */
@@ -534,8 +521,8 @@ private class ExplicitParameterNode extends ParameterNode {
534521

535522
ExplicitParameterNode() { exists(instr.getParameter()) }
536523

537-
override predicate isParameterOf(Function f, int pos) {
538-
f.getParameter(pos) = instr.getParameter()
524+
override predicate isParameterOf(Function f, ParameterPosition pos) {
525+
f.getParameter(pos.(DirectPosition).getIndex()) = instr.getParameter()
539526
}
540527

541528
/** Gets the `Parameter` associated with this node. */
@@ -550,8 +537,8 @@ class ThisParameterNode extends ParameterNode {
550537

551538
ThisParameterNode() { instr.getIRVariable() instanceof IRThisVariable }
552539

553-
override predicate isParameterOf(Function f, int pos) {
554-
pos = -1 and instr.getEnclosingFunction() = f
540+
override predicate isParameterOf(Function f, ParameterPosition pos) {
541+
pos.(DirectPosition).getIndex() = -1 and instr.getEnclosingFunction() = f
555542
}
556543

557544
override string toString() { result = "this" }
@@ -561,12 +548,12 @@ class ThisParameterNode extends ParameterNode {
561548
class ParameterIndirectionNode extends ParameterNode {
562549
override InitializeIndirectionInstruction instr;
563550

564-
override predicate isParameterOf(Function f, int pos) {
551+
override predicate isParameterOf(Function f, ParameterPosition pos) {
565552
exists(int index |
566553
instr.getEnclosingFunction() = f and
567554
instr.hasIndex(index)
568555
|
569-
pos = getArgumentPosOfSideEffect(index)
556+
pos.(IndirectionPosition).getIndex() = index
570557
)
571558
}
572559

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,4 +659,15 @@ module Consistency {
659659
not phiHasInputFromBlock(_, def, _) and
660660
not uncertainWriteDefinitionInput(_, def)
661661
}
662+
663+
query predicate notDominatedByDef(RelevantDefinition def, SourceVariable v, BasicBlock bb, int i) {
664+
exists(BasicBlock bbDef, int iDef | def.definesAt(v, bbDef, iDef) |
665+
ssaDefReachesReadWithinBlock(v, def, bb, i) and
666+
(bb != bbDef or i < iDef)
667+
or
668+
ssaDefReachesRead(v, def, bb, i) and
669+
not ssaDefReachesReadWithinBlock(v, def, bb, i) and
670+
not def.definesAt(v, getImmediateBasicBlockDominator*(bb), _)
671+
)
672+
}
662673
}

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

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,6 @@ private newtype TDefOrUse =
5151
TExplicitUse(Operand op) { isExplicitUse(op) } or
5252
TReturnParamIndirection(Operand op) { returnParameterIndirection(op, _) }
5353

54-
pragma[nomagic]
55-
private int getRank(DefOrUse defOrUse, IRBlock block) {
56-
defOrUse =
57-
rank[result](int i, DefOrUse cand |
58-
block.getInstruction(i) = toInstruction(cand)
59-
|
60-
cand order by i
61-
)
62-
}
63-
6454
private class DefOrUse extends TDefOrUse {
6555
/** Gets the instruction associated with this definition, if any. */
6656
Instruction asDef() { none() }
@@ -74,9 +64,10 @@ private class DefOrUse extends TDefOrUse {
7464
/** Gets the block of this definition or use. */
7565
abstract IRBlock getBlock();
7666

77-
/** Holds if this definition or use has rank `rank` in block `block`. */
78-
cached
79-
final predicate hasRankInBlock(IRBlock block, int rnk) { rnk = getRank(this, block) }
67+
/** Holds if this definition or use has index `index` in block `block`. */
68+
final predicate hasIndexInBlock(IRBlock block, int index) {
69+
block.getInstruction(index) = toInstruction(this)
70+
}
8071

8172
/** Gets the location of this element. */
8273
abstract Cpp::Location getLocation();
@@ -313,8 +304,8 @@ cached
313304
private module Cached {
314305
private predicate defUseFlow(Node nodeFrom, Node nodeTo) {
315306
exists(IRBlock bb1, int i1, IRBlock bb2, int i2, DefOrUse defOrUse, Use use |
316-
defOrUse.hasRankInBlock(bb1, i1) and
317-
use.hasRankInBlock(bb2, i2) and
307+
defOrUse.hasIndexInBlock(bb1, i1) and
308+
use.hasIndexInBlock(bb2, i2) and
318309
adjacentDefRead(_, bb1, i1, bb2, i2) and
319310
nodeFrom.asInstruction() = toInstruction(defOrUse) and
320311
flowOutOfAddressStep(use.getOperand(), nodeTo)
@@ -326,9 +317,9 @@ private module Cached {
326317
exists(IRBlock bb1, int i1, IRBlock bb2, int i2, Def def, Use use |
327318
nodeFrom.isTerminal() and
328319
def.getInstruction() = nodeFrom.getStoreInstruction() and
329-
def.hasRankInBlock(bb1, i1) and
320+
def.hasIndexInBlock(bb1, i1) and
330321
adjacentDefRead(_, bb1, i1, bb2, i2) and
331-
use.hasRankInBlock(bb2, i2) and
322+
use.hasIndexInBlock(bb2, i2) and
332323
flowOutOfAddressStep(use.getOperand(), nodeTo)
333324
)
334325
or
@@ -359,8 +350,8 @@ private module Cached {
359350

360351
private predicate fromReadNode(ReadNode nodeFrom, Node nodeTo) {
361352
exists(IRBlock bb1, int i1, IRBlock bb2, int i2, Use use1, Use use2 |
362-
use1.hasRankInBlock(bb1, i1) and
363-
use2.hasRankInBlock(bb2, i2) and
353+
use1.hasIndexInBlock(bb1, i1) and
354+
use2.hasIndexInBlock(bb2, i2) and
364355
use1.getOperand().getDef() = nodeFrom.getInstruction() and
365356
adjacentDefRead(_, bb1, i1, bb2, i2) and
366357
flowOutOfAddressStep(use2.getOperand(), nodeTo)
@@ -371,15 +362,15 @@ private module Cached {
371362
exists(PhiNode phi, Use use, IRBlock block, int rnk |
372363
phi = nodeFrom.getPhiNode() and
373364
adjacentDefRead(phi, _, _, block, rnk) and
374-
use.hasRankInBlock(block, rnk) and
365+
use.hasIndexInBlock(block, rnk) and
375366
flowOutOfAddressStep(use.getOperand(), nodeTo)
376367
)
377368
}
378369

379370
private predicate toPhiNode(Node nodeFrom, SsaPhiNode nodeTo) {
380371
// Flow to phi nodes
381372
exists(Def def, IRBlock block, int rnk |
382-
def.hasRankInBlock(block, rnk) and
373+
def.hasIndexInBlock(block, rnk) and
383374
nodeTo.hasInputAtRankInBlock(block, rnk)
384375
|
385376
exists(StoreNodeInstr storeNode |
@@ -512,8 +503,8 @@ private module Cached {
512503
|
513504
store = def.getInstruction() and
514505
store.getSourceValueOperand() = operand and
515-
def.hasRankInBlock(block1, rnk1) and
516-
use.hasRankInBlock(block2, rnk2) and
506+
def.hasIndexInBlock(block1, rnk1) and
507+
use.hasIndexInBlock(block2, rnk2) and
517508
adjacentDefRead(_, block1, rnk1, block2, rnk2)
518509
|
519510
// The shared SSA library has determined that `use` is the next use of the operand
@@ -543,12 +534,12 @@ private module Cached {
543534
not operand = getSourceAddressOperand(_) and
544535
exists(Use use1, Use use2, IRBlock block1, int rnk1, IRBlock block2, int rnk2 |
545536
use1.getOperand() = operand and
546-
use1.hasRankInBlock(block1, rnk1) and
537+
use1.hasIndexInBlock(block1, rnk1) and
547538
// Don't flow to the next use if this use is part of a store operation that totally
548539
// overrides a variable.
549540
not explicitWrite(true, _, use1.getOperand().getDef()) and
550541
adjacentDefRead(_, block1, rnk1, block2, rnk2) and
551-
use2.hasRankInBlock(block2, rnk2) and
542+
use2.hasIndexInBlock(block2, rnk2) and
552543
flowOutOfAddressStep(use2.getOperand(), nodeTo)
553544
)
554545
or
@@ -620,7 +611,7 @@ import Cached
620611
predicate variableWrite(IRBlock bb, int i, SourceVariable v, boolean certain) {
621612
DataFlowImplCommon::forceCachingInSameStage() and
622613
exists(Def def |
623-
def.hasRankInBlock(bb, i) and
614+
def.hasIndexInBlock(bb, i) and
624615
v = def.getSourceVariable() and
625616
(if def.isCertain() then certain = true else certain = false)
626617
)
@@ -632,7 +623,7 @@ predicate variableWrite(IRBlock bb, int i, SourceVariable v, boolean certain) {
632623
*/
633624
predicate variableRead(IRBlock bb, int i, SourceVariable v, boolean certain) {
634625
exists(Use use |
635-
use.hasRankInBlock(bb, i) and
626+
use.hasIndexInBlock(bb, i) and
636627
v = use.getSourceVariable() and
637628
certain = true
638629
)

0 commit comments

Comments
 (0)