-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix sequnce number compare and add codeql query for this
- Loading branch information
1 parent
eef2f7e
commit e0e325a
Showing
2 changed files
with
38 additions
and
1 deletion.
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,37 @@ | ||
/** | ||
* Finds relational comparisons of sequence numbers that are not using the fd_seq_* functions | ||
* @id asymmetric-research/seq-cmp | ||
* @kind problem | ||
* @severity warning | ||
* @precision low | ||
*/ | ||
|
||
import cpp | ||
|
||
predicate include(Location l) { | ||
l.getFile().getRelativePath().matches("src/") | ||
or not l.getFile().getBaseName().matches("fd_cstr%") | ||
} | ||
|
||
class SeqNum extends Variable { | ||
SeqNum() { | ||
this.getName().matches("%seq%") and | ||
include(this.getLocation()) | ||
} | ||
} | ||
|
||
from SeqNum seqNum1, SeqNum seqNum2, Access a, Access b | ||
where exists( | ||
/* Using == and != is fine because they match the implementation of | ||
fd_seq_eq and fd_seq_ne */ | ||
RelationalOperation cmp | | ||
cmp.getAnOperand() = a and | ||
cmp.getAnOperand() = b | ||
) and | ||
a = seqNum1.getAnAccess() and | ||
b = seqNum2.getAnAccess() and | ||
a != b and | ||
include(a.getLocation()) and | ||
include(b.getLocation()) and | ||
a.getTarget().getName() < b.getTarget().getName() /* Avoid duplicate results */ | ||
select a, "Use fd_seq_lt, fd_seq_le, fd_seq_ge, fd_seq_gt or equivlanet implementations to compare sequence numbers" |
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