Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4a81d36

Browse files
committed
C++: Move all of the swap models into Swap.qll.
1 parent ec573b5 commit 4a81d36

6 files changed

Lines changed: 85 additions & 85 deletions

File tree

cpp/ql/src/semmle/code/cpp/models/implementations/StdContainer.qll

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -170,24 +170,6 @@ private class StdSequenceContainerAssign extends TaintFunction {
170170
}
171171
}
172172

173-
/**
174-
* The standard container `swap` functions.
175-
*/
176-
private class StdSequenceContainerSwap extends TaintFunction {
177-
StdSequenceContainerSwap() {
178-
this.hasQualifiedName("std", ["array", "vector", "deque", "list", "forward_list"], "swap")
179-
}
180-
181-
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
182-
// container1.swap(container2)
183-
input.isQualifierObject() and
184-
output.isParameterDeref(0)
185-
or
186-
input.isParameterDeref(0) and
187-
output.isQualifierObject()
188-
}
189-
}
190-
191173
/**
192174
* The standard container functions `at` and `operator[]`.
193175
*/

cpp/ql/src/semmle/code/cpp/models/implementations/StdMap.qll

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,6 @@ private class StdMapTryEmplace extends TaintFunction {
102102
}
103103
}
104104

105-
/**
106-
* The standard map `swap` function.
107-
*/
108-
private class StdMapSwap extends TaintFunction {
109-
StdMapSwap() { this.hasQualifiedName("std", ["map", "unordered_map"], "swap") }
110-
111-
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
112-
// container1.swap(container2)
113-
input.isQualifierObject() and
114-
output.isParameterDeref(0)
115-
or
116-
input.isParameterDeref(0) and
117-
output.isQualifierObject()
118-
}
119-
}
120-
121105
/**
122106
* The standard map `merge` function.
123107
*/

cpp/ql/src/semmle/code/cpp/models/implementations/StdPair.qll

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,3 @@ private class StdPairConstructor extends Constructor, TaintFunction {
6060
)
6161
}
6262
}
63-
64-
/**
65-
* The standard pair `swap` function.
66-
*/
67-
private class StdPairSwap extends TaintFunction {
68-
StdPairSwap() { this.hasQualifiedName("std", "pair", "swap") }
69-
70-
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
71-
// container1.swap(container2)
72-
input.isQualifierObject() and
73-
output.isParameterDeref(0)
74-
or
75-
input.isParameterDeref(0) and
76-
output.isQualifierObject()
77-
}
78-
}

cpp/ql/src/semmle/code/cpp/models/implementations/StdSet.qll

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,6 @@ private class StdSetEmplace extends TaintFunction {
7272
}
7373
}
7474

75-
/**
76-
* The standard set `swap` functions.
77-
*/
78-
private class StdSetSwap extends TaintFunction {
79-
StdSetSwap() { this.hasQualifiedName("std", ["set", "unordered_set"], "swap") }
80-
81-
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
82-
// container1.swap(container2)
83-
input.isQualifierObject() and
84-
output.isParameterDeref(0)
85-
or
86-
input.isParameterDeref(0) and
87-
output.isQualifierObject()
88-
}
89-
}
90-
9175
/**
9276
* The standard set `merge` function.
9377
*/

cpp/ql/src/semmle/code/cpp/models/implementations/StdString.qll

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -252,25 +252,6 @@ private class StdStringSubstr extends TaintFunction {
252252
}
253253
}
254254

255-
/**
256-
* The standard functions `std::string.swap` and `std::stringstream::swap`.
257-
*/
258-
private class StdStringSwap extends TaintFunction {
259-
StdStringSwap() {
260-
this.hasQualifiedName("std", "basic_string", "swap") or
261-
this.hasQualifiedName("std", "basic_stringstream", "swap")
262-
}
263-
264-
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
265-
// str1.swap(str2)
266-
input.isQualifierObject() and
267-
output.isParameterDeref(0)
268-
or
269-
input.isParameterDeref(0) and
270-
output.isQualifierObject()
271-
}
272-
}
273-
274255
/**
275256
* The `std::string` functions `at` and `operator[]`.
276257
*/

cpp/ql/src/semmle/code/cpp/models/implementations/Swap.qll

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,88 @@ private class Swap extends DataFlowFunction {
1515
output.isParameterDeref(0)
1616
}
1717
}
18+
19+
/**
20+
* The standard functions `std::string.swap` and `std::stringstream::swap`.
21+
*/
22+
private class StdStringSwap extends TaintFunction {
23+
StdStringSwap() {
24+
this.hasQualifiedName("std", "basic_string", "swap") or
25+
this.hasQualifiedName("std", "basic_stringstream", "swap")
26+
}
27+
28+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
29+
// str1.swap(str2)
30+
input.isQualifierObject() and
31+
output.isParameterDeref(0)
32+
or
33+
input.isParameterDeref(0) and
34+
output.isQualifierObject()
35+
}
36+
}
37+
38+
/**
39+
* The standard container `swap` functions.
40+
*/
41+
private class StdSequenceContainerSwap extends TaintFunction {
42+
StdSequenceContainerSwap() {
43+
this.hasQualifiedName("std", ["array", "vector", "deque", "list", "forward_list"], "swap")
44+
}
45+
46+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
47+
// container1.swap(container2)
48+
input.isQualifierObject() and
49+
output.isParameterDeref(0)
50+
or
51+
input.isParameterDeref(0) and
52+
output.isQualifierObject()
53+
}
54+
}
55+
56+
/**
57+
* The standard set `swap` functions.
58+
*/
59+
private class StdSetSwap extends TaintFunction {
60+
StdSetSwap() { this.hasQualifiedName("std", ["set", "unordered_set"], "swap") }
61+
62+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
63+
// container1.swap(container2)
64+
input.isQualifierObject() and
65+
output.isParameterDeref(0)
66+
or
67+
input.isParameterDeref(0) and
68+
output.isQualifierObject()
69+
}
70+
}
71+
72+
/**
73+
* The standard pair `swap` function.
74+
*/
75+
private class StdPairSwap extends TaintFunction {
76+
StdPairSwap() { this.hasQualifiedName("std", "pair", "swap") }
77+
78+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
79+
// container1.swap(container2)
80+
input.isQualifierObject() and
81+
output.isParameterDeref(0)
82+
or
83+
input.isParameterDeref(0) and
84+
output.isQualifierObject()
85+
}
86+
}
87+
88+
/**
89+
* The standard map `swap` function.
90+
*/
91+
private class StdMapSwap extends TaintFunction {
92+
StdMapSwap() { this.hasQualifiedName("std", ["map", "unordered_map"], "swap") }
93+
94+
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
95+
// container1.swap(container2)
96+
input.isQualifierObject() and
97+
output.isParameterDeref(0)
98+
or
99+
input.isParameterDeref(0) and
100+
output.isQualifierObject()
101+
}
102+
}

0 commit comments

Comments
 (0)