Skip to content

Commit 250ac68

Browse files
authored
Merge branch 'main' into redsun82/swift-open-redirection
2 parents a93e361 + e0f1b38 commit 250ac68

File tree

84 files changed

+565
-399
lines changed

Some content is hidden

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

84 files changed

+565
-399
lines changed
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 `getaddrinfo` function is now recognized as a flow source.
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 `ArgvSource` flow source has been generalized to handle cases where the argument vector of `main` is not named `argv`.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ private class Fread extends AliasFunction, RemoteFlowSourceFunction {
1515

1616
override predicate hasRemoteFlowSource(FunctionOutput output, string description) {
1717
output.isParameterDeref(0) and
18-
description = "String read by " + this.getName()
18+
description = "string read by " + this.getName()
1919
}
2020
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ private class GetDelimFunction extends TaintFunction, AliasFunction, SideEffectF
3636

3737
override predicate hasRemoteFlowSource(FunctionOutput output, string description) {
3838
output.isParameterDeref(0) and
39-
description = "String read by " + this.getName()
39+
description = "string read by " + this.getName()
4040
}
4141
}

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

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

5050
override predicate hasRemoteFlowSource(FunctionOutput output, string description) {
5151
output.isParameterDeref(0) and
52-
description = "String read by " + this.getName()
52+
description = "string read by " + this.getName()
5353
or
5454
output.isReturnValue() and
55-
description = "String read by " + this.getName()
55+
description = "string read by " + this.getName()
5656
}
5757

5858
override predicate hasArrayWithVariableSize(int bufParam, int countParam) {
@@ -98,10 +98,10 @@ private class GetsFunction extends DataFlowFunction, ArrayFunction, AliasFunctio
9898

9999
override predicate hasLocalFlowSource(FunctionOutput output, string description) {
100100
output.isParameterDeref(0) and
101-
description = "String read by " + this.getName()
101+
description = "string read by " + this.getName()
102102
or
103103
output.isReturnValue() and
104-
description = "String read by " + this.getName()
104+
description = "string read by " + this.getName()
105105
}
106106

107107
override predicate hasArrayWithUnknownSize(int bufParam) { bufParam = 0 }

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

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import semmle.code.cpp.models.interfaces.Taint
22
import semmle.code.cpp.models.interfaces.Alias
33
import semmle.code.cpp.models.interfaces.ArrayFunction
4+
import semmle.code.cpp.models.interfaces.FlowSource
45

56
private class InetNtoa extends TaintFunction {
6-
InetNtoa() { hasGlobalName("inet_ntoa") }
7+
InetNtoa() { this.hasGlobalName("inet_ntoa") }
78

89
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
910
input.isParameter(0) and
@@ -12,7 +13,7 @@ private class InetNtoa extends TaintFunction {
1213
}
1314

1415
private class InetAton extends TaintFunction, ArrayFunction {
15-
InetAton() { hasGlobalName("inet_aton") }
16+
InetAton() { this.hasGlobalName("inet_aton") }
1617

1718
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
1819
input.isParameterDeref(0) and
@@ -32,7 +33,7 @@ private class InetAton extends TaintFunction, ArrayFunction {
3233
}
3334

3435
private class InetAddr extends TaintFunction, ArrayFunction, AliasFunction {
35-
InetAddr() { hasGlobalName("inet_addr") }
36+
InetAddr() { this.hasGlobalName("inet_addr") }
3637

3738
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
3839
input.isParameterDeref(0) and
@@ -51,7 +52,7 @@ private class InetAddr extends TaintFunction, ArrayFunction, AliasFunction {
5152
}
5253

5354
private class InetNetwork extends TaintFunction, ArrayFunction {
54-
InetNetwork() { hasGlobalName("inet_network") }
55+
InetNetwork() { this.hasGlobalName("inet_network") }
5556

5657
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
5758
input.isParameterDeref(0) and
@@ -64,7 +65,7 @@ private class InetNetwork extends TaintFunction, ArrayFunction {
6465
}
6566

6667
private class InetMakeaddr extends TaintFunction {
67-
InetMakeaddr() { hasGlobalName("inet_makeaddr") }
68+
InetMakeaddr() { this.hasGlobalName("inet_makeaddr") }
6869

6970
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
7071
(
@@ -76,7 +77,7 @@ private class InetMakeaddr extends TaintFunction {
7677
}
7778

7879
private class InetLnaof extends TaintFunction {
79-
InetLnaof() { hasGlobalName("inet_lnaof") }
80+
InetLnaof() { this.hasGlobalName("inet_lnaof") }
8081

8182
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
8283
input.isParameter(0) and
@@ -85,7 +86,7 @@ private class InetLnaof extends TaintFunction {
8586
}
8687

8788
private class InetNetof extends TaintFunction {
88-
InetNetof() { hasGlobalName("inet_netof") }
89+
InetNetof() { this.hasGlobalName("inet_netof") }
8990

9091
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
9192
input.isParameter(0) and
@@ -94,7 +95,7 @@ private class InetNetof extends TaintFunction {
9495
}
9596

9697
private class InetPton extends TaintFunction, ArrayFunction {
97-
InetPton() { hasGlobalName("inet_pton") }
98+
InetPton() { this.hasGlobalName("inet_pton") }
9899

99100
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
100101
(
@@ -114,7 +115,7 @@ private class InetPton extends TaintFunction, ArrayFunction {
114115
}
115116

116117
private class Gethostbyname extends TaintFunction, ArrayFunction {
117-
Gethostbyname() { hasGlobalName("gethostbyname") }
118+
Gethostbyname() { this.hasGlobalName("gethostbyname") }
118119

119120
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
120121
input.isParameterDeref(0) and
@@ -127,7 +128,7 @@ private class Gethostbyname extends TaintFunction, ArrayFunction {
127128
}
128129

129130
private class Gethostbyaddr extends TaintFunction, ArrayFunction {
130-
Gethostbyaddr() { hasGlobalName("gethostbyaddr") }
131+
Gethostbyaddr() { this.hasGlobalName("gethostbyaddr") }
131132

132133
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
133134
(
@@ -142,3 +143,21 @@ private class Gethostbyaddr extends TaintFunction, ArrayFunction {
142143

143144
override predicate hasArrayWithNullTerminator(int bufParam) { bufParam = 0 }
144145
}
146+
147+
private class Getaddrinfo extends TaintFunction, ArrayFunction, RemoteFlowSourceFunction {
148+
Getaddrinfo() { this.hasGlobalName("getaddrinfo") }
149+
150+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
151+
input.isParameterDeref([0 .. 2]) and
152+
output.isParameterDeref(3)
153+
}
154+
155+
override predicate hasArrayInput(int bufParam) { bufParam in [0, 1] }
156+
157+
override predicate hasArrayWithNullTerminator(int bufParam) { bufParam in [0, 1] }
158+
159+
override predicate hasRemoteFlowSource(FunctionOutput output, string description) {
160+
output.isParameterDeref(3) and
161+
description = "address returned by " + this.getName()
162+
}
163+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private class Recv extends AliasFunction, ArrayFunction, SideEffectFunction,
8383
or
8484
this.hasGlobalName("recvfrom") and output.isParameterDeref([4, 5])
8585
) and
86-
description = "Buffer read by " + this.getName()
86+
description = "buffer read by " + this.getName()
8787
}
8888

8989
override predicate hasSocketInput(FunctionInput input) { input.isParameter(0) }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ abstract private class ScanfFunctionModel extends ArrayFunction, TaintFunction,
7474
private class ScanfModel extends ScanfFunctionModel, LocalFlowSourceFunction instanceof Scanf {
7575
override predicate hasLocalFlowSource(FunctionOutput output, string description) {
7676
output.isParameterDeref(any(int i | i >= this.getArgsStartPosition())) and
77-
description = "Value read by " + this.getName()
77+
description = "value read by " + this.getName()
7878
}
7979
}
8080

@@ -84,7 +84,7 @@ private class ScanfModel extends ScanfFunctionModel, LocalFlowSourceFunction ins
8484
private class FscanfModel extends ScanfFunctionModel, RemoteFlowSourceFunction instanceof Fscanf {
8585
override predicate hasRemoteFlowSource(FunctionOutput output, string description) {
8686
output.isParameterDeref(any(int i | i >= this.getArgsStartPosition())) and
87-
description = "Value read by " + this.getName()
87+
description = "value read by " + this.getName()
8888
}
8989
}
9090

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private class Send extends AliasFunction, ArrayFunction, SideEffectFunction, Rem
5858
override ParameterIndex getParameterSizeIndex(ParameterIndex i) { i = 1 and result = 2 }
5959

6060
override predicate hasRemoteFlowSink(FunctionInput input, string description) {
61-
input.isParameterDeref(1) and description = "Buffer sent by " + this.getName()
61+
input.isParameterDeref(1) and description = "buffer sent by " + this.getName()
6262
}
6363

6464
override predicate hasSocketInput(FunctionInput input) { input.isParameter(0) }

cpp/ql/lib/semmle/code/cpp/security/FlowSources.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ private class LocalParameterSource extends LocalFlowSource {
8989

9090
private class ArgvSource extends LocalFlowSource {
9191
ArgvSource() {
92-
exists(Parameter argv |
93-
argv.hasName("argv") and
94-
argv.getFunction().hasGlobalName("main") and
92+
exists(Function main, Parameter argv |
93+
main.hasGlobalName("main") and
94+
main.getParameter(1) = argv and
9595
this.asExpr() = argv.getAnAccess()
9696
)
9797
}

0 commit comments

Comments
 (0)