Skip to content

Commit fd750a3

Browse files
committed
Merge branch 'main' into tausbn/python-add-support-for-python-3.12-type-syntax
2 parents cfdeb0e + 71ef985 commit fd750a3

File tree

1,863 files changed

+88101
-30493
lines changed

Some content is hidden

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

1,863 files changed

+88101
-30493
lines changed

cpp/autobuilder/Semmle.Autobuild.Cpp.Tests/BuildScripts.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ IEnumerable<string> IBuildActions.EnumerateDirectories(string dir)
145145

146146
bool IBuildActions.IsMacOs() => IsMacOs;
147147

148-
public bool IsArm { get; set; }
148+
public bool IsRunningOnAppleSilicon { get; set; }
149149

150-
bool IBuildActions.IsArm() => IsArm;
150+
bool IBuildActions.IsRunningOnAppleSilicon() => IsRunningOnAppleSilicon;
151151

152152
string IBuildActions.PathCombine(params string[] parts)
153153
{
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added models for the `sprintf` variants from the `StrSafe.h` header.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added models for `strlcpy` and `strlcat`.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The "Returning stack-allocated memory" (`cpp/return-stack-allocated-memory`) query now also detects returning stack-allocated memory allocated by calls to `alloca`, `strdupa`, and `strndupa`.

cpp/ql/lib/semmle/code/cpp/ir/dataflow/MustFlow.qll

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ abstract class MustFlowConfiguration extends string {
3131
*/
3232
abstract predicate isSink(Operand sink);
3333

34+
/**
35+
* Holds if data flow through `instr` is prohibited.
36+
*/
37+
predicate isBarrier(Instruction instr) { none() }
38+
3439
/**
3540
* Holds if the additional flow step from `node1` to `node2` must be taken
3641
* into account in the analysis.
@@ -48,18 +53,21 @@ abstract class MustFlowConfiguration extends string {
4853
*/
4954
final predicate hasFlowPath(MustFlowPathNode source, MustFlowPathSink sink) {
5055
this.isSource(source.getInstruction()) and
51-
source.getASuccessor+() = sink
56+
source.getASuccessor*() = sink
5257
}
5358
}
5459

5560
/** Holds if `node` flows from a source. */
5661
pragma[nomagic]
5762
private predicate flowsFromSource(Instruction node, MustFlowConfiguration config) {
58-
config.isSource(node)
59-
or
60-
exists(Instruction mid |
61-
step(mid, node, config) and
62-
flowsFromSource(mid, pragma[only_bind_into](config))
63+
not config.isBarrier(node) and
64+
(
65+
config.isSource(node)
66+
or
67+
exists(Instruction mid |
68+
step(mid, node, config) and
69+
flowsFromSource(mid, pragma[only_bind_into](config))
70+
)
6371
)
6472
}
6573

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ class Node0Impl extends TIRDataFlowNode0 {
8181
/** Gets the operands corresponding to this node, if any. */
8282
Operand asOperand() { result = this.(OperandNode0).getOperand() }
8383

84+
/** Gets the location of this node. */
85+
final Location getLocation() { result = this.getLocationImpl() }
86+
87+
/** INTERNAL: Do not use. */
88+
Location getLocationImpl() {
89+
none() // overridden by subclasses
90+
}
91+
8492
/** INTERNAL: Do not use. */
8593
string toStringImpl() {
8694
none() // overridden by subclasses
@@ -131,9 +139,15 @@ abstract class InstructionNode0 extends Node0Impl {
131139
override DataFlowType getType() { result = getInstructionType(instr, _) }
132140

133141
override string toStringImpl() {
134-
// This predicate is overridden in subclasses. This default implementation
135-
// does not use `Instruction.toString` because that's expensive to compute.
136-
result = instr.getOpcode().toString()
142+
if instr.(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable
143+
then result = "this"
144+
else result = instr.getAst().toString()
145+
}
146+
147+
override Location getLocationImpl() {
148+
if exists(instr.getAst().getLocation())
149+
then result = instr.getAst().getLocation()
150+
else result instanceof UnknownDefaultLocation
137151
}
138152

139153
final override predicate isGLValue() { exists(getInstructionType(instr, true)) }
@@ -173,7 +187,17 @@ abstract class OperandNode0 extends Node0Impl {
173187

174188
override DataFlowType getType() { result = getOperandType(op, _) }
175189

176-
override string toStringImpl() { result = op.toString() }
190+
override string toStringImpl() {
191+
if op.getDef().(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable
192+
then result = "this"
193+
else result = op.getDef().getAst().toString()
194+
}
195+
196+
override Location getLocationImpl() {
197+
if exists(op.getDef().getAst().getLocation())
198+
then result = op.getDef().getAst().getLocation()
199+
else result instanceof UnknownDefaultLocation
200+
}
177201

178202
final override predicate isGLValue() { exists(getOperandType(op, true)) }
179203
}
@@ -632,20 +656,20 @@ predicate jumpStep(Node n1, Node n2) {
632656
v = globalUse.getVariable() and
633657
n1.(FinalGlobalValue).getGlobalUse() = globalUse
634658
|
635-
globalUse.getIndirectionIndex() = 1 and
659+
globalUse.getIndirection() = 1 and
636660
v = n2.asVariable()
637661
or
638-
v = n2.asIndirectVariable(globalUse.getIndirectionIndex())
662+
v = n2.asIndirectVariable(globalUse.getIndirection())
639663
)
640664
or
641665
exists(Ssa::GlobalDef globalDef |
642666
v = globalDef.getVariable() and
643667
n2.(InitialGlobalValue).getGlobalDef() = globalDef
644668
|
645-
globalDef.getIndirectionIndex() = 1 and
669+
globalDef.getIndirection() = 1 and
646670
v = n1.asVariable()
647671
or
648-
v = n1.asIndirectVariable(globalDef.getIndirectionIndex())
672+
v = n1.asIndirectVariable(globalDef.getIndirection())
649673
)
650674
)
651675
}

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

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,10 @@ private class Node0 extends Node, TNode0 {
432432

433433
override Declaration getFunction() { result = node.getFunction() }
434434

435+
override Location getLocationImpl() { result = node.getLocation() }
436+
437+
override string toStringImpl() { result = node.toString() }
438+
435439
override DataFlowType getType() { result = node.getType() }
436440

437441
override predicate isGLValue() { node.isGLValue() }
@@ -448,18 +452,6 @@ class InstructionNode extends Node0 {
448452

449453
/** Gets the instruction corresponding to this node. */
450454
Instruction getInstruction() { result = instr }
451-
452-
override Location getLocationImpl() {
453-
if exists(instr.getAst().getLocation())
454-
then result = instr.getAst().getLocation()
455-
else result instanceof UnknownDefaultLocation
456-
}
457-
458-
override string toStringImpl() {
459-
if instr.(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable
460-
then result = "this"
461-
else result = instr.getAst().toString()
462-
}
463455
}
464456

465457
/**
@@ -473,18 +465,6 @@ class OperandNode extends Node, Node0 {
473465

474466
/** Gets the operand corresponding to this node. */
475467
Operand getOperand() { result = op }
476-
477-
override Location getLocationImpl() {
478-
if exists(op.getDef().getAst().getLocation())
479-
then result = op.getDef().getAst().getLocation()
480-
else result instanceof UnknownDefaultLocation
481-
}
482-
483-
override string toStringImpl() {
484-
if op.getDef().(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable
485-
then result = "this"
486-
else result = op.getDef().getAst().toString()
487-
}
488468
}
489469

490470
/**

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

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,12 @@ private newtype TDefOrUseImpl =
113113
TGlobalUse(GlobalLikeVariable v, IRFunction f, int indirectionIndex) {
114114
// Represents a final "use" of a global variable to ensure that
115115
// the assignment to a global variable isn't ruled out as dead.
116-
exists(VariableAddressInstruction vai, int defIndex |
117-
vai.getEnclosingIRFunction() = f and
118-
vai.getAstVariable() = v and
119-
isDef(_, _, _, vai, _, defIndex) and
120-
indirectionIndex = [0 .. defIndex] + 1
121-
)
116+
isGlobalUse(v, f, _, indirectionIndex)
122117
} or
123118
TGlobalDefImpl(GlobalLikeVariable v, IRFunction f, int indirectionIndex) {
124119
// Represents the initial "definition" of a global variable when entering
125120
// a function body.
126-
exists(VariableAddressInstruction vai |
127-
vai.getEnclosingIRFunction() = f and
128-
vai.getAstVariable() = v and
129-
isUse(_, _, vai, _, indirectionIndex) and
130-
not isDef(_, _, vai.getAUse(), _, _, _)
131-
)
121+
isGlobalDefImpl(v, f, _, indirectionIndex)
132122
} or
133123
TIteratorDef(
134124
Operand iteratorDerefAddress, BaseSourceVariableInstruction container, int indirectionIndex
@@ -150,6 +140,27 @@ private newtype TDefOrUseImpl =
150140
)
151141
}
152142

143+
private predicate isGlobalUse(
144+
GlobalLikeVariable v, IRFunction f, int indirection, int indirectionIndex
145+
) {
146+
exists(VariableAddressInstruction vai |
147+
vai.getEnclosingIRFunction() = f and
148+
vai.getAstVariable() = v and
149+
isDef(_, _, _, vai, indirection, indirectionIndex)
150+
)
151+
}
152+
153+
private predicate isGlobalDefImpl(
154+
GlobalLikeVariable v, IRFunction f, int indirection, int indirectionIndex
155+
) {
156+
exists(VariableAddressInstruction vai |
157+
vai.getEnclosingIRFunction() = f and
158+
vai.getAstVariable() = v and
159+
isUse(_, _, vai, indirection, indirectionIndex) and
160+
not isDef(_, _, _, vai, _, indirectionIndex)
161+
)
162+
}
163+
153164
private predicate unspecifiedTypeIsModifiableAt(Type unspecified, int indirectionIndex) {
154165
indirectionIndex = [1 .. getIndirectionForUnspecifiedType(unspecified).getNumberOfIndirections()] and
155166
exists(CppType cppType |
@@ -438,7 +449,7 @@ class GlobalUse extends UseImpl, TGlobalUse {
438449

439450
override FinalGlobalValue getNode() { result.getGlobalUse() = this }
440451

441-
override int getIndirection() { result = ind + 1 }
452+
override int getIndirection() { isGlobalUse(global, f, result, ind) }
442453

443454
/** Gets the global variable associated with this use. */
444455
GlobalLikeVariable getVariable() { result = global }
@@ -460,7 +471,9 @@ class GlobalUse extends UseImpl, TGlobalUse {
460471
)
461472
}
462473

463-
override SourceVariable getSourceVariable() { sourceVariableIsGlobal(result, global, f, ind) }
474+
override SourceVariable getSourceVariable() {
475+
sourceVariableIsGlobal(result, global, f, this.getIndirection())
476+
}
464477

465478
final override Cpp::Location getLocation() { result = f.getLocation() }
466479

@@ -501,16 +514,18 @@ class GlobalDefImpl extends DefOrUseImpl, TGlobalDefImpl {
501514

502515
/** Gets the global variable associated with this definition. */
503516
override SourceVariable getSourceVariable() {
504-
sourceVariableIsGlobal(result, global, f, indirectionIndex)
517+
sourceVariableIsGlobal(result, global, f, this.getIndirection())
505518
}
506519

520+
int getIndirection() { result = indirectionIndex }
521+
507522
/**
508523
* Gets the type of this use after specifiers have been deeply stripped
509524
* and typedefs have been resolved.
510525
*/
511526
Type getUnspecifiedType() { result = global.getUnspecifiedType() }
512527

513-
override string toString() { result = "GlobalDef" }
528+
override string toString() { result = "Def of " + this.getSourceVariable() }
514529

515530
override Location getLocation() { result = f.getLocation() }
516531

@@ -980,7 +995,7 @@ class GlobalDef extends TGlobalDef, SsaDefOrUse {
980995
final override Location getLocation() { result = global.getLocation() }
981996

982997
/** Gets a textual representation of this definition. */
983-
override string toString() { result = "GlobalDef" }
998+
override string toString() { result = global.toString() }
984999

9851000
/**
9861001
* Holds if this definition has index `index` in block `block`, and
@@ -990,6 +1005,9 @@ class GlobalDef extends TGlobalDef, SsaDefOrUse {
9901005
global.hasIndexInBlock(block, index, sv)
9911006
}
9921007

1008+
/** Gets the indirection index of this definition. */
1009+
int getIndirection() { result = global.getIndirection() }
1010+
9931011
/** Gets the indirection index of this definition. */
9941012
int getIndirectionIndex() { result = global.getIndirectionIndex() }
9951013

cpp/ql/lib/semmle/code/cpp/models/implementations/Gets.qll

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ private class FgetsFunction extends DataFlowFunction, TaintFunction, ArrayFuncti
4949
}
5050

5151
override predicate hasRemoteFlowSource(FunctionOutput output, string description) {
52-
output.isParameterDeref(0) and
53-
description = "string read by " + this.getName()
54-
or
55-
output.isReturnValue() and
52+
(
53+
output.isParameterDeref(0) or
54+
output.isReturnValue() or
55+
output.isReturnValueDeref()
56+
) and
5657
description = "string read by " + this.getName()
5758
}
5859

cpp/ql/lib/semmle/code/cpp/models/implementations/Inet.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private class Getaddrinfo extends TaintFunction, ArrayFunction, RemoteFlowSource
157157
override predicate hasArrayWithNullTerminator(int bufParam) { bufParam in [0, 1] }
158158

159159
override predicate hasRemoteFlowSource(FunctionOutput output, string description) {
160-
output.isParameterDeref(3) and
160+
output.isParameterDeref(3, 2) and
161161
description = "address returned by " + this.getName()
162162
}
163163
}

0 commit comments

Comments
 (0)