Skip to content

Commit 55e5edc

Browse files
committed
Fix IncorrectIntegerConversion for use-use flow
We were assuming that `sink` only had one successor, the TypeCastNode, but it can now have an adjacent use as well.
1 parent 6b5a6d9 commit 55e5edc

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

go/ql/lib/semmle/go/security/IncorrectIntegerConversionLib.qll

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,17 @@ private predicate integerTypeBound(IntegerType it, int bitSize, int architecture
290290
* the type assertion succeeded. If it is not checked then there will be a
291291
* run-time panic if the type assertion fails, so we can assume it succeeded.
292292
*/
293-
class TypeAssertionCheck extends DataFlow::ExprNode, FlowStateTransformer {
293+
class TypeAssertionCheck extends DataFlow::InstructionNode, FlowStateTransformer {
294294
IntegerType it;
295295

296296
TypeAssertionCheck() {
297-
exists(TypeAssertExpr tae |
298-
this = DataFlow::exprNode(tae.getExpr()) and
299-
it = tae.getTypeExpr().getType().getUnderlyingType()
297+
exists(IR::Instruction evalAssert, TypeAssertExpr assert |
298+
it = assert.getTypeExpr().getType().getUnderlyingType() and
299+
evalAssert = IR::evalExprInstruction(assert)
300+
|
301+
if exists(IR::extractTupleElement(evalAssert, _))
302+
then this.asInstruction() = IR::extractTupleElement(evalAssert, 0)
303+
else this.asInstruction() = evalAssert
300304
)
301305
}
302306

go/ql/src/Security/CWE-681/IncorrectIntegerConversionQuery.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import semmle.go.security.IncorrectIntegerConversionLib
1818
import Flow::PathGraph
1919

2020
from
21-
Flow::PathNode source, Flow::PathNode sink, DataFlow::CallNode call, DataFlow::Node sinkConverted
21+
Flow::PathNode source, Flow::PathNode sink, DataFlow::CallNode call,
22+
DataFlow::TypeCastNode sinkConverted
2223
where
2324
Flow::flowPath(source, sink) and
2425
call.getResult(0) = source.getNode() and

0 commit comments

Comments
 (0)