-
Notifications
You must be signed in to change notification settings - Fork 1.9k
JS: Precise data-flow for returns from async functions #4019
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
Changes from all commits
0004c28
cc94c5e
26ef2f3
0edb46c
b9a98f5
8f06e96
94cf3a8
54fd7d9
2680afc
244052f
30dc77e
9bcac10
3477857
e1ecc46
65a1769
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -922,6 +922,32 @@ module DataFlow { | |
| override File getFile() { result = function.getFile() } | ||
| } | ||
|
|
||
| /** | ||
| * A data flow node representing the values returned by a function. | ||
| */ | ||
| class FunctionReturnNode extends DataFlow::Node, TFunctionReturnNode { | ||
| Function function; | ||
|
|
||
| FunctionReturnNode() { this = TFunctionReturnNode(function) } | ||
|
|
||
| override string toString() { result = "return of " + function.describe() } | ||
|
|
||
| override predicate hasLocationInfo( | ||
| string filepath, int startline, int startcolumn, int endline, int endcolumn | ||
| ) { | ||
| function.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) | ||
| } | ||
|
|
||
| override BasicBlock getBasicBlock() { result = function.(ExprOrStmt).getBasicBlock() } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This basic block belongs to the enclosing function. How about
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Getting the basic-block of the enclosing function is consistent with how I think the current behavior is fine.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oof. I still think the current behavior is completely wrong, but I understand if you don't want to fix it in this PR. Opened https://github.com/github/codeql-javascript-team/issues/214. |
||
|
|
||
| /** | ||
| * Gets the function corresponding to this return node. | ||
| */ | ||
| Function getFunction() { result = function } | ||
|
|
||
| override File getFile() { result = function.getFile() } | ||
| } | ||
|
|
||
| /** | ||
| * A data flow node representing the exceptions thrown by the callee of an invocation. | ||
| */ | ||
|
|
@@ -1265,6 +1291,13 @@ module DataFlow { | |
| nd = TExceptionalFunctionReturnNode(function) | ||
| } | ||
|
|
||
| /** | ||
| * INTERNAL: Use `FunctionReturnNode` instead. | ||
| */ | ||
| predicate functionReturnNode(DataFlow::Node nd, Function function) { | ||
| nd = TFunctionReturnNode(function) | ||
| } | ||
|
|
||
| /** | ||
| * Gets the data flow node corresponding the given l-value expression, if | ||
| * such a node exists. | ||
|
|
@@ -1460,6 +1493,11 @@ module DataFlow { | |
| localCall(succExpr, f) | ||
| ) | ||
| ) | ||
| or | ||
| // from returned expr to the FunctionReturnNode. | ||
| exists(Function f | not f.isAsync() | | ||
| DataFlow::functionReturnNode(succ, f) and pred = valueNode(f.getAReturnedExpr()) | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.