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

Skip to content

Commit 2ecabad

Browse files
author
Max Schaefer
authored
Merge pull request #1004 from asger-semmle/suffix-check-bug
JS: Recognize '+' in suffix check
2 parents edba241 + 8e8085e commit 2ecabad

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

javascript/ql/src/Security/CWE-020/IncorrectSuffixCheck.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ predicate isDerivedFromLength(DataFlow::Node length, DataFlow::Node operand) {
9595
or
9696
isDerivedFromLength(length.getAPredecessor(), operand)
9797
or
98-
exists(SubExpr sub |
99-
isDerivedFromLength(sub.getAnOperand().flow(), operand) and
100-
length = sub.flow()
98+
exists(BinaryExpr expr | expr instanceof SubExpr or expr instanceof AddExpr |
99+
isDerivedFromLength(expr.getAnOperand().flow(), operand) and
100+
length = expr.flow()
101101
)
102102
}
103103

javascript/ql/test/query-tests/Security/CWE-020/IncorrectSuffixCheck.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
| tst.js:55:32:55:71 | x.index ... gth - 1 | This suffix check is missing a length comparison to correctly handle indexOf returning -1. |
99
| tst.js:67:32:67:71 | x.index ... gth - 1 | This suffix check is missing a length comparison to correctly handle indexOf returning -1. |
1010
| tst.js:76:25:76:57 | index = ... gth - 1 | This suffix check is missing a length comparison to correctly handle indexOf returning -1. |
11+
| tst.js:80:10:80:57 | x.index ... th + 1) | This suffix check is missing a length comparison to correctly handle indexOf returning -1. |

javascript/ql/test/query-tests/Security/CWE-020/tst.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,7 @@ function withIndexOfCheckBad(x, y) {
7575
let index = x.indexOf(y);
7676
return index !== 0 && index === x.length - y.length - 1; // NOT OK
7777
}
78+
79+
function plus(x, y) {
80+
return x.indexOf("." + y) === x.length - (y.length + 1); // NOT OK
81+
}

0 commit comments

Comments
 (0)