forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExternalArtifact.qll
More file actions
131 lines (109 loc) · 3.26 KB
/
ExternalArtifact.qll
File metadata and controls
131 lines (109 loc) · 3.26 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* Provides classes for working with external data.
*/
import semmle.javascript.Locations
/**
* An external data item.
*/
class ExternalData extends @externalDataElement {
/** Gets the path of the file this data was loaded from. */
string getDataPath() {
externalData(this, result, _, _)
}
/**
* Gets the path of the file this data was loaded from, with its
* extension replaced by `.ql`.
*/
string getQueryPath() {
result = getDataPath().regexpReplaceAll("\\.[^.]*$", ".ql")
}
/** Gets the number of fields in this data item. */
int getNumFields() {
result = 1 + max(int i | externalData(this, _, i, _) | i)
}
/** Gets the value of the `i`th field of this data item. */
string getField(int i) {
externalData(this, _, i, result)
}
/** Gets the integer value of the `i`th field of this data item. */
int getFieldAsInt(int i) {
result = getField(i).toInt()
}
/** Gets the floating-point value of the `i`th field of this data item. */
float getFieldAsFloat(int i) {
result = getField(i).toFloat()
}
/** Gets the value of the `i`th field of this data item, interpreted as a date. */
date getFieldAsDate(int i) {
result = getField(i).toDate()
}
/** Gets a textual representation of this data item. */
string toString() {
result = getQueryPath() + ": " + buildTupleString(0)
}
/** Gets a textual representation of this data item, starting with the `n`th field. */
private string buildTupleString(int n) {
(n = getNumFields() - 1 and result = getField(n))
or
(n < getNumFields() - 1 and result = getField(n) + "," + buildTupleString(n+1))
}
}
/**
* An external data item interpreted as an error or warning reported by an external tool.
*/
class ExternalError extends ExternalData {
/** Gets the name of the tool that reported the error. */
string getReporter() {
result = getField(0)
}
/** Gets the absolute path of the file in which the error occurs. */
string getPath() {
result = getField(1)
}
/** Gets the reported line of the error. */
int getLine() {
result = getFieldAsInt(2)
}
/** Gets the reported column of the error. */
int getColumn() {
result = getFieldAsInt(3)
}
/**
* Gets the error type.
*
* This is tool-specific, but usually either "warning" or "error".
*/
string getType() {
result = getField(4)
}
/** Gets the error message. */
string getMessage() {
result = getField(5)
}
/** Gets the file associated with this error. */
File getFile() {
result.getAbsolutePath() = this.getPath()
}
/** Gets the URL associated with this error. */
string getURL() {
exists(string path, int line, int col |
path = this.getPath() and
line = this.getLine() and
col = this.getColumn() and
toUrl(path, line, col, line, col, result)
)
}
}
/**
* An external data item with a location and a message.
*/
class DefectExternalData extends ExternalData {
DefectExternalData() {
this.getField(0).regexpMatch("\\w+://.*:[0-9]+:[0-9]+:[0-9]+:[0-9]+$") and
this.getNumFields() = 2
}
/** Gets the URL associated with this data item. */
string getURL() { result = getField(0) }
/** Gets the message associated with this data item. */
string getMessage() { result = getField(1) }
}