14
14
15
15
import cpp
16
16
import codingstandards.cpp.misra
17
+ import codingstandards.cpp.BannedFunctions
17
18
18
- predicate isBannedStringFunction ( Function f ) {
19
- f . hasGlobalName ( [
20
- "strcat" , "strchr" , "strcmp" , "strcoll" , "strcpy" , "strcspn" ,
21
- "strerror ", "strlen " , "strncat " , "strncmp " , "strncpy " , "strpbrk " ,
22
- "strrchr ", "strspn " , "strstr " , "strtok " , "strxfrm " ,
23
- "strtol" , "strtoll" , "strtoul" , "strtoull" , "strtod" , "strtof" , "strtold" ,
24
- "fgetwc" , "fputwc" , "wcstol" , "wcstoll" , "wcstoul" , "wcstoull" ,
25
- "wcstod ", "wcstof " , "wcstold" ,
26
- "strtoumax" , "strtoimax" , "wcstoumax" , "wcstoimax"
27
- ] )
19
+ class StringFunction extends Function {
20
+ StringFunction ( ) {
21
+ this . hasGlobalName ( [
22
+ "strcat ", "strchr " , "strcmp " , "strcoll " , "strcpy " , "strcspn" , "strerror" , "strlen ",
23
+ "strncat ", "strncmp " , "strncpy " , "strpbrk " , "strrchr" , "strspn" , "strstr" , "strtok ",
24
+ "strxfrm" , "strtol" , "strtoll" , "strtoul" , "strtoull" , "strtod" , "strtof" , "strtold" ,
25
+ "fgetwc" , "fputwc" , "wcstol" , "wcstoll" , "wcstoul" , "wcstoull" , "wcstod" , "wcstof ",
26
+ "wcstold ", "strtoumax " , "strtoimax" , "wcstoumax" , "wcstoimax"
27
+ ] )
28
+ }
28
29
}
29
30
30
- from Expr e , Function f , string msg
31
- where
32
- not isExcluded ( e , BannedAPIsPackage:: unsafeStringHandlingFunctionsQuery ( ) ) and
33
- (
34
- ( e .( FunctionCall ) .getTarget ( ) = f and isBannedStringFunction ( f ) and
35
- msg = "Call to banned string handling function '" + f .getName ( ) + "'." )
36
- or
37
- ( e .( AddressOfExpr ) .getOperand ( ) .( FunctionAccess ) .getTarget ( ) = f and isBannedStringFunction ( f ) and
38
- msg = "Address taken of banned string handling function '" + f .getName ( ) + "'." )
39
- or
40
- ( e .( FunctionAccess ) .getTarget ( ) = f and isBannedStringFunction ( f ) and
41
- not e .getParent ( ) instanceof FunctionCall and
42
- not e .getParent ( ) instanceof AddressOfExpr and
43
- msg = "Reference to banned string handling function '" + f .getName ( ) + "'." )
44
- )
45
- select e , msg
31
+ from BannedFunctions< StringFunction > :: Use use
32
+ where not isExcluded ( use , BannedAPIsPackage:: unsafeStringHandlingFunctionsQuery ( ) )
33
+ select use , use .getAction ( ) + " banned string handling function '" + use .getFunctionName ( ) + "'."
0 commit comments