Skip to content

Commit 78b2538

Browse files
committed
JS: Protect against bad join in BadRandomness
This code resulted in bad join orders in response to certain library changes. The actual library changes have to be split into smaller pieces but I'd like to ensure I don't run into the bad join again.
1 parent 46f88e7 commit 78b2538

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

javascript/ql/src/Security/CWE-327/BadRandomness.ql

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,26 @@ private int powerOfTwo() {
3030
* Gets a node that has value 2^n for some n.
3131
*/
3232
private DataFlow::Node isPowerOfTwo() {
33-
exists(DataFlow::Node prev |
34-
prev.getIntValue() = powerOfTwo()
35-
or
36-
// Getting around the 32 bit ints in QL. These are some hex values of the form 0x10000000
37-
prev.asExpr().(NumberLiteral).getValue() =
38-
["281474976710656", "17592186044416", "1099511627776", "68719476736", "4294967296"]
39-
|
40-
result = prev.getASuccessor*()
41-
)
33+
result.getIntValue() = powerOfTwo()
34+
or
35+
// Getting around the 32 bit ints in QL. These are some hex values of the form 0x10000000
36+
result.asExpr().(NumberLiteral).getValue() =
37+
["281474976710656", "17592186044416", "1099511627776", "68719476736", "4294967296"]
38+
or
39+
result = isPowerOfTwo().getASuccessor()
4240
}
4341

4442
/**
4543
* Gets a node that has value (2^n)-1 for some n.
4644
*/
4745
private DataFlow::Node isPowerOfTwoMinusOne() {
48-
exists(DataFlow::Node prev |
49-
prev.getIntValue() = powerOfTwo() - 1
50-
or
51-
// Getting around the 32 bit ints in QL. These are some hex values of the form 0xfffffff
52-
prev.asExpr().(NumberLiteral).getValue() =
53-
["281474976710655", "17592186044415", "1099511627775", "68719476735", "4294967295"]
54-
|
55-
result = prev.getASuccessor*()
56-
)
46+
result.getIntValue() = powerOfTwo() - 1
47+
or
48+
// Getting around the 32 bit ints in QL. These are some hex values of the form 0xfffffff
49+
result.asExpr().(NumberLiteral).getValue() =
50+
["281474976710655", "17592186044415", "1099511627775", "68719476735", "4294967295"]
51+
or
52+
result = isPowerOfTwoMinusOne().getASuccessor()
5753
}
5854

5955
/**

0 commit comments

Comments
 (0)