mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
Merge pull request #6884 from geoffw0/setliterals
Replace or chains with set literals.
This commit is contained in:
@@ -58,15 +58,7 @@ predicate intTrivial(Literal lit) { exists(string v | trivialIntValue(v) and v =
|
||||
predicate longTrivial(Literal lit) { exists(string v | trivialLongValue(v) and v = lit.getValue()) }
|
||||
|
||||
predicate powerOfTen(float f) {
|
||||
f = 10 or
|
||||
f = 100 or
|
||||
f = 1000 or
|
||||
f = 10000 or
|
||||
f = 100000 or
|
||||
f = 1000000 or
|
||||
f = 10000000 or
|
||||
f = 100000000 or
|
||||
f = 1000000000
|
||||
f = [10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]
|
||||
}
|
||||
|
||||
predicate floatTrivial(Literal lit) {
|
||||
|
||||
@@ -13,14 +13,15 @@
|
||||
import cpp
|
||||
|
||||
predicate commonErrorCode(string value) {
|
||||
value = "0" or
|
||||
value = "1" or
|
||||
value = "-1" or
|
||||
value = "18446744073709551615" or // 2^64-1, i.e. -1 as an unsigned int64
|
||||
value = "4294967295" or // 2^32-1, i.e. -1 as an unsigned int32
|
||||
value = "3735928559" or // 0xdeadbeef
|
||||
value = "3735929054" or // 0xdeadc0de
|
||||
value = "3405691582" // 0xcafebabe
|
||||
value =
|
||||
[
|
||||
"0", "1", "-1", // common error codes
|
||||
"18446744073709551615", // 2^64-1, i.e. -1 as an unsigned int64
|
||||
"4294967295", // 2^32-1, i.e. -1 as an unsigned int32
|
||||
"3735928559", // 0xdeadbeef
|
||||
"3735929054", // 0xdeadc0de
|
||||
"3405691582" // 0xcafebabe
|
||||
]
|
||||
}
|
||||
|
||||
from Expr e
|
||||
|
||||
@@ -43,23 +43,25 @@ predicate isSizePlus(Expr e, BufferSizeExpr baseSize, int plus) {
|
||||
|
||||
predicate strncpyFunction(Function f, int argDest, int argSrc, int argLimit) {
|
||||
exists(string name | name = f.getName() |
|
||||
(
|
||||
name = "strcpy_s" or // strcpy_s(dst, max_amount, src)
|
||||
name = "wcscpy_s" or // wcscpy_s(dst, max_amount, src)
|
||||
name = "_mbscpy_s" // _mbscpy_s(dst, max_amount, src)
|
||||
) and
|
||||
name =
|
||||
[
|
||||
"strcpy_s", // strcpy_s(dst, max_amount, src)
|
||||
"wcscpy_s", // wcscpy_s(dst, max_amount, src)
|
||||
"_mbscpy_s" // _mbscpy_s(dst, max_amount, src)
|
||||
] and
|
||||
argDest = 0 and
|
||||
argSrc = 2 and
|
||||
argLimit = 1
|
||||
or
|
||||
(
|
||||
name = "strncpy" or // strncpy(dst, src, max_amount)
|
||||
name = "strncpy_l" or // strncpy_l(dst, src, max_amount, locale)
|
||||
name = "wcsncpy" or // wcsncpy(dst, src, max_amount)
|
||||
name = "_wcsncpy_l" or // _wcsncpy_l(dst, src, max_amount, locale)
|
||||
name = "_mbsncpy" or // _mbsncpy(dst, src, max_amount)
|
||||
name = "_mbsncpy_l" // _mbsncpy_l(dst, src, max_amount, locale)
|
||||
) and
|
||||
name =
|
||||
[
|
||||
"strncpy", // strncpy(dst, src, max_amount)
|
||||
"strncpy_l", // strncpy_l(dst, src, max_amount, locale)
|
||||
"wcsncpy", // wcsncpy(dst, src, max_amount)
|
||||
"_wcsncpy_l", // _wcsncpy_l(dst, src, max_amount, locale)
|
||||
"_mbsncpy", // _mbsncpy(dst, src, max_amount)
|
||||
"_mbsncpy_l" // _mbsncpy_l(dst, src, max_amount, locale)
|
||||
] and
|
||||
argDest = 0 and
|
||||
argSrc = 1 and
|
||||
argLimit = 2
|
||||
|
||||
@@ -15,10 +15,7 @@ import cpp
|
||||
class ForbiddenFunction extends Function {
|
||||
ForbiddenFunction() {
|
||||
exists(string name | name = this.getName() |
|
||||
name = "setjmp" or
|
||||
name = "longjmp" or
|
||||
name = "sigsetjmp" or
|
||||
name = "siglongjmp"
|
||||
name = ["setjmp", "longjmp", "sigsetjmp", "siglongjmp"]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,12 +26,8 @@ import TaintedWithPath
|
||||
class FileFunction extends FunctionWithWrappers {
|
||||
FileFunction() {
|
||||
exists(string nme | this.hasGlobalName(nme) |
|
||||
nme = "fopen" or
|
||||
nme = "_fopen" or
|
||||
nme = "_wfopen" or
|
||||
nme = "open" or
|
||||
nme = "_open" or
|
||||
nme = "_wopen" or
|
||||
nme = ["fopen", "_fopen", "_wfopen", "open", "_open", "_wopen"]
|
||||
or
|
||||
// create file function on windows
|
||||
nme.matches("CreateFile%")
|
||||
)
|
||||
@@ -40,10 +36,7 @@ class FileFunction extends FunctionWithWrappers {
|
||||
or
|
||||
// on any of the fstream classes, or filebuf
|
||||
exists(string nme | this.getDeclaringType().hasQualifiedName("std", nme) |
|
||||
nme = "basic_fstream" or
|
||||
nme = "basic_ifstream" or
|
||||
nme = "basic_ofstream" or
|
||||
nme = "basic_filebuf"
|
||||
nme = ["basic_fstream", "basic_ifstream", "basic_ofstream", "basic_filebuf"]
|
||||
) and
|
||||
// we look for either the open method or the constructor
|
||||
(this.getName() = "open" or this instanceof Constructor)
|
||||
|
||||
@@ -21,11 +21,7 @@ class TaintSource extends VariableAccess {
|
||||
this.getTarget() instanceof SemanticStackVariable and
|
||||
x.isUserInput(this, cause)
|
||||
|
|
||||
cause = "read" or
|
||||
cause = "fread" or
|
||||
cause = "recv" or
|
||||
cause = "recvfrom" or
|
||||
cause = "recvmsg"
|
||||
cause = ["read", "fread", "recv", "recvfrom", "recvmsg"]
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,12 +14,5 @@ import cpp
|
||||
from Include i, string name
|
||||
where
|
||||
name = i.getIncludeText() and
|
||||
(
|
||||
name.matches("%'%") or
|
||||
name.matches("%\\\\%") or
|
||||
name.matches("%/*%") or
|
||||
name.matches("%//%") or
|
||||
name.matches("%\"%\"%\"%") or
|
||||
name.matches("%<%\"%>%")
|
||||
)
|
||||
name.matches(["%'%", "%\\\\%", "%/*%", "%//%", "%\"%\"%\"%", "%<%\"%>%"])
|
||||
select i, "AV Rule 53.1: Invalid character sequence in header file name '" + name + "'"
|
||||
|
||||
Reference in New Issue
Block a user