Skip to content

Commit 9c41b21

Browse files
authored
Merge pull request #748 from esben-semmle/js/fix/js/useless-assignment-to-property
Approved by xiemaisi
2 parents eabc674 + 9af6a81 commit 9c41b21

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

change-notes/1.20/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
| Unused parameter | Fewer false-positive results | This rule no longer flags parameters with leading underscore. |
3232
| Unused variable, import, function or class | Fewer false-positive results | This rule now flags fewer variables that are implictly used by JSX elements, and no longer flags variables with leading underscore. |
3333
| Uncontrolled data used in path expression | Fewer false-positive results | This rule now recognizes the Express `root` option, which prevents path traversal. |
34+
| Useless assignment to property. | Fewer false-positive results | This rule now treats assignments with complex right-hand sides correctly. |
3435

3536
## Changes to QL libraries
3637

javascript/ql/src/Declarations/DeadStoreOfProperty.ql

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@ predicate isDeadAssignment(string name, DataFlow::PropWrite assign1, DataFlow::P
7878
*/
7979
bindingset[name]
8080
predicate maybeAccessesAssignedPropInBlock(string name, DataFlow::PropWrite assign, boolean after) {
81-
exists(ControlFlowNode write, ReachableBasicBlock block, int i, int j, Expr e |
82-
write = assign.getWriteNode() and
83-
block = assign.getBasicBlock() and
84-
write = block.getNode(i) and
81+
exists(ReachableBasicBlock block, int i, int j, Expr e |
82+
assign.getWriteNode() = block.getNode(i) and
8583
e = block.getNode(j) and
8684
maybeAccessesProperty(e, name)
8785
|
@@ -108,8 +106,8 @@ predicate noPropAccessBetween(string name, DataFlow::PropWrite assign1, DataFlow
108106
then
109107
// same block: check for access between
110108
not exists(int i1, Expr mid, int i2 |
111-
assign1.getWriteNode() = block1.getNode(i1) and
112-
assign2.getWriteNode() = block2.getNode(i2) and
109+
write1 = block1.getNode(i1) and
110+
write2 = block2.getNode(i2) and
113111
mid = block1.getNode([i1 + 1 .. i2 - 1]) and
114112
maybeAccessesProperty(mid, name)
115113
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(function(o1, o2){
2+
o1.p = x ? x : x;
3+
o1.p = o1.p + (x ? x : x);
4+
5+
o2.p = x ? x : x;
6+
let v2 = o2.p + (x ? x : x);
7+
o2.p = v;
8+
9+
let v1 = x? x: x;
10+
o3.p = v;
11+
o3.p = o3.p + (x ? x : x);
12+
});

0 commit comments

Comments
 (0)