55import semmle.code.cpp.models.interfaces.Taint
66import 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 */
1118private 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 */
3842private 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 */
5761private 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 */
8183private 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 */
108110private 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 */
121123private 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 */
138140private 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 */
150152private 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 */
164166private 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