55import semmle.code.cpp.models.interfaces.Taint
66import semmle.code.cpp.models.interfaces.Iterator
77
8+ /**
9+ * An instantiation of `std::set` or `std::unordered_set`.
10+ */
11+ private class StdSet extends ClassTemplateInstantiation {
12+ StdSet ( ) { this .hasQualifiedName ( [ "std" , "bsl" ] , [ "set" , "unordered_set" ] ) }
13+ }
14+
815/**
916 * Additional model for set constructors using iterator inputs.
1017 */
1118private class StdSetConstructor extends Constructor , TaintFunction {
12- StdSetConstructor ( ) {
13- this .hasQualifiedName ( "std" , "set" , "set" ) or
14- this .hasQualifiedName ( "std" , "unordered_set" , "unordered_set" )
15- }
19+ StdSetConstructor ( ) { this .getDeclaringType ( ) instanceof StdSet }
1620
1721 /**
1822 * Gets the index of a parameter to this function that is an iterator.
@@ -36,7 +40,7 @@ private class StdSetConstructor extends Constructor, TaintFunction {
3640 * The standard set `insert` and `insert_or_assign` functions.
3741 */
3842private class StdSetInsert extends TaintFunction {
39- StdSetInsert ( ) { this .hasQualifiedName ( "std" , [ "set" , "unordered_set" ] , " insert") }
43+ StdSetInsert ( ) { this .getClassAndName ( " insert") instanceof StdSet }
4044
4145 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
4246 // flow from last parameter to qualifier and return value
@@ -53,9 +57,7 @@ private class StdSetInsert extends TaintFunction {
5357 * The standard set `emplace` and `emplace_hint` functions.
5458 */
5559private class StdSetEmplace extends TaintFunction {
56- StdSetEmplace ( ) {
57- this .hasQualifiedName ( "std" , [ "set" , "unordered_set" ] , [ "emplace" , "emplace_hint" ] )
58- }
60+ StdSetEmplace ( ) { this .getClassAndName ( [ "emplace" , "emplace_hint" ] ) instanceof StdSet }
5961
6062 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
6163 // flow from any parameter to qualifier and return value
@@ -76,7 +78,7 @@ private class StdSetEmplace extends TaintFunction {
7678 * The standard set `merge` function.
7779 */
7880private class StdSetMerge extends TaintFunction {
79- StdSetMerge ( ) { this .hasQualifiedName ( "std" , [ "set" , "unordered_set" ] , " merge") }
81+ StdSetMerge ( ) { this .getClassAndName ( " merge") instanceof StdSet }
8082
8183 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
8284 // container1.merge(container2)
@@ -89,7 +91,7 @@ private class StdSetMerge extends TaintFunction {
8991 * The standard set `find` function.
9092 */
9193private class StdSetFind extends TaintFunction {
92- StdSetFind ( ) { this .hasQualifiedName ( "std" , [ "set" , "unordered_set" ] , " find") }
94+ StdSetFind ( ) { this .getClassAndName ( " find") instanceof StdSet }
9395
9496 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
9597 input .isQualifierObject ( ) and
@@ -101,7 +103,7 @@ private class StdSetFind extends TaintFunction {
101103 * The standard set `erase` function.
102104 */
103105private class StdSetErase extends TaintFunction {
104- StdSetErase ( ) { this .hasQualifiedName ( "std" , [ "set" , "unordered_set" ] , " erase") }
106+ StdSetErase ( ) { this .getClassAndName ( " erase") instanceof StdSet }
105107
106108 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
107109 // flow from qualifier to iterator return value
@@ -116,8 +118,7 @@ private class StdSetErase extends TaintFunction {
116118 */
117119private class StdSetEqualRange extends TaintFunction {
118120 StdSetEqualRange ( ) {
119- this .hasQualifiedName ( "std" , [ "set" , "unordered_set" ] ,
120- [ "lower_bound" , "upper_bound" , "equal_range" ] )
121+ this .getClassAndName ( [ "lower_bound" , "upper_bound" , "equal_range" ] ) instanceof StdSet
121122 }
122123
123124 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
0 commit comments