Merge pull request #718 from owen-mc/fix-incorrect-integer-conversion-for-type-assertions

Integer conversion should ignore type assertions
This commit is contained in:
Chris Smowton
2022-04-12 12:44:43 +01:00
committed by GitHub
2 changed files with 11 additions and 0 deletions

View File

@@ -110,6 +110,7 @@ class ConversionWithoutBoundsCheckConfig extends TaintTracking::Configuration {
* a common pattern to serialise `byte(v)`, `byte(v >> 8)`, and so on.
*/
predicate isSink(DataFlow::TypeCastNode sink, int bitSize) {
sink.asExpr() instanceof ConversionExpr and
exists(IntegerType integerType | sink.getResultType().getUnderlyingType() = integerType |
bitSize = integerType.getSize()
or

View File

@@ -409,3 +409,13 @@ func parsePositiveInt2(value string) (int, error) {
}
return int(i64), nil
}
func typeAssertion(s string) {
n, err := strconv.ParseInt(s, 10, 0)
if err == nil {
var itf interface{} = n
i32 := itf.(int32)
println(i32)
}
}