Skip to content

Commit 7d34ce4

Browse files
committed
Rewrite with different flow state
1 parent 84c0c09 commit 7d34ce4

8 files changed

+254
-84
lines changed

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

Lines changed: 240 additions & 69 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ where
2424
call.getResult(0) = source.getNode() and
2525
sinkConverted = sink.getNode().getASuccessor()
2626
select sinkConverted, source, sink,
27-
"Incorrect conversion of " +
28-
describeBitSize(getSourceBitSize(sink.getState()), getIntTypeBitSize(source.getNode().getFile()))
29-
+ " from $@ to a lower bit size type " + sinkConverted.getType().getUnderlyingType().getName() +
27+
"Incorrect conversion of " + describeBitSize2(source.getNode()) +
28+
" from $@ to a lower bit size type " + sinkConverted.getType().getUnderlyingType().getName() +
3029
" without an upper bound check.", source, call.getTarget().getQualifiedName()

go/ql/test/query-tests/Security/CWE-681/IncorrectIntegerConversion.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func testParseUint() {
134134
if err != nil {
135135
panic(err)
136136
}
137-
_ = int8(parsed)
137+
_ = int8(parsed) // $ hasValueFlow="type conversion"
138138
_ = uint8(parsed)
139139
_ = int16(parsed)
140140
_ = uint16(parsed)
@@ -152,7 +152,7 @@ func testParseUint() {
152152
}
153153
_ = int8(parsed) // $ hasValueFlow="type conversion"
154154
_ = uint8(parsed) // $ hasValueFlow="type conversion"
155-
_ = int16(parsed)
155+
_ = int16(parsed) // $ hasValueFlow="type conversion"
156156
_ = uint16(parsed)
157157
_ = int32(parsed)
158158
_ = uint32(parsed)
@@ -170,11 +170,11 @@ func testParseUint() {
170170
_ = uint8(parsed) // $ hasValueFlow="type conversion"
171171
_ = int16(parsed) // $ hasValueFlow="type conversion"
172172
_ = uint16(parsed) // $ hasValueFlow="type conversion"
173-
_ = int32(parsed)
173+
_ = int32(parsed) // $ hasValueFlow="type conversion"
174174
_ = uint32(parsed)
175175
_ = int64(parsed)
176176
_ = uint64(parsed)
177-
_ = int(parsed)
177+
_ = int(parsed) // $ hasValueFlow="type conversion"
178178
_ = uint(parsed)
179179
}
180180
{
@@ -188,7 +188,7 @@ func testParseUint() {
188188
_ = uint16(parsed) // $ hasValueFlow="type conversion"
189189
_ = int32(parsed) // $ hasValueFlow="type conversion"
190190
_ = uint32(parsed) // $ hasValueFlow="type conversion"
191-
_ = int64(parsed)
191+
_ = int64(parsed) // $ hasValueFlow="type conversion"
192192
_ = uint64(parsed)
193193
_ = int(parsed) // $ hasValueFlow="type conversion"
194194
_ = uint(parsed) // $ hasValueFlow="type conversion"
@@ -204,9 +204,9 @@ func testParseUint() {
204204
_ = uint16(parsed) // $ hasValueFlow="type conversion"
205205
_ = int32(parsed) // $ hasValueFlow="type conversion"
206206
_ = uint32(parsed) // $ hasValueFlow="type conversion"
207-
_ = int64(parsed)
207+
_ = int64(parsed) // $ hasValueFlow="type conversion"
208208
_ = uint64(parsed)
209-
_ = int(parsed)
209+
_ = int(parsed) // $ hasValueFlow="type conversion"
210210
_ = uint(parsed)
211211
}
212212
}

go/ql/test/query-tests/Security/CWE-681/Test32BitArchitectureBuildConstraintInFileName_386.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func testIntSource386() {
2020
if err != nil {
2121
panic(err)
2222
}
23-
_ = int32(parsed)
23+
_ = int32(parsed) // $ hasValueFlow="type conversion"
2424
_ = uint32(parsed)
2525
}
2626
{

go/ql/test/query-tests/Security/CWE-681/Test32BitArchitectureBuildConstraints.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func testIntSource32() {
2323
if err != nil {
2424
panic(err)
2525
}
26-
_ = int32(parsed)
26+
_ = int32(parsed) // $ hasValueFlow="type conversion"
2727
_ = uint32(parsed)
2828
}
2929
{

go/ql/test/query-tests/Security/CWE-681/Test64BitArchitectureBuildConstraintInFileName_amd64.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func testIntSinkAmd64() {
2020
if err != nil {
2121
panic(err)
2222
}
23-
_ = int(parsed)
23+
_ = int(parsed) // $ hasValueFlow="type conversion"
2424
_ = uint(parsed)
2525
}
2626
}

go/ql/test/query-tests/Security/CWE-681/Test64BitArchitectureBuildConstraints.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func testIntSink64() {
2323
if err != nil {
2424
panic(err)
2525
}
26-
_ = int(parsed)
26+
_ = int(parsed) // $ hasValueFlow="type conversion"
2727
_ = uint(parsed)
2828
}
2929
}

go/ql/test/query-tests/Security/CWE-681/TestOldBuildConstraints.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func oldTestIntSink64() {
2424
if err != nil {
2525
panic(err)
2626
}
27-
_ = int(parsed)
27+
_ = int(parsed) // $ hasValueFlow="type conversion"
2828
_ = uint(parsed)
2929
}
3030
}

0 commit comments

Comments
 (0)