mirror of
https://github.com/github/codeql.git
synced 2025-12-22 19:56:32 +01:00
C/C++ : change Variable and ArrayType name + Add detection for Uint 32 and 64
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
</overview>
|
||||
|
||||
<recommendation>
|
||||
<p>Use a Uint8 instead</p>
|
||||
<p>Use a int with a lower bit size instead. For instance in this example use a 8 bit int.</p>
|
||||
</recommendation>
|
||||
|
||||
<example>
|
||||
|
||||
@@ -8,16 +8,20 @@
|
||||
*/
|
||||
|
||||
import cpp
|
||||
import semmle.code.cpp.controlflow.SSA
|
||||
|
||||
from
|
||||
Variable E, ArrayExpr useExpr, ArrayType defExpr, VariableDeclarationEntry def, VariableAccess use
|
||||
Variable var, ArrayExpr useExpr, VariableDeclarationEntry def, ArrayType defLine, VariableAccess use
|
||||
where
|
||||
def = defExpr.getATypeNameUse() and
|
||||
E = def.getDeclaration() and
|
||||
def = defLine.getATypeNameUse() and
|
||||
var = def.getDeclaration() and
|
||||
use = useExpr.getArrayBase() and
|
||||
E = use.getTarget() and
|
||||
useExpr.getArrayOffset().getType() instanceof UInt16_t and
|
||||
defExpr.getArraySize() <= 256
|
||||
select useExpr, "Using a UInt16_t to acess the array $@ of size " + defExpr.getArraySize() + ".", E,
|
||||
E.getName()
|
||||
var = use.getTarget() and (
|
||||
(useExpr.getArrayOffset().getType() instanceof UInt16_t and
|
||||
defLine.getArraySize() <= 256) or
|
||||
(useExpr.getArrayOffset().getType() instanceof UInt32_t and
|
||||
defLine.getArraySize() <= 900) or
|
||||
(useExpr.getArrayOffset().getType() instanceof UInt64_t and
|
||||
defLine.getArraySize() <= 1000)
|
||||
)
|
||||
select useExpr, "Using a " + useExpr.getArrayOffset().getType() +" to acess the array $@ of size " + defLine.getArraySize() + ".", var,
|
||||
var.getName()
|
||||
|
||||
Reference in New Issue
Block a user