ruby: add Rack::ResponseNode class

This commit is contained in:
Alex Ford 2023-05-16 14:45:59 +01:00
Родитель c28af7672d
Коммит e7e0cf5cb3
2 изменённых файлов: 11 добавлений и 6 удалений

Просмотреть файл

@ -1279,13 +1279,18 @@ class HashLiteralNode extends LocalSourceNode, ExprNode {
* into calls to `Array.[]`, so this includes both desugared calls as well as
* explicit calls.
*/
class ArrayLiteralNode extends LocalSourceNode, ExprNode {
ArrayLiteralNode() { super.getExprNode() instanceof CfgNodes::ExprNodes::ArrayLiteralCfgNode }
class ArrayLiteralNode extends LocalSourceNode, CallNode {
private CfgNodes::ExprNodes::ArrayLiteralCfgNode arrayNode;
ArrayLiteralNode() { super.getExprNode() = arrayNode }
/**
* Gets an element of the array.
*/
Node getAnElement() { result = this.(CallNode).getPositionalArgument(_) }
Node getAnElement() { result = this.getElement(_) }
/** Gets the `i`th element of the array. */
Node getElement(int i) { result = this.getPositionalArgument(i) }
}
/**

Просмотреть файл

@ -30,14 +30,14 @@ module Rack {
DataFlow::ParameterNode getEnv() { result = call.getParameter(0) }
}
private predicate isRackResponse(DataFlow::Node r) {
class ResponseNode extends DataFlow::ArrayLiteralNode {
// [status, headers, body]
r.asExpr().(ArrayLiteralCfgNode).getNumberOfArguments() = 3
ResponseNode() { this.getNumberOfArguments() = 3 }
}
private DataFlow::LocalSourceNode trackRackResponse(TypeTracker t) {
t.start() and
isRackResponse(result)
result instanceof ResponseNode
or
exists(TypeTracker t2 | result = trackRackResponse(t2).track(t2, t))
}