Skip to content

Commit c0b579c

Browse files
committed
Improve tests
1 parent 7d34ce4 commit c0b579c

File tree

1 file changed

+59
-2
lines changed

1 file changed

+59
-2
lines changed

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

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,72 @@ func testBoundsChecking(input string) {
266266
}
267267
if parsed <= math.MaxUint16 {
268268
_ = uint16(parsed)
269+
_ = uint(parsed)
270+
_ = int32(parsed)
271+
}
272+
}
273+
{
274+
parsed, err := strconv.ParseUint(input, 10, 0)
275+
if err != nil {
276+
panic(err)
277+
}
278+
if parsed <= math.MaxUint64 {
279+
_ = int8(parsed) // $ hasValueFlow="type conversion"
280+
_ = uint8(parsed) // $ hasValueFlow="type conversion"
281+
_ = int16(parsed) // $ hasValueFlow="type conversion"
282+
_ = uint16(parsed) // $ hasValueFlow="type conversion"
283+
_ = int32(parsed) // $ hasValueFlow="type conversion"
284+
_ = uint32(parsed) // $ hasValueFlow="type conversion"
285+
_ = int64(parsed) // $ hasValueFlow="type conversion"
286+
_ = uint64(parsed)
287+
_ = int(parsed) // $ hasValueFlow="type conversion"
288+
_ = uint(parsed)
289+
}
290+
if parsed <= math.MaxInt64 {
291+
_ = int8(parsed) // $ hasValueFlow="type conversion"
292+
_ = uint8(parsed) // $ hasValueFlow="type conversion"
293+
_ = int16(parsed) // $ hasValueFlow="type conversion"
294+
_ = uint16(parsed) // $ hasValueFlow="type conversion"
295+
_ = int32(parsed) // $ hasValueFlow="type conversion"
296+
_ = uint32(parsed) // $ hasValueFlow="type conversion"
297+
_ = int64(parsed)
298+
_ = uint64(parsed)
299+
_ = int(parsed) // $ hasValueFlow="type conversion"
300+
_ = uint(parsed)
301+
}
302+
if parsed <= math.MaxUint32 {
303+
_ = int8(parsed) // $ hasValueFlow="type conversion"
304+
_ = uint8(parsed) // $ hasValueFlow="type conversion"
305+
_ = int16(parsed) // $ hasValueFlow="type conversion"
306+
_ = uint16(parsed) // $ hasValueFlow="type conversion"
307+
_ = int32(parsed) // $ hasValueFlow="type conversion"
308+
_ = uint32(parsed)
309+
_ = int64(parsed)
310+
_ = uint64(parsed)
311+
_ = int(parsed) // $ hasValueFlow="type conversion"
312+
_ = uint(parsed)
313+
}
314+
if parsed <= math.MaxInt32 {
315+
_ = int8(parsed) // $ hasValueFlow="type conversion"
316+
_ = uint8(parsed) // $ hasValueFlow="type conversion"
317+
_ = int16(parsed) // $ hasValueFlow="type conversion"
318+
_ = uint16(parsed) // $ hasValueFlow="type conversion"
319+
_ = int32(parsed)
320+
_ = uint32(parsed)
321+
_ = int64(parsed)
322+
_ = uint64(parsed)
323+
_ = int(parsed)
324+
_ = uint(parsed)
269325
}
270326
}
271327
{
272328
parsed, err := strconv.ParseUint(input, 10, 32)
273329
if err != nil {
274330
panic(err)
275331
}
276-
if parsed <= math.MaxUint8 {
277-
_ = uint8(parsed)
332+
if parsed <= math.MaxUint16 {
333+
_ = uint16(parsed)
334+
_ = int16(parsed) // $ hasValueFlow="type conversion"
278335
}
279336
if parsed < 5 {
280337
_ = uint16(parsed)

0 commit comments

Comments
 (0)