forked from openzfs/zfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CodeQL query to detect redundant assignments
Signed-off-by: Richard Yao <[email protected]>
- Loading branch information
Showing
6 changed files
with
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: "Custom CodeQL Analysis" | ||
|
||
queries: | ||
- uses: ./.github/codeql/custom-queries/cpp/deprecatedFunctionUsage.ql | ||
# - uses: ./.github/codeql/openzfs-code-scanning.qls |
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,4 @@ | ||
name: "Custom CodeQL Analysis" | ||
|
||
paths-ignore: | ||
- tests |
50 changes: 50 additions & 0 deletions
50
.github/codeql/custom-queries/cpp/deprecatedFunctionUsage.ql
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,50 @@ | ||
/** | ||
* @name Deprecated function usage detection | ||
* @description Detects functions whose usage is banned from the OpenZFS | ||
* codebase due to QA concerns. | ||
* @kind problem | ||
* @severity error | ||
* @id cpp/deprecated-function-usage | ||
*/ | ||
|
||
import cpp | ||
|
||
predicate isDeprecatedFunction(Function f) { | ||
f.getName() = "strtok" or | ||
f.getName() = "__xpg_basename" or | ||
f.getName() = "basename" or | ||
f.getName() = "dirname" or | ||
f.getName() = "bcopy" or | ||
f.getName() = "bcmp" or | ||
f.getName() = "bzero" or | ||
f.getName() = "asctime" or | ||
f.getName() = "asctime_r" | ||
} | ||
|
||
string getReplacementMessage(Function f) { | ||
if f.getName() = "strtok" then | ||
result = "strtok_r(3)" | ||
else if f.getName() = "__xpg_basename" then | ||
result = "zfs_basename()" | ||
else if f.getName() = "basename" then | ||
result = "zfs_basename()" | ||
else if f.getName() = "dirname" then | ||
result = "zfs_dirnamelen()" | ||
else if f.getName() = "bcopy" then | ||
result = "memcpy(3)/memmove(3)" | ||
else if f.getName() = "bcmp" then | ||
result = "memcmp(3)" | ||
else if f.getName() = "bzero" then | ||
result = "memset(3)" | ||
else if f.getName() = "asctime" then | ||
result = "strftime(3)" | ||
else | ||
result = "strftime(3)" | ||
} | ||
|
||
from FunctionCall fc, Function f | ||
where | ||
fc.getTarget() = f and | ||
isDeprecatedFunction(f) | ||
select fc, "Usage of '" + f.getName() + "' is deprecated, consider using '" + | ||
getReplacementMessage(f) + "' instead." |
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,4 @@ | ||
name: openzfs-cpp-queries | ||
version: 0.0.0 | ||
libraryPathDependencies: codeql-cpp | ||
suites: openzfs-cpp-suite |
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,3 @@ | ||
# Reusing existing QL Pack | ||
- import: codeql-suites/cpp-code-scanning.qls | ||
from: codeql-cpp |
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