mirror of
https://github.com/github/codeql.git
synced 2026-01-30 06:42:57 +01:00
Split Incorrect Integer Conversion into query and lib files
This is in preparation for changing the tests to use inline expectations
This commit is contained in:
@@ -1,20 +1,4 @@
|
||||
/**
|
||||
* @name Incorrect conversion between integer types
|
||||
* @description Converting the result of `strconv.Atoi`, `strconv.ParseInt`,
|
||||
* and `strconv.ParseUint` to integer types of smaller bit size
|
||||
* can produce unexpected values.
|
||||
* @kind path-problem
|
||||
* @problem.severity warning
|
||||
* @security-severity 8.1
|
||||
* @id go/incorrect-integer-conversion
|
||||
* @tags security
|
||||
* external/cwe/cwe-190
|
||||
* external/cwe/cwe-681
|
||||
* @precision very-high
|
||||
*/
|
||||
|
||||
import go
|
||||
import DataFlow::PathGraph
|
||||
|
||||
/**
|
||||
* Gets the maximum value of an integer (signed if `isSigned`
|
||||
@@ -192,13 +176,3 @@ string describeBitSize(int bitSize, int intTypeBitSize) {
|
||||
"a number with architecture-dependent bit-width, which is constrained to be " +
|
||||
intTypeBitSize + "-bit by build constraints,"
|
||||
}
|
||||
|
||||
from
|
||||
DataFlow::PathNode source, DataFlow::PathNode sink, ConversionWithoutBoundsCheckConfig cfg,
|
||||
DataFlow::CallNode call
|
||||
where cfg.hasFlowPath(source, sink) and call.getResult(0) = source.getNode()
|
||||
select sink.getNode(), source, sink,
|
||||
"Incorrect conversion of " +
|
||||
describeBitSize(cfg.getSourceBitSize(), getIntTypeBitSize(source.getNode().getFile())) +
|
||||
" from $@ to a lower bit size type " + sink.getNode().getType().getUnderlyingType().getName() +
|
||||
" without an upper bound check.", source, call.getTarget().getQualifiedName()
|
||||
28
ql/src/Security/CWE-681/IncorrectIntegerConversionQuery.ql
Normal file
28
ql/src/Security/CWE-681/IncorrectIntegerConversionQuery.ql
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* @name Incorrect conversion between integer types
|
||||
* @description Converting the result of `strconv.Atoi`, `strconv.ParseInt`,
|
||||
* and `strconv.ParseUint` to integer types of smaller bit size
|
||||
* can produce unexpected values.
|
||||
* @kind path-problem
|
||||
* @problem.severity warning
|
||||
* @security-severity 8.1
|
||||
* @id go/incorrect-integer-conversion
|
||||
* @tags security
|
||||
* external/cwe/cwe-190
|
||||
* external/cwe/cwe-681
|
||||
* @precision very-high
|
||||
*/
|
||||
|
||||
import go
|
||||
import DataFlow::PathGraph
|
||||
import semmle.go.security.IncorrectIntegerConversionLib
|
||||
|
||||
from
|
||||
DataFlow::PathNode source, DataFlow::PathNode sink, ConversionWithoutBoundsCheckConfig cfg,
|
||||
DataFlow::CallNode call
|
||||
where cfg.hasFlowPath(source, sink) and call.getResult(0) = source.getNode()
|
||||
select sink.getNode(), source, sink,
|
||||
"Incorrect conversion of " +
|
||||
describeBitSize(cfg.getSourceBitSize(), getIntTypeBitSize(source.getNode().getFile())) +
|
||||
" from $@ to a lower bit size type " + sink.getNode().getType().getUnderlyingType().getName() +
|
||||
" without an upper bound check.", source, call.getTarget().getQualifiedName()
|
||||
@@ -1 +1 @@
|
||||
Security/CWE-681/IncorrectIntegerConversion.ql
|
||||
Security/CWE-681/IncorrectIntegerConversionQuery.ql
|
||||
|
||||
Reference in New Issue
Block a user