Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b0364e3

Browse files
authored
Merge pull request #729 from aschackmull/java/intmulttolong
Java: Restrict attention to integral types in IntMultToLong.
2 parents a09394d + 06e48ca commit b0364e3

4 files changed

Lines changed: 4 additions & 2 deletions

File tree

change-notes/1.20/analysis-java.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
| **Query** | **Expected impact** | **Change** |
1616
|----------------------------|------------------------|------------------------------------------------------------------|
17+
| Result of multiplication cast to wider type (`java/integer-multiplication-cast-to-long`) | Fewer results | Results involving conversions to `float` or `double` are no longer reported, as they were almost exclusively false positives. |
1718

1819
## Changes to QL libraries
1920

java/ql/src/Likely Bugs/Arithmetic/IntMultToLong.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ where
4747
e.getType() = sourceType and
4848
c.getConversionTarget() = destType and
4949
destType.widerThan(sourceType) and
50+
// restrict attention to integral types
51+
destType instanceof IntegralType and
5052
// not a trivial conversion
5153
not c.isTrivial() and
5254
// not an explicit conversion, which is probably intended by a user
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
| Test.java:20:23:20:48 | ... * ... | Potential overflow in $@ before it is converted to long by use in an assignment context. | Test.java:20:23:20:48 | ... * ... | int multiplication |
22
| Test.java:27:23:27:52 | ... + ... | Potential overflow in $@ before it is converted to long by use in an assignment context. | Test.java:27:23:27:48 | ... * ... | int multiplication |
33
| Test.java:34:23:34:63 | ...?...:... | Potential overflow in $@ before it is converted to long by use in an assignment context. | Test.java:34:30:34:55 | ... * ... | int multiplication |
4-
| Test.java:41:25:41:49 | ... * ... | Potential overflow in $@ before it is converted to double by use in an assignment context. | Test.java:41:25:41:49 | ... * ... | long multiplication |

java/ql/test/query-tests/security/CWE-190/semmle/tests/Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static void main(String[] args) {
3737
{
3838
long timeInSeconds = 10000000L;
3939

40-
// BAD: same problem, but with longs
40+
// same problem, but with longs; not reported as the conversion to double is not sufficient indication of a large number
4141
double timeInNanos = timeInSeconds * 10000000L;
4242
}
4343

0 commit comments

Comments
 (0)