-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUndefinedBehavior.qll
More file actions
33 lines (29 loc) · 1.05 KB
/
UndefinedBehavior.qll
File metadata and controls
33 lines (29 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import cpp
import codingstandards.cpp.UndefinedBehavior
/**
* Library for modeling undefined behavior.
*/
abstract class CUndefinedBehavior extends UndefinedBehavior { }
class C99MainFunction extends Function {
C99MainFunction() {
this.getNumberOfParameters() = 2 and
this.getType() instanceof IntType and
this.getParameter(0).getType() instanceof IntType and
this.getParameter(1).getType().(PointerType).getBaseType().(PointerType).getBaseType()
instanceof CharType
or
this.getNumberOfParameters() = 0 and
this.getType() instanceof VoidType
}
}
class CUndefinedMainDefinition extends CUndefinedBehavior, Function {
CUndefinedMainDefinition() {
// for testing purposes, we use the prefix ____codeql_coding_standards`
(this.getName() = "main" or this.getName().indexOf("____codeql_coding_standards") = 0) and
not this instanceof C99MainFunction
}
override string getReason() {
result =
"The behavior of the program is undefined because the main function is not defined according to the C standard."
}
}