-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathEnvironment.qll
More file actions
35 lines (30 loc) · 906 Bytes
/
Environment.qll
File metadata and controls
35 lines (30 loc) · 906 Bytes
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
34
35
/**
* Reading from the environment, for example with 'getenv'.
*/
import cpp
/**
* An expression that reads from an environment variable.
*/
class EnvironmentRead extends Expr {
EnvironmentRead() { readsEnvironment(this, _) }
/**
* The name of the environment variable.
*/
string getEnvironmentVariable() {
// Conveniently, it's always the first argument to the call
this.(Call).getArgument(0).(TextLiteral).getValue() = result
}
/**
* A very short description of the source, suitable for use in
* an error message.
*/
string getSourceDescription() { readsEnvironment(this, result) }
}
private predicate readsEnvironment(Expr read, string sourceDescription) {
exists(FunctionCall call, string name |
read = call and
call.getTarget().hasGlobalOrStdName(name) and
name = ["getenv", "secure_getenv", "_wgetenv"] and
sourceDescription = name
)
}