Skip to content

Commit 63bd757

Browse files
committed
JS: Add another test and TODO about an issue with constant array indices
1 parent fa5fded commit 63bd757

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

javascript/ql/lib/semmle/javascript/dataflow/internal/Contents.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,10 @@ module Public {
255255
Content asSingleton() { this = MkSingletonContent(result) }
256256

257257
/** Gets the property name to be accessed. */
258-
PropertyName asPropertyName() { result = this.asSingleton().asPropertyName() }
258+
PropertyName asPropertyName() {
259+
// TODO: array indices should be mapped to a ContentSet that also reads from UnknownArrayElement
260+
result = this.asSingleton().asPropertyName()
261+
}
259262

260263
/** Gets the array index to be accessed. */
261264
int asArrayIndex() { result = this.asSingleton().asArrayIndex() }

javascript/ql/test/library-tests/TaintTracking/BasicTaintTracking.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ flow
5151
| array-mutation.js:31:33:31:40 | source() | array-mutation.js:32:8:32:8 | h |
5252
| array-mutation.js:35:36:35:43 | source() | array-mutation.js:36:8:36:8 | i |
5353
| array-mutation.js:39:17:39:24 | source() | array-mutation.js:40:8:40:8 | j |
54+
| array-mutation.js:43:10:43:17 | source() | array-mutation.js:44:8:44:11 | k[0] |
55+
| array-mutation.js:43:10:43:17 | source() | array-mutation.js:45:8:45:11 | k[1] |
56+
| array-mutation.js:43:10:43:17 | source() | array-mutation.js:46:8:46:11 | k[2] |
5457
| arrays-init.js:2:16:2:23 | source() | arrays-init.js:17:8:17:13 | arr[1] |
5558
| arrays-init.js:2:16:2:23 | source() | arrays-init.js:22:8:22:13 | arr[6] |
5659
| arrays-init.js:2:16:2:23 | source() | arrays-init.js:28:8:28:13 | arr[1] |

javascript/ql/test/library-tests/TripleDot/tst.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,12 @@ function t15() {
163163
args.push(source('t15.1'));
164164
target('safe', ...args);
165165
}
166+
167+
function t16() {
168+
let array = new Array(Math.floor(Math.random() * 10))
169+
array.push(source("t16.1"));
170+
sink(array[0]); // $ MISSING: hasValueFlow=t16.1 SPURIOUS: hasTaintFlow=t16.1
171+
sink(array[1]); // $ MISSING: hasValueFlow=t16.1 SPURIOUS: hasTaintFlow=t16.1
172+
sink(array[2]); // $ MISSING: hasValueFlow=t16.1 SPURIOUS: hasTaintFlow=t16.1
173+
sink(array); // $ hasTaintFlow=t16.1
174+
}

0 commit comments

Comments
 (0)