forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigFiles.qll
More file actions
72 lines (58 loc) · 2.41 KB
/
ConfigFiles.qll
File metadata and controls
72 lines (58 loc) · 2.41 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Provides classes and predicates for working with configuration files, such
* as Java `.properties` or `.ini` files.
*/
import semmle.code.Location
/** An element in a configuration file has a location. */
abstract class ConfigLocatable extends @configLocatable {
/** Gets the source location for this element. */
Location getLocation() { configLocations(this, result) }
/** Gets the file associated with this element. */
File getFile() { result = getLocation().getFile() }
/** Gets a textual representation of this element. */
abstract string toString();
}
/**
* A name-value pair often used to store configuration properties
* for applications, such as the port, name or address of a database.
*/
class ConfigPair extends @config, ConfigLocatable {
/** Gets the name of this `ConfigPair`, if any. */
ConfigName getNameElement() { configNames(result, this, _) }
/** Gets the value of this `ConfigPair`, if any. */
ConfigValue getValueElement() { configValues(result, this, _) }
/**
* Gets the string value of the name of this `ConfigPair` if
* it exists and the empty string if it doesn't.
*/
string getEffectiveName() {
if exists(getNameElement()) then result = getNameElement().getName() else result = ""
}
/**
* Gets the string value of the value of this `ConfigPair` if
* it exists and the empty string if it doesn't.
*/
string getEffectiveValue() {
if exists(getValueElement()) then result = getValueElement().getValue() else result = ""
}
/** Gets a printable representation of this `ConfigPair`. */
override string toString() { result = getEffectiveName() + "=" + getEffectiveValue() }
}
/** The name element of a `ConfigPair`. */
class ConfigName extends @configName, ConfigLocatable {
/** Gets the name as a string. */
string getName() { configNames(this, _, result) }
/** Gets a printable representation of this `ConfigName`. */
override string toString() { result = getName() }
}
/** The value element of a `ConfigPair`. */
class ConfigValue extends @configValue, ConfigLocatable {
/** Gets the value as a string. */
string getValue() { configValues(this, _, result) }
/** Gets a printable representation of this `ConfigValue`. */
override string toString() { result = getValue() }
}
/** A Java property is a name-value pair in a `.properties` file. */
class JavaProperty extends ConfigPair {
JavaProperty() { getFile().getExtension() = "properties" }
}