Skip to content

Commit 6266d8b

Browse files
authored
Merge pull request #184 from aschackmull/java/intmulttolong-message
Approved by yh-semmle
2 parents 3d02229 + b9acdf5 commit 6266d8b

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* external/cwe/cwe-197
1616
* external/cwe/cwe-681
1717
*/
18+
1819
import java
1920
import semmle.code.java.dataflow.RangeUtils
2021
import semmle.code.java.Conversions
@@ -25,7 +26,8 @@ predicate small(MulExpr e) {
2526
lhs = e.getLeftOperand().getProperExpr().(ConstantIntegerExpr).getIntValue() and
2627
rhs = e.getRightOperand().getProperExpr().(ConstantIntegerExpr).getIntValue() and
2728
lhs * rhs = res and
28-
t.getOrdPrimitiveType().getMinValue() <= res and res <= t.getOrdPrimitiveType().getMaxValue()
29+
t.getOrdPrimitiveType().getMinValue() <= res and
30+
res <= t.getOrdPrimitiveType().getMaxValue()
2931
)
3032
}
3133

@@ -52,4 +54,7 @@ where
5254
// not obviously small and ok
5355
not small(e) and
5456
e.getEnclosingCallable().fromSource()
55-
select c, "$@ converted to "+ destType.getName() +" by use in " + ("a " + c.kind()).regexpReplaceAll("^a ([aeiou])", "an $1") + ".", e, sourceType.getName() + " multiplication"
57+
select c,
58+
"Potential overflow in $@ before it is converted to " + destType.getName() + " by use in " +
59+
("a " + c.kind()).regexpReplaceAll("^a ([aeiou])", "an $1") + ".", e,
60+
sourceType.getName() + " multiplication"
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| Test.java:20:23:20:48 | ... * ... | $@ converted to long by use in an assignment context. | Test.java:20:23:20:48 | ... * ... | int multiplication |
2-
| Test.java:27:23:27:52 | ... + ... | $@ converted to long by use in an assignment context. | Test.java:27:23:27:48 | ... * ... | int multiplication |
3-
| Test.java:34:23:34:63 | ...?...:... | $@ converted to long by use in an assignment context. | Test.java:34:30:34:55 | ... * ... | int multiplication |
4-
| Test.java:41:25:41:49 | ... * ... | $@ converted to double by use in an assignment context. | Test.java:41:25:41:49 | ... * ... | long multiplication |
1+
| 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 |
2+
| 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 |
3+
| 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 |

0 commit comments

Comments
 (0)