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

Skip to content

Commit c32e54e

Browse files
authored
Merge pull request #5176 from criemen/bsl-smartptr
BSL support for smart pointers and other std classes.
2 parents 173b16a + 552f0a7 commit c32e54e

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import semmle.code.cpp.models.interfaces.Taint
44
* The `std::shared_ptr` and `std::unique_ptr` template classes.
55
*/
66
private class UniqueOrSharedPtr extends Class {
7-
UniqueOrSharedPtr() { this.hasQualifiedName("std", ["shared_ptr", "unique_ptr"]) }
7+
UniqueOrSharedPtr() { this.hasQualifiedName(["std", "bsl"], ["shared_ptr", "unique_ptr"]) }
88
}
99

1010
/**
1111
* The `std::make_shared` and `std::make_unique` template functions.
1212
*/
1313
private class MakeUniqueOrShared extends TaintFunction {
14-
MakeUniqueOrShared() { this.hasQualifiedName("std", ["make_shared", "make_unique"]) }
14+
MakeUniqueOrShared() { this.hasQualifiedName(["bsl", "std"], ["make_shared", "make_unique"]) }
1515

1616
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
1717
// Exclude the specializations of `std::make_shared` and `std::make_unique` that allocate arrays

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
import semmle.code.cpp.models.interfaces.Taint
66
import semmle.code.cpp.models.interfaces.Iterator
77

8+
/**
9+
* The `std::map` and `std::unordered_map` template classes.
10+
*/
11+
private class MapOrUnorderedMap extends Class {
12+
MapOrUnorderedMap() { this.hasQualifiedName(["std", "bsl"], ["map", "unordered_map"]) }
13+
}
14+
815
/**
916
* Additional model for map constructors using iterator inputs.
1017
*/
1118
private class StdMapConstructor extends Constructor, TaintFunction {
12-
StdMapConstructor() {
13-
this.hasQualifiedName("std", "map", "map") or
14-
this.hasQualifiedName("std", "unordered_map", "unordered_map")
15-
}
19+
StdMapConstructor() { this.getDeclaringType() instanceof MapOrUnorderedMap }
1620

1721
/**
1822
* Gets the index of a parameter to this function that is an iterator.
@@ -37,7 +41,7 @@ private class StdMapConstructor extends Constructor, TaintFunction {
3741
*/
3842
private class StdMapInsert extends TaintFunction {
3943
StdMapInsert() {
40-
this.hasQualifiedName("std", ["map", "unordered_map"], ["insert", "insert_or_assign"])
44+
this.getClassAndName(["insert", "insert_or_assign"]) instanceof MapOrUnorderedMap
4145
}
4246

4347
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
@@ -55,9 +59,7 @@ private class StdMapInsert extends TaintFunction {
5559
* The standard map `emplace` and `emplace_hint` functions.
5660
*/
5761
private class StdMapEmplace extends TaintFunction {
58-
StdMapEmplace() {
59-
this.hasQualifiedName("std", ["map", "unordered_map"], ["emplace", "emplace_hint"])
60-
}
62+
StdMapEmplace() { this.getClassAndName(["emplace", "emplace_hint"]) instanceof MapOrUnorderedMap }
6163

6264
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
6365
// flow from the last parameter (which may be the value part used to
@@ -79,7 +81,7 @@ private class StdMapEmplace extends TaintFunction {
7981
* The standard map `try_emplace` function.
8082
*/
8183
private class StdMapTryEmplace extends TaintFunction {
82-
StdMapTryEmplace() { this.hasQualifiedName("std", ["map", "unordered_map"], "try_emplace") }
84+
StdMapTryEmplace() { this.getClassAndName("try_emplace") instanceof MapOrUnorderedMap }
8385

8486
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
8587
// flow from any parameter apart from the key to qualifier and return value
@@ -106,7 +108,7 @@ private class StdMapTryEmplace extends TaintFunction {
106108
* The standard map `merge` function.
107109
*/
108110
private class StdMapMerge extends TaintFunction {
109-
StdMapMerge() { this.hasQualifiedName("std", ["map", "unordered_map"], "merge") }
111+
StdMapMerge() { this.getClassAndName("merge") instanceof MapOrUnorderedMap }
110112

111113
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
112114
// container1.merge(container2)
@@ -119,7 +121,7 @@ private class StdMapMerge extends TaintFunction {
119121
* The standard map functions `at` and `operator[]`.
120122
*/
121123
private class StdMapAt extends TaintFunction {
122-
StdMapAt() { this.hasQualifiedName("std", ["map", "unordered_map"], ["at", "operator[]"]) }
124+
StdMapAt() { this.getClassAndName(["at", "operator[]"]) instanceof MapOrUnorderedMap }
123125

124126
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
125127
// flow from qualifier to referenced return value
@@ -136,7 +138,7 @@ private class StdMapAt extends TaintFunction {
136138
* The standard map `find` function.
137139
*/
138140
private class StdMapFind extends TaintFunction {
139-
StdMapFind() { this.hasQualifiedName("std", ["map", "unordered_map"], "find") }
141+
StdMapFind() { this.getClassAndName("find") instanceof MapOrUnorderedMap }
140142

141143
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
142144
input.isQualifierObject() and
@@ -148,7 +150,7 @@ private class StdMapFind extends TaintFunction {
148150
* The standard map `erase` function.
149151
*/
150152
private class StdMapErase extends TaintFunction {
151-
StdMapErase() { this.hasQualifiedName("std", ["map", "unordered_map"], "erase") }
153+
StdMapErase() { this.getClassAndName("erase") instanceof MapOrUnorderedMap }
152154

153155
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
154156
// flow from qualifier to iterator return value
@@ -163,8 +165,7 @@ private class StdMapErase extends TaintFunction {
163165
*/
164166
private class StdMapEqualRange extends TaintFunction {
165167
StdMapEqualRange() {
166-
this.hasQualifiedName("std", ["map", "unordered_map"],
167-
["lower_bound", "upper_bound", "equal_range"])
168+
this.getClassAndName(["lower_bound", "upper_bound", "equal_range"]) instanceof MapOrUnorderedMap
168169
}
169170

170171
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {

0 commit comments

Comments
 (0)