-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Provides the `restrictAlertsTo` extensible predicate to restrict alerts to specific source | ||
* locations, and the `AlertFilteringImpl` parameterized module to apply the filtering. | ||
*/ | ||
|
||
private import codeql.util.Location | ||
|
||
/** | ||
* Restricts alerts to a specific location in specific files. | ||
* | ||
* If this predicate is empty, accept all alerts. Otherwise, accept alerts only at the specified | ||
* locations. Note that alert restrictions apply only to the start line of an alert (even if the | ||
* alert location spans multiple lines) because alerts are displayed on their start lines. | ||
* | ||
* - filePath: Absolute path of the file to restrict alerts to. | ||
* - startLine: Start line number (starting with 1, inclusive) to restrict alerts to. | ||
* - endLine: End line number (starting with 1, inclusive) to restrict alerts to. | ||
* | ||
* If startLine and endLine are both 0, accept alerts anywhere in the file. | ||
*/ | ||
extensible predicate restrictAlertsTo(string filePath, int startLine, int endLine); | ||
|
||
/** Module for applying alert location filtering. */ | ||
module AlertFilteringImpl<LocationSig Location> { | ||
/** Applies alert filtering to the given location. */ | ||
bindingset[location] | ||
predicate filterByLocation(Location location) { | ||
not exists( | restrictAlertsTo(_, _, _)) | ||
or | ||
exists(string filePath, int startLine, int endLine | | ||
restrictAlertsTo(filePath, startLine, endLine) and | ||
( | ||
startLine = 0 and | ||
endLine = 0 and | ||
location.hasLocationInfo(filePath, _, _, _, _) | ||
or | ||
// Expand short ranges to join with the start line of the location | ||
startLine <= endLine and | ||
endLine - startLine <= 1000 and | ||
location.hasLocationInfo(filePath, [startLine .. endLine], _, _, _) | ||
or | ||
// For long ranges, over-approximate with matching the entire file | ||
endLine - startLine > 1000 and | ||
location.hasLocationInfo(filePath, _, _, _, _) | ||
) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
extensions: | ||
|
||
- addsTo: | ||
pack: codeql/util | ||
extensible: restrictAlertsTo | ||
# Empty predicate means no restrictions on alert locations | ||
data: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters