-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JS: Added support for Array.prototype.[findLastIndex, findLast] ES2022 feature #18005
Conversation
04830fb
to
8795d1a
Compare
8795d1a
to
04830fb
Compare
b025fc6
to
0648392
Compare
0648392
to
1b0f8aa
Compare
{ // Test for findLastIndex function | ||
const list = ["source"]; | ||
const element = list.findLastIndex((item) => sink(item)); // NOT OK -- Not caught, currently missing dataflow tracking. | ||
const element = list.findLastIndex((item) => sink(item)); // NOT OK | ||
sink(element); // OK | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add a test like:
const element = source.findLastIndex((item) => sink(item)); // NOT OK - only found with taint-tracking.
sink(element); // OK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adds test case: f1e95a8
449c51b
to
28ead40
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two small suggestions to look into.
Otherwise OK 👍
override predicate step(DataFlow::Node obj, DataFlow::Node element) { | ||
exists(DataFlow::MethodCallNode call | | ||
call.getMethodName() = ["findLast", "find", "findLastIndex"] and | ||
obj = call.getReceiver().getALocalSource() and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
obj = call.getReceiver().getALocalSource() and | |
obj = call.getReceiver() and |
I don't think you need .getALocalSource()
here.
Try to see if the tests work with this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9dbf7d1 fixes.
@@ -492,7 +492,20 @@ private module ArrayLibraries { | |||
exists(DataFlow::MethodCallNode call | | |||
call.getMethodName() = ["findLast", "find", "findLastIndex"] and | |||
prop = arrayLikeElement() and | |||
obj = call.getReceiver() and | |||
obj = call.getReceiver().getALocalSource() and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
obj = call.getReceiver().getALocalSource() and | |
obj = call.getReceiver() and |
In the storeStep
you definitely need .getALocalSource()
, but I'm not sure you need it here?
See if this suggestion still passes the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
64c45de fixes.
Added support for ES2023 feature,
Arrray.protype.findLastIndex
,Arrray.protype. findLast
.DCA run shows that the run time stays approximately the same. Meta queries revealed new taint for
Arrray.protype.find
calls with lambda, which was expected.