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:
Owen Mansel-Chan
2021-11-01 12:53:09 +00:00
parent 7d333d7dbe
commit 109e3660f8
4 changed files with 29 additions and 27 deletions

View File

@@ -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()

View 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()

View File

@@ -1 +1 @@
Security/CWE-681/IncorrectIntegerConversion.ql
Security/CWE-681/IncorrectIntegerConversionQuery.ql