Skip to content

Commit cc3a76f

Browse files
erik-kroghcklin
authored andcommitted
fix out of bounds string access in isUsingDecl
1 parent 1a575ef commit cc3a76f

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

javascript/extractor/src/com/semmle/jcorn/Parser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2708,7 +2708,8 @@ boolean isUsingDecl() {
27082708
Matcher m = Whitespace.skipWhiteSpace.matcher(this.input);
27092709
m.find(this.pos);
27102710
int next = m.end();
2711-
return !Whitespace.lineBreakG.matcher(inputSubstring(this.pos, next)).matches()
2711+
return this.input.length() > next &&
2712+
!Whitespace.lineBreakG.matcher(inputSubstring(this.pos, next)).matches()
27122713
&& Identifiers.isIdentifierChar(this.input.codePointAt(next), false);
27132714
}
27142715

javascript/ql/test/library-tests/AST/ExplicitResource/printAst.expected

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ nodes
44
| file://:0:0:0:0 | (Arguments) | semmle.label | (Arguments) |
55
| file://:0:0:0:0 | (Arguments) | semmle.label | (Arguments) |
66
| file://:0:0:0:0 | (Parameters) | semmle.label | (Parameters) |
7+
| tst.html:1:5:1:9 | [ExprStmt] using | semmle.label | [ExprStmt] using |
8+
| tst.html:1:5:1:9 | [ExprStmt] using | semmle.order | 1 |
9+
| tst.html:1:5:1:9 | [VarRef] using | semmle.label | [VarRef] using |
710
| tst.js:1:1:10:1 | [FunctionDeclStmt] functio ... } } | semmle.label | [FunctionDeclStmt] functio ... } } |
8-
| tst.js:1:1:10:1 | [FunctionDeclStmt] functio ... } } | semmle.order | 1 |
11+
| tst.js:1:1:10:1 | [FunctionDeclStmt] functio ... } } | semmle.order | 2 |
912
| tst.js:1:10:1:10 | [VarDecl] g | semmle.label | [VarDecl] g |
1013
| tst.js:1:14:10:1 | [BlockStmt] { u ... } } | semmle.label | [BlockStmt] { u ... } } |
1114
| tst.js:2:5:2:33 | [DeclStmt] using stream = ... | semmle.label | [DeclStmt] using stream = ... |
@@ -28,7 +31,7 @@ nodes
2831
| tst.js:6:45:9:5 | [BlockStmt] { ... ; } | semmle.label | [BlockStmt] { ... ; } |
2932
| tst.js:8:9:8:14 | [BreakStmt] break; | semmle.label | [BreakStmt] break; |
3033
| tst.js:12:1:21:1 | [FunctionDeclStmt] async f ... nd"); } | semmle.label | [FunctionDeclStmt] async f ... nd"); } |
31-
| tst.js:12:1:21:1 | [FunctionDeclStmt] async f ... nd"); } | semmle.order | 2 |
34+
| tst.js:12:1:21:1 | [FunctionDeclStmt] async f ... nd"); } | semmle.order | 3 |
3235
| tst.js:12:16:12:16 | [VarDecl] h | semmle.label | [VarDecl] h |
3336
| tst.js:12:20:21:1 | [BlockStmt] { a ... nd"); } | semmle.label | [BlockStmt] { a ... nd"); } |
3437
| tst.js:13:5:13:39 | [DeclStmt] using stream = ... | semmle.label | [DeclStmt] using stream = ... |
@@ -51,7 +54,7 @@ nodes
5154
| tst.js:20:13:20:15 | [Label] log | semmle.label | [Label] log |
5255
| tst.js:20:17:20:21 | [Literal] "end" | semmle.label | [Literal] "end" |
5356
| tst.js:23:1:29:1 | [FunctionDeclStmt] functio ... ing); } | semmle.label | [FunctionDeclStmt] functio ... ing); } |
54-
| tst.js:23:1:29:1 | [FunctionDeclStmt] functio ... ing); } | semmle.order | 3 |
57+
| tst.js:23:1:29:1 | [FunctionDeclStmt] functio ... ing); } | semmle.order | 4 |
5558
| tst.js:23:10:23:18 | [VarDecl] usesUsing | semmle.label | [VarDecl] usesUsing |
5659
| tst.js:23:22:29:1 | [BlockStmt] { u ... ing); } | semmle.label | [BlockStmt] { u ... ing); } |
5760
| tst.js:24:5:24:9 | [VarRef] using | semmle.label | [VarRef] using |
@@ -77,6 +80,8 @@ edges
7780
| file://:0:0:0:0 | (Arguments) | tst.js:28:11:28:15 | [VarRef] using | semmle.order | 0 |
7881
| file://:0:0:0:0 | (Parameters) | tst.js:25:20:25:22 | [SimpleParameter] foo | semmle.label | 0 |
7982
| file://:0:0:0:0 | (Parameters) | tst.js:25:20:25:22 | [SimpleParameter] foo | semmle.order | 0 |
83+
| tst.html:1:5:1:9 | [ExprStmt] using | tst.html:1:5:1:9 | [VarRef] using | semmle.label | 1 |
84+
| tst.html:1:5:1:9 | [ExprStmt] using | tst.html:1:5:1:9 | [VarRef] using | semmle.order | 1 |
8085
| tst.js:1:1:10:1 | [FunctionDeclStmt] functio ... } } | tst.js:1:10:1:10 | [VarDecl] g | semmle.label | 0 |
8186
| tst.js:1:1:10:1 | [FunctionDeclStmt] functio ... } } | tst.js:1:10:1:10 | [VarDecl] g | semmle.order | 0 |
8287
| tst.js:1:1:10:1 | [FunctionDeclStmt] functio ... } } | tst.js:1:14:10:1 | [BlockStmt] { u ... } } | semmle.label | 5 |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<%= using %>
2+
<!-- the above should not crash-->

0 commit comments

Comments
 (0)