@@ -15,33 +15,22 @@ import codingstandards.c.misra
15
15
import codingstandards.cpp.ReadErrorsAndEOF
16
16
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
17
17
18
- //import semmle.code.cpp.rangeanalysis.RangeAnalysisUtils
19
18
class CtypeFunction extends Function {
20
19
CtypeFunction ( ) { this .getADeclaration ( ) .getAFile ( ) .( HeaderFile ) .getBaseName ( ) = "ctype.h" }
21
20
}
22
21
23
- /* TODO Under construction */
24
22
from FunctionCall ctypeCall
25
23
where
26
24
not isExcluded ( ctypeCall ,
27
- StandardLibraryFunctionTypesPackage:: ctypeFunctionArgNotUnsignedCharOrEofQuery ( ) )
28
- // and
29
- // not exists(CtypeFunction ctype, Expr ctypeCallArgument |
30
- // ctype = ctypeCall.getTarget() and
31
- // ctypeCallArgument = ctypeCall.getAnArgument().getExplicitlyConverted()
32
- // |
33
- // /* Case 1: The argument's value should be in the `unsigned char` range. */
34
- // // Use `.getExplicitlyConverted` to consider inline argument casts.
35
- // -1 <= lowerBound(ctypeCallArgument) and
36
- // upperBound(ctypeCallArgument) <= 255
37
- // or
38
- // /* Case 2: EOF flows to this argument without modifications. */
39
- // exists(EOFInvocation eof |
40
- // DataFlow::localFlow(DataFlow::exprNode(eof.getExpr()), DataFlow::exprNode(ctypeCallArgument))
41
- // )
42
- // )
43
- select ctypeCall .getAnArgument ( ) , lowerBound ( ctypeCall .getAnArgument ( ) ) ,
44
- upperBound ( ctypeCall .getAnArgument ( ) )
45
- // select ctypeCall,
46
- // "The <ctype.h> function " + ctypeCall + " accepts an argument " +
47
- // ctypeCall.getAnArgument().toString() + " that is not an unsigned char nor an EOF."
25
+ StandardLibraryFunctionTypesPackage:: ctypeFunctionArgNotUnsignedCharOrEofQuery ( ) ) and
26
+ not exists ( CtypeFunction ctype , Expr ctypeCallArgument |
27
+ ctype = ctypeCall .getTarget ( ) and
28
+ ctypeCallArgument = ctypeCall .getAnArgument ( ) .getExplicitlyConverted ( )
29
+ |
30
+ /* The argument's value should be in the EOF + `unsigned char` range. */
31
+ - 1 <= lowerBound ( ctypeCallArgument ) and upperBound ( ctypeCallArgument ) <= 255
32
+ ) and
33
+ ctypeCall .getBasicBlock ( ) .isReachable ( )
34
+ select ctypeCall ,
35
+ "The <ctype.h> function " + ctypeCall + " accepts an argument " +
36
+ ctypeCall .getAnArgument ( ) .toString ( ) + " that is not an unsigned char nor an EOF."
0 commit comments