1212 */
1313
1414import cpp
15+ import semmle.code.cpp.models.implementations.Strcpy
1516import semmle.code.cpp.dataflow.DataFlow
1617
17- predicate isStringComparisonFunction ( string functionName ) {
18- functionName = "strcpy" or
19- functionName = "wcscpy" or
20- functionName = "_mbscpy" or
21- functionName = "strncpy" or
22- functionName = "_strncpy_l" or
23- functionName = "wcsncpy" or
24- functionName = "_wcsncpy_l" or
25- functionName = "_mbsncpy" or
26- functionName = "_mbsncpy_l"
27- }
28-
2918predicate isBoolean ( Expr e1 ) {
3019 exists ( Type t1 |
3120 t1 = e1 .getType ( ) and
@@ -36,12 +25,12 @@ predicate isBoolean(Expr e1) {
3625predicate isStringCopyCastedAsBoolean ( FunctionCall func , Expr expr1 , string msg ) {
3726 DataFlow:: localFlow ( DataFlow:: exprNode ( func ) , DataFlow:: exprNode ( expr1 ) ) and
3827 isBoolean ( expr1 .getConversion * ( ) ) and
39- isStringComparisonFunction ( func .getTarget ( ) . getName ( ) ) and
28+ func .getTarget ( ) instanceof StrcpyFunction and
4029 msg = "Return value of " + func .getTarget ( ) .getName ( ) + " used as a Boolean."
4130}
4231
4332predicate isStringCopyUsedInLogicalOperationOrCondition ( FunctionCall func , Expr expr1 , string msg ) {
44- isStringComparisonFunction ( func .getTarget ( ) . getName ( ) ) and
33+ func .getTarget ( ) instanceof StrcpyFunction and
4534 (
4635 (
4736 // it is being used in an equality or logical operation
0 commit comments