File tree Expand file tree Collapse file tree 5 files changed +24
-24
lines changed
query-tests/security/cwe-079 Expand file tree Collapse file tree 5 files changed +24
-24
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,23 @@ private class Desugared extends AstNode {
126126 */
127127int desugarLevel ( AstNode n ) { result = count ( Desugared desugared | n = desugared .getADescendant ( ) ) }
128128
129+ /**
130+ * Holds if `n` appears in a context that is desugared. That is, a
131+ * transitive, reflexive parent of `n` is a desugared node.
132+ */
133+ predicate isInDesugeredContext ( AstNode n ) { n = any ( AstNode sugar ) .getDesugared ( ) .getAChild * ( ) }
134+
135+ /**
136+ * Holds if `n` is a node that only exists as a result of desugaring some
137+ * other node.
138+ */
139+ predicate isDesugarNode ( AstNode n ) {
140+ n = any ( AstNode sugar ) .getDesugared ( )
141+ or
142+ isInDesugeredContext ( n ) and
143+ forall ( AstNode parent | parent = n .getParent ( ) | parent .isSynthesized ( ) )
144+ }
145+
129146/**
130147 * Use this predicate in `Synthesis::child` to generate an assignment of `value` to
131148 * synthesized variable `v`, where the assignment is a child of `assignParent` at
Original file line number Diff line number Diff line change 11private import ruby
2+ private import codeql.ruby.ast.internal.Synthesis
23private import codeql.ruby.CFG
34private import codeql.ruby.dataflow.SSA
45private import DataFlowPublic
@@ -274,6 +275,8 @@ predicate nodeIsHidden(Node n) {
274275 def instanceof Ssa:: PhiNode
275276 )
276277 or
278+ isDesugarNode ( n .( ExprNode ) .getExprNode ( ) .getExpr ( ) )
279+ or
277280 n instanceof SummaryNode
278281 or
279282 n instanceof SummaryParameterNode
Original file line number Diff line number Diff line change 88
99private import AST
1010private import codeql.ruby.security.performance.RegExpTreeView as RETV
11-
12- /** Holds if `n` appears in the desugaring of some other node. */
13- predicate isDesugared ( AstNode n ) {
14- n = any ( AstNode sugar ) .getDesugared ( )
15- or
16- isDesugared ( n .getParent ( ) )
17- }
11+ private import codeql.ruby.ast.internal.Synthesis
1812
1913/**
2014 * The query can extend this class to control which nodes are printed.
@@ -25,19 +19,7 @@ class PrintAstConfiguration extends string {
2519 /**
2620 * Holds if the given node should be printed.
2721 */
28- predicate shouldPrintNode ( AstNode n ) {
29- not isDesugared ( n )
30- or
31- not n .isSynthesized ( )
32- or
33- n .isSynthesized ( ) and
34- not n = any ( AstNode sugar ) .getDesugared ( ) and
35- exists ( AstNode parent |
36- parent = n .getParent ( ) and
37- not parent .isSynthesized ( ) and
38- not n = parent .getDesugared ( )
39- )
40- }
22+ predicate shouldPrintNode ( AstNode n ) { not isDesugarNode ( n ) }
4123
4224 predicate shouldPrintAstEdge ( AstNode parent , string edgeName , AstNode child ) {
4325 child = parent .getAChild ( edgeName ) and
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import codeql.ruby.ast.internal.Synthesis
88
99class DesugarPrintAstConfiguration extends PrintAstConfiguration {
1010 override predicate shouldPrintNode ( AstNode n ) {
11- isDesugared ( n )
11+ isInDesugeredContext ( n )
1212 or
1313 exists ( n .getDesugared ( ) )
1414 }
Original file line number Diff line number Diff line change 11edges
22| app/controllers/foo/bars_controller.rb:9:12:9:17 | call to params : | app/controllers/foo/bars_controller.rb:9:12:9:29 | ...[...] : |
33| app/controllers/foo/bars_controller.rb:9:12:9:29 | ...[...] : | app/views/foo/bars/show.html.erb:47:5:47:13 | call to user_name |
4- | app/controllers/foo/bars_controller.rb:13:5:13:37 | ... = ... : | app/views/foo/bars/show.html.erb:51:5:51:18 | call to user_name_memo |
5- | app/controllers/foo/bars_controller.rb:13:20:13:25 | call to params : | app/controllers/foo/bars_controller.rb:13:5:13:37 | ... = ... : |
4+ | app/controllers/foo/bars_controller.rb:13:20:13:25 | call to params : | app/views/foo/bars/show.html.erb:51:5:51:18 | call to user_name_memo |
65| app/controllers/foo/bars_controller.rb:17:21:17:26 | call to params : | app/controllers/foo/bars_controller.rb:17:21:17:36 | ...[...] : |
76| app/controllers/foo/bars_controller.rb:17:21:17:36 | ...[...] : | app/views/foo/bars/show.html.erb:2:18:2:30 | @user_website |
87| app/controllers/foo/bars_controller.rb:18:10:18:15 | call to params : | app/controllers/foo/bars_controller.rb:19:22:19:23 | dt : |
2120nodes
2221| app/controllers/foo/bars_controller.rb:9:12:9:17 | call to params : | semmle.label | call to params : |
2322| app/controllers/foo/bars_controller.rb:9:12:9:29 | ...[...] : | semmle.label | ...[...] : |
24- | app/controllers/foo/bars_controller.rb:13:5:13:37 | ... = ... : | semmle.label | ... = ... : |
2523| app/controllers/foo/bars_controller.rb:13:20:13:25 | call to params : | semmle.label | call to params : |
2624| app/controllers/foo/bars_controller.rb:17:21:17:26 | call to params : | semmle.label | call to params : |
2725| app/controllers/foo/bars_controller.rb:17:21:17:36 | ...[...] : | semmle.label | ...[...] : |
You can’t perform that action at this time.
0 commit comments