@@ -14,10 +14,7 @@ import semmle.code.cpp.models.interfaces.Taint
1414 */
1515class StdSequenceContainerConstructor extends Constructor , TaintFunction {
1616 StdSequenceContainerConstructor ( ) {
17- this .getDeclaringType ( ) .hasQualifiedName ( "std" , "vector" ) or
18- this .getDeclaringType ( ) .hasQualifiedName ( "std" , "deque" ) or
19- this .getDeclaringType ( ) .hasQualifiedName ( "std" , "list" ) or
20- this .getDeclaringType ( ) .hasQualifiedName ( "std" , "forward_list" )
17+ this .getDeclaringType ( ) .hasQualifiedName ( "std" , [ "vector" , "deque" , "list" , "forward_list" ] )
2118 }
2219
2320 /**
@@ -26,7 +23,7 @@ class StdSequenceContainerConstructor extends Constructor, TaintFunction {
2623 */
2724 int getAValueTypeParameterIndex ( ) {
2825 getParameter ( result ) .getUnspecifiedType ( ) .( ReferenceType ) .getBaseType ( ) =
29- getDeclaringType ( ) .getTemplateArgument ( 0 ) // i.e. the `T` of this `std::vector<T>`
26+ getDeclaringType ( ) .getTemplateArgument ( 0 ) . ( Type ) . getUnspecifiedType ( ) // i.e. the `T` of this `std::vector<T>`
3027 }
3128
3229 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
@@ -36,16 +33,32 @@ class StdSequenceContainerConstructor extends Constructor, TaintFunction {
3633 }
3734}
3835
36+ /**
37+ * The standard container function `data`.
38+ */
39+ class StdSequenceContainerData extends TaintFunction {
40+ StdSequenceContainerData ( ) { this .hasQualifiedName ( "std" , [ "array" , "vector" ] , "data" ) }
41+
42+ override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
43+ // flow from container itself (qualifier) to return value
44+ input .isQualifierObject ( ) and
45+ output .isReturnValueDeref ( )
46+ or
47+ // reverse flow from returned reference to the qualifier (for writes to
48+ // `data`)
49+ input .isReturnValueDeref ( ) and
50+ output .isQualifierObject ( )
51+ }
52+ }
53+
3954/**
4055 * The standard container functions `push_back` and `push_front`.
4156 */
4257class StdSequenceContainerPush extends TaintFunction {
4358 StdSequenceContainerPush ( ) {
4459 this .hasQualifiedName ( "std" , "vector" , "push_back" ) or
45- this .hasQualifiedName ( "std" , "deque" , "push_back" ) or
46- this .hasQualifiedName ( "std" , "deque" , "push_front" ) or
47- this .hasQualifiedName ( "std" , "list" , "push_back" ) or
48- this .hasQualifiedName ( "std" , "list" , "push_front" ) or
60+ this .hasQualifiedName ( "std" , "deque" , [ "push_back" , "push_front" ] ) or
61+ this .hasQualifiedName ( "std" , "list" , [ "push_back" , "push_front" ] ) or
4962 this .hasQualifiedName ( "std" , "forward_list" , "push_front" )
5063 }
5164
@@ -61,14 +74,10 @@ class StdSequenceContainerPush extends TaintFunction {
6174 */
6275class StdSequenceContainerFrontBack extends TaintFunction {
6376 StdSequenceContainerFrontBack ( ) {
64- this .hasQualifiedName ( "std" , "array" , "front" ) or
65- this .hasQualifiedName ( "std" , "array" , "back" ) or
66- this .hasQualifiedName ( "std" , "vector" , "front" ) or
67- this .hasQualifiedName ( "std" , "vector" , "back" ) or
68- this .hasQualifiedName ( "std" , "deque" , "front" ) or
69- this .hasQualifiedName ( "std" , "deque" , "back" ) or
70- this .hasQualifiedName ( "std" , "list" , "front" ) or
71- this .hasQualifiedName ( "std" , "list" , "back" ) or
77+ this .hasQualifiedName ( "std" , "array" , [ "front" , "back" ] ) or
78+ this .hasQualifiedName ( "std" , "vector" , [ "front" , "back" ] ) or
79+ this .hasQualifiedName ( "std" , "deque" , [ "front" , "back" ] ) or
80+ this .hasQualifiedName ( "std" , "list" , [ "front" , "back" ] ) or
7281 this .hasQualifiedName ( "std" , "forward_list" , "front" )
7382 }
7483
@@ -79,16 +88,36 @@ class StdSequenceContainerFrontBack extends TaintFunction {
7988 }
8089}
8190
91+ /**
92+ * The standard container function `assign`.
93+ */
94+ class StdSequenceContainerAssign extends TaintFunction {
95+ StdSequenceContainerAssign ( ) {
96+ this .hasQualifiedName ( "std" , [ "vector" , "deque" , "list" , "forward_list" ] , "assign" )
97+ }
98+
99+ /**
100+ * Gets the index of a parameter to this function that is a reference to the
101+ * value type of the container.
102+ */
103+ int getAValueTypeParameterIndex ( ) {
104+ getParameter ( result ) .getUnspecifiedType ( ) .( ReferenceType ) .getBaseType ( ) =
105+ getDeclaringType ( ) .getTemplateArgument ( 0 ) .( Type ) .getUnspecifiedType ( ) // i.e. the `T` of this `std::vector<T>`
106+ }
107+
108+ override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
109+ // flow from parameter to string itself (qualifier) and return value
110+ input .isParameterDeref ( getAValueTypeParameterIndex ( ) ) and
111+ output .isQualifierObject ( )
112+ }
113+ }
114+
82115/**
83116 * The standard container `swap` functions.
84117 */
85118class StdSequenceContainerSwap extends TaintFunction {
86119 StdSequenceContainerSwap ( ) {
87- this .hasQualifiedName ( "std" , "array" , "swap" ) or
88- this .hasQualifiedName ( "std" , "vector" , "swap" ) or
89- this .hasQualifiedName ( "std" , "deque" , "swap" ) or
90- this .hasQualifiedName ( "std" , "list" , "swap" ) or
91- this .hasQualifiedName ( "std" , "forward_list" , "swap" )
120+ this .hasQualifiedName ( "std" , [ "array" , "vector" , "deque" , "list" , "forward_list" ] , "swap" )
92121 }
93122
94123 override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
@@ -100,3 +129,22 @@ class StdSequenceContainerSwap extends TaintFunction {
100129 output .isQualifierObject ( )
101130 }
102131}
132+
133+ /**
134+ * The standard container functions `at` and `operator[]`.
135+ */
136+ class StdSequenceContainerAt extends TaintFunction {
137+ StdSequenceContainerAt ( ) {
138+ this .hasQualifiedName ( "std" , [ "vector" , "array" , "deque" ] , [ "at" , "operator[]" ] )
139+ }
140+
141+ override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
142+ // flow from qualifier to referenced return value
143+ input .isQualifierObject ( ) and
144+ output .isReturnValueDeref ( )
145+ or
146+ // reverse flow from returned reference to the qualifier
147+ input .isReturnValueDeref ( ) and
148+ output .isQualifierObject ( )
149+ }
150+ }
0 commit comments