|
1 | 1 | /** |
2 | | - * Provides models for C++ containers such as `std::vector` and `std::list`. |
| 2 | + * Provides models for C++ containers `std::array`, `std::vector`, `std::deque`, `std::list` and `std::forward_list`. |
3 | 3 | */ |
4 | 4 |
|
5 | 5 | import semmle.code.cpp.models.interfaces.Taint |
6 | 6 |
|
7 | 7 | /** |
8 | | - * Model standard container constructors. |
| 8 | + * Additional model for standard container constructors that reference the |
| 9 | + * value type of the container (that is, the `T` in `std::vector<T>`). For |
| 10 | + * example the fill constructor: |
| 11 | + * ``` |
| 12 | + * std::vector<std::string> v(100, potentially_tainted_string); |
| 13 | + * ``` |
9 | 14 | */ |
10 | 15 | class StdContainerConstructor extends Constructor, TaintFunction { |
11 | | - StdContainerConstructor() { this.getDeclaringType().hasQualifiedName("std", "vector") } |
| 16 | + StdContainerConstructor() { |
| 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") |
| 21 | + } |
12 | 22 |
|
13 | 23 | /** |
14 | 24 | * Gets the index of a parameter to this function that is a reference to the |
15 | | - * type of thing contained. |
| 25 | + * value type of the container. |
16 | 26 | */ |
17 | | - int getAnElementParameter() { |
| 27 | + int getAValueTypeParameter() { |
18 | 28 | getParameter(result).getType().getUnspecifiedType().(ReferenceType).getBaseType() = |
19 | 29 | getDeclaringType().getTemplateArgument(0) // i.e. the `T` of this `std::vector<T>` |
20 | 30 | } |
21 | 31 |
|
22 | 32 | override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) { |
23 | | - // taint flow from any parameter of type `T` to the returned object |
24 | | - input.isParameterDeref(getAnElementParameter()) and |
| 33 | + // taint flow from any parameter of the value type to the returned object |
| 34 | + input.isParameterDeref(getAValueTypeParameter()) and |
25 | 35 | output.isReturnValue() // TODO: this should be `isQualifierObject` by our current definitions, but that flow is not yet supported. |
26 | 36 | } |
27 | 37 | } |
|
0 commit comments