@@ -8,15 +8,33 @@ class StdBasicString extends TemplateClass {
8
8
}
9
9
10
10
/**
11
- * The `std::string` functions `c_str` and `data `.
11
+ * The `std::string` function `c_str`.
12
12
*/
13
13
class StdStringCStr extends TaintFunction {
14
- StdStringCStr ( ) { this .hasQualifiedName ( "std" , "basic_string" , [ "c_str" , "data" ] ) }
14
+ StdStringCStr ( ) { this .hasQualifiedName ( "std" , "basic_string" , "c_str" ) }
15
15
16
16
override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
17
17
// flow from string itself (qualifier) to return value
18
18
input .isQualifierObject ( ) and
19
- output .isReturnValue ( )
19
+ output .isReturnValueDeref ( )
20
+ }
21
+ }
22
+
23
+ /**
24
+ * The `std::string` function `data`.
25
+ */
26
+ class StdStringData extends TaintFunction {
27
+ StdStringData ( ) { this .hasQualifiedName ( "std" , "basic_string" , "data" ) }
28
+
29
+ override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
30
+ // flow from string itself (qualifier) to return value
31
+ input .isQualifierObject ( ) and
32
+ output .isReturnValueDeref ( )
33
+ or
34
+ // reverse flow from returned reference to the qualifier (for writes to
35
+ // `data`)
36
+ input .isReturnValueDeref ( ) and
37
+ output .isQualifierObject ( )
20
38
}
21
39
}
22
40
@@ -53,17 +71,18 @@ class StdStringAppend extends TaintFunction {
53
71
* Gets the index of a parameter to this function that is a string (or
54
72
* character).
55
73
*/
56
- int getAStringParameter ( ) {
74
+ int getAStringParameterIndex ( ) {
57
75
getParameter ( result ) .getType ( ) instanceof PointerType or
58
76
getParameter ( result ) .getType ( ) instanceof ReferenceType or
59
- getParameter ( result ) .getType ( ) = getDeclaringType ( ) .getTemplateArgument ( 0 ) // i.e. `std::basic_string::CharT`
77
+ getParameter ( result ) .getUnspecifiedType ( ) =
78
+ getDeclaringType ( ) .getTemplateArgument ( 0 ) .( Type ) .getUnspecifiedType ( ) // i.e. `std::basic_string::CharT`
60
79
}
61
80
62
81
override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
63
82
// flow from string and parameter to string (qualifier) and return value
64
83
(
65
84
input .isQualifierObject ( ) or
66
- input .isParameterDeref ( getAStringParameter ( ) )
85
+ input .isParameterDeref ( getAStringParameterIndex ( ) )
67
86
) and
68
87
(
69
88
output .isQualifierObject ( ) or
@@ -82,15 +101,16 @@ class StdStringAssign extends TaintFunction {
82
101
* Gets the index of a parameter to this function that is a string (or
83
102
* character).
84
103
*/
85
- int getAStringParameter ( ) {
104
+ int getAStringParameterIndex ( ) {
86
105
getParameter ( result ) .getType ( ) instanceof PointerType or
87
106
getParameter ( result ) .getType ( ) instanceof ReferenceType or
88
- getParameter ( result ) .getType ( ) = getDeclaringType ( ) .getTemplateArgument ( 0 ) // i.e. `std::basic_string::CharT`
107
+ getParameter ( result ) .getUnspecifiedType ( ) =
108
+ getDeclaringType ( ) .getTemplateArgument ( 0 ) .( Type ) .getUnspecifiedType ( ) // i.e. `std::basic_string::CharT`
89
109
}
90
110
91
111
override predicate hasTaintFlow ( FunctionInput input , FunctionOutput output ) {
92
112
// flow from parameter to string itself (qualifier) and return value
93
- input .isParameterDeref ( getAStringParameter ( ) ) and
113
+ input .isParameterDeref ( getAStringParameterIndex ( ) ) and
94
114
(
95
115
output .isQualifierObject ( ) or
96
116
output .isReturnValueDeref ( )
0 commit comments