Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4d2f658

Browse files
author
Dave Bartolomeo
committed
Don't treat allocator argument as a string input
1 parent 1e96404 commit 4d2f658

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

cpp/ql/src/semmle/code/cpp/models/implementations/StdString.qll

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,19 @@ class StdStringConstructor extends Constructor, TaintFunction {
3030
* character).
3131
*/
3232
int getAStringParameterIndex() {
33-
getParameter(result).getType() instanceof PointerType or // e.g. `std::basic_string::CharT *`
34-
getParameter(result).getType() instanceof ReferenceType or // e.g. `std::basic_string &`
35-
getParameter(result).getUnspecifiedType() =
36-
getDeclaringType().getTemplateArgument(0).(Type).getUnspecifiedType() // i.e. `std::basic_string::CharT`
33+
exists(Type paramType | paramType = getParameter(result).getUnspecifiedType() |
34+
// e.g. `std::basic_string::CharT *`
35+
paramType instanceof PointerType
36+
or
37+
// e.g. `std::basic_string &`, avoiding `const Allocator&`
38+
paramType instanceof ReferenceType and
39+
not paramType.(ReferenceType).getBaseType() =
40+
getDeclaringType().getTemplateArgument(2).(Type).getUnspecifiedType()
41+
or
42+
// i.e. `std::basic_string::CharT`
43+
getParameter(result).getUnspecifiedType() =
44+
getDeclaringType().getTemplateArgument(0).(Type).getUnspecifiedType()
45+
)
3746
}
3847

3948
/**

0 commit comments

Comments
 (0)