Ruby: Replace getValueText with getConstantValue

This commit is contained in:
Tom Hvitved
2022-01-20 14:22:11 +01:00
parent fede7dd238
commit aa9cfebc65
37 changed files with 732 additions and 280 deletions

View File

@@ -68,7 +68,7 @@ class DefaultTaintFlowConf extends TaintTracking::Configuration {
private string getSourceArgString(DataFlow::Node src) {
defaultSource(src) and
src.asExpr().getExpr().(MethodCall).getAnArgument().getValueText() = result
src.asExpr().getExpr().(MethodCall).getAnArgument().getConstantValue().toString() = result
}
class InlineFlowTest extends InlineExpectationsTest {

View File

@@ -214,7 +214,9 @@
| control/cases.rb:101:18:101:19 | 10 | 10 |
| control/cases.rb:102:6:102:9 | :foo | foo |
| control/cases.rb:103:6:103:15 | :"foo bar" | foo bar |
| control/cases.rb:104:6:104:7 | - ... | -5 |
| control/cases.rb:104:7:104:7 | 5 | 5 |
| control/cases.rb:104:11:104:13 | + ... | 10 |
| control/cases.rb:104:12:104:13 | 10 | 10 |
| control/cases.rb:105:7:105:7 | 1 | 1 |
| control/cases.rb:106:7:106:7 | 0 | 0 |
@@ -355,29 +357,27 @@
| gems/test.gemspec:9:3:9:12 | __synth__0 | https://github.com/github/codeql-ruby |
| gems/test.gemspec:9:19:9:57 | "https://github.com/github/cod..." | https://github.com/github/codeql-ruby |
| literals/literals.rb:2:1:2:3 | nil | nil |
| literals/literals.rb:3:1:3:3 | NIL | NIL |
| literals/literals.rb:3:1:3:3 | NIL | nil |
| literals/literals.rb:4:1:4:5 | false | false |
| literals/literals.rb:5:1:5:5 | FALSE | FALSE |
| literals/literals.rb:5:1:5:5 | FALSE | false |
| literals/literals.rb:6:1:6:4 | true | true |
| literals/literals.rb:7:1:7:4 | TRUE | TRUE |
| literals/literals.rb:7:1:7:4 | TRUE | true |
| literals/literals.rb:10:1:10:4 | 1234 | 1234 |
| literals/literals.rb:11:1:11:5 | 5_678 | 5_678 |
| literals/literals.rb:11:1:11:5 | 5_678 | 5678 |
| literals/literals.rb:12:1:12:1 | 0 | 0 |
| literals/literals.rb:13:1:13:5 | 0d900 | 0d900 |
| literals/literals.rb:16:1:16:6 | 0x1234 | 0x1234 |
| literals/literals.rb:17:1:17:10 | 0xdeadbeef | 0xdeadbeef |
| literals/literals.rb:18:1:18:11 | 0xF00D_face | 0xF00D_face |
| literals/literals.rb:21:1:21:4 | 0123 | 0123 |
| literals/literals.rb:22:1:22:5 | 0o234 | 0o234 |
| literals/literals.rb:23:1:23:6 | 0O45_6 | 0O45_6 |
| literals/literals.rb:26:1:26:10 | 0b10010100 | 0b10010100 |
| literals/literals.rb:27:1:27:11 | 0B011_01101 | 0B011_01101 |
| literals/literals.rb:13:1:13:5 | 0d900 | 0 |
| literals/literals.rb:16:1:16:6 | 0x1234 | 4660 |
| literals/literals.rb:21:1:21:4 | 0123 | 83 |
| literals/literals.rb:22:1:22:5 | 0o234 | 156 |
| literals/literals.rb:23:1:23:6 | 0O45_6 | 302 |
| literals/literals.rb:26:1:26:10 | 0b10010100 | 148 |
| literals/literals.rb:27:1:27:11 | 0B011_01101 | 109 |
| literals/literals.rb:30:1:30:5 | 12.34 | 12.34 |
| literals/literals.rb:31:1:31:7 | 1234e-2 | 1234e-2 |
| literals/literals.rb:32:1:32:7 | 1.234E1 | 1.234E1 |
| literals/literals.rb:35:1:35:3 | 23r | 23r |
| literals/literals.rb:36:1:36:5 | 9.85r | 9.85r |
| literals/literals.rb:39:1:39:2 | 2i | 2i |
| literals/literals.rb:31:1:31:7 | 1234e-2 | 12.34 |
| literals/literals.rb:32:1:32:7 | 1.234E1 | 12.34 |
| literals/literals.rb:35:1:35:3 | 23r | 23/1 |
| literals/literals.rb:36:1:36:5 | 9.85r | 985/100 |
| literals/literals.rb:39:1:39:2 | 2i | 0+2i |
| literals/literals.rb:46:1:46:2 | "" | |
| literals/literals.rb:47:1:47:2 | "" | |
| literals/literals.rb:48:1:48:7 | "hello" | hello |
@@ -633,7 +633,9 @@
| operations/operations.rb:20:5:20:5 | 0 | 0 |
| operations/operations.rb:23:2:23:2 | a | 0 |
| operations/operations.rb:24:5:24:5 | b | 0 |
| operations/operations.rb:25:1:25:3 | + ... | 14 |
| operations/operations.rb:25:2:25:3 | 14 | 14 |
| operations/operations.rb:26:1:26:2 | - ... | -7 |
| operations/operations.rb:26:2:26:2 | 7 | 7 |
| operations/operations.rb:27:2:27:2 | x | 0 |
| operations/operations.rb:28:10:28:12 | foo | 0 |
@@ -674,9 +676,9 @@
| operations/operations.rb:47:1:47:1 | y | 0 |
| operations/operations.rb:47:6:47:7 | 16 | 16 |
| operations/operations.rb:48:1:48:3 | foo | 0 |
| operations/operations.rb:48:7:48:10 | 0xff | 0xff |
| operations/operations.rb:48:7:48:10 | 0xff | 255 |
| operations/operations.rb:49:1:49:3 | bar | 0 |
| operations/operations.rb:49:7:49:10 | 0x02 | 0x02 |
| operations/operations.rb:49:7:49:10 | 0x02 | 2 |
| operations/operations.rb:50:1:50:3 | baz | 0 |
| operations/operations.rb:50:7:50:9 | qux | 0 |
| operations/operations.rb:53:1:53:1 | x | 0 |
@@ -724,7 +726,7 @@
| operations/operations.rb:82:8:82:8 | 3 | 3 |
| operations/operations.rb:83:9:83:12 | mask | 0 |
| operations/operations.rb:84:2:84:4 | bar | 0 |
| operations/operations.rb:84:9:84:12 | 0x01 | 0x01 |
| operations/operations.rb:84:9:84:12 | 0x01 | 1 |
| operations/operations.rb:85:2:85:4 | baz | 0 |
| operations/operations.rb:85:9:85:11 | qux | 0 |
| operations/operations.rb:88:8:88:8 | 1 | 1 |

View File

@@ -1,4 +1,4 @@
import ruby
from Expr e
select e, e.getValueText()
select e, e.getConstantValue()

View File

@@ -1,28 +1,28 @@
allLiterals
| literals.rb:2:1:2:3 | nil | NilLiteral | nil |
| literals.rb:3:1:3:3 | NIL | NilLiteral | NIL |
| literals.rb:3:1:3:3 | NIL | NilLiteral | nil |
| literals.rb:4:1:4:5 | false | BooleanLiteral | false |
| literals.rb:5:1:5:5 | FALSE | BooleanLiteral | FALSE |
| literals.rb:5:1:5:5 | FALSE | BooleanLiteral | false |
| literals.rb:6:1:6:4 | true | BooleanLiteral | true |
| literals.rb:7:1:7:4 | TRUE | BooleanLiteral | TRUE |
| literals.rb:7:1:7:4 | TRUE | BooleanLiteral | true |
| literals.rb:10:1:10:4 | 1234 | IntegerLiteral | 1234 |
| literals.rb:11:1:11:5 | 5_678 | IntegerLiteral | 5_678 |
| literals.rb:11:1:11:5 | 5_678 | IntegerLiteral | 5678 |
| literals.rb:12:1:12:1 | 0 | IntegerLiteral | 0 |
| literals.rb:13:1:13:5 | 0d900 | IntegerLiteral | 0d900 |
| literals.rb:16:1:16:6 | 0x1234 | IntegerLiteral | 0x1234 |
| literals.rb:17:1:17:10 | 0xdeadbeef | IntegerLiteral | 0xdeadbeef |
| literals.rb:18:1:18:11 | 0xF00D_face | IntegerLiteral | 0xF00D_face |
| literals.rb:21:1:21:4 | 0123 | IntegerLiteral | 0123 |
| literals.rb:22:1:22:5 | 0o234 | IntegerLiteral | 0o234 |
| literals.rb:23:1:23:6 | 0O45_6 | IntegerLiteral | 0O45_6 |
| literals.rb:26:1:26:10 | 0b10010100 | IntegerLiteral | 0b10010100 |
| literals.rb:27:1:27:11 | 0B011_01101 | IntegerLiteral | 0B011_01101 |
| literals.rb:13:1:13:5 | 0d900 | IntegerLiteral | 0 |
| literals.rb:16:1:16:6 | 0x1234 | IntegerLiteral | 4660 |
| literals.rb:17:1:17:10 | 0xdeadbeef | IntegerLiteral | <none> |
| literals.rb:18:1:18:11 | 0xF00D_face | IntegerLiteral | <none> |
| literals.rb:21:1:21:4 | 0123 | IntegerLiteral | 83 |
| literals.rb:22:1:22:5 | 0o234 | IntegerLiteral | 156 |
| literals.rb:23:1:23:6 | 0O45_6 | IntegerLiteral | 302 |
| literals.rb:26:1:26:10 | 0b10010100 | IntegerLiteral | 148 |
| literals.rb:27:1:27:11 | 0B011_01101 | IntegerLiteral | 109 |
| literals.rb:30:1:30:5 | 12.34 | FloatLiteral | 12.34 |
| literals.rb:31:1:31:7 | 1234e-2 | FloatLiteral | 1234e-2 |
| literals.rb:32:1:32:7 | 1.234E1 | FloatLiteral | 1.234E1 |
| literals.rb:35:1:35:3 | 23r | RationalLiteral | 23r |
| literals.rb:36:1:36:5 | 9.85r | RationalLiteral | 9.85r |
| literals.rb:39:1:39:2 | 2i | ComplexLiteral | 2i |
| literals.rb:31:1:31:7 | 1234e-2 | FloatLiteral | 12.34 |
| literals.rb:32:1:32:7 | 1.234E1 | FloatLiteral | 12.34 |
| literals.rb:35:1:35:3 | 23r | RationalLiteral | 23/1 |
| literals.rb:36:1:36:5 | 9.85r | RationalLiteral | 985/100 |
| literals.rb:39:1:39:2 | 2i | ComplexLiteral | 0+2i |
| literals.rb:46:1:46:2 | "" | StringLiteral | |
| literals.rb:47:1:47:2 | "" | StringLiteral | |
| literals.rb:48:1:48:7 | "hello" | StringLiteral | hello |
@@ -735,23 +735,23 @@ exclusiveRangeLiterals
| literals.rb:122:2:122:7 | _ ... _ |
numericLiterals
| literals.rb:10:1:10:4 | 1234 | IntegerLiteral | 1234 |
| literals.rb:11:1:11:5 | 5_678 | IntegerLiteral | 5_678 |
| literals.rb:11:1:11:5 | 5_678 | IntegerLiteral | 5678 |
| literals.rb:12:1:12:1 | 0 | IntegerLiteral | 0 |
| literals.rb:13:1:13:5 | 0d900 | IntegerLiteral | 0d900 |
| literals.rb:16:1:16:6 | 0x1234 | IntegerLiteral | 0x1234 |
| literals.rb:17:1:17:10 | 0xdeadbeef | IntegerLiteral | 0xdeadbeef |
| literals.rb:18:1:18:11 | 0xF00D_face | IntegerLiteral | 0xF00D_face |
| literals.rb:21:1:21:4 | 0123 | IntegerLiteral | 0123 |
| literals.rb:22:1:22:5 | 0o234 | IntegerLiteral | 0o234 |
| literals.rb:23:1:23:6 | 0O45_6 | IntegerLiteral | 0O45_6 |
| literals.rb:26:1:26:10 | 0b10010100 | IntegerLiteral | 0b10010100 |
| literals.rb:27:1:27:11 | 0B011_01101 | IntegerLiteral | 0B011_01101 |
| literals.rb:13:1:13:5 | 0d900 | IntegerLiteral | 0 |
| literals.rb:16:1:16:6 | 0x1234 | IntegerLiteral | 4660 |
| literals.rb:17:1:17:10 | 0xdeadbeef | IntegerLiteral | <none> |
| literals.rb:18:1:18:11 | 0xF00D_face | IntegerLiteral | <none> |
| literals.rb:21:1:21:4 | 0123 | IntegerLiteral | 83 |
| literals.rb:22:1:22:5 | 0o234 | IntegerLiteral | 156 |
| literals.rb:23:1:23:6 | 0O45_6 | IntegerLiteral | 302 |
| literals.rb:26:1:26:10 | 0b10010100 | IntegerLiteral | 148 |
| literals.rb:27:1:27:11 | 0B011_01101 | IntegerLiteral | 109 |
| literals.rb:30:1:30:5 | 12.34 | FloatLiteral | 12.34 |
| literals.rb:31:1:31:7 | 1234e-2 | FloatLiteral | 1234e-2 |
| literals.rb:32:1:32:7 | 1.234E1 | FloatLiteral | 1.234E1 |
| literals.rb:35:1:35:3 | 23r | RationalLiteral | 23r |
| literals.rb:36:1:36:5 | 9.85r | RationalLiteral | 9.85r |
| literals.rb:39:1:39:2 | 2i | ComplexLiteral | 2i |
| literals.rb:31:1:31:7 | 1234e-2 | FloatLiteral | 12.34 |
| literals.rb:32:1:32:7 | 1.234E1 | FloatLiteral | 12.34 |
| literals.rb:35:1:35:3 | 23r | RationalLiteral | 23/1 |
| literals.rb:36:1:36:5 | 9.85r | RationalLiteral | 985/100 |
| literals.rb:39:1:39:2 | 2i | ComplexLiteral | 0+2i |
| literals.rb:58:13:58:13 | 2 | IntegerLiteral | 2 |
| literals.rb:58:17:58:17 | 2 | IntegerLiteral | 2 |
| literals.rb:59:15:59:15 | 3 | IntegerLiteral | 3 |
@@ -804,17 +804,17 @@ numericLiterals
| literals.rb:146:14:146:14 | 1 | IntegerLiteral | 1 |
integerLiterals
| literals.rb:10:1:10:4 | 1234 | IntegerLiteral | 1234 |
| literals.rb:11:1:11:5 | 5_678 | IntegerLiteral | 5_678 |
| literals.rb:11:1:11:5 | 5_678 | IntegerLiteral | 5678 |
| literals.rb:12:1:12:1 | 0 | IntegerLiteral | 0 |
| literals.rb:13:1:13:5 | 0d900 | IntegerLiteral | 0d900 |
| literals.rb:16:1:16:6 | 0x1234 | IntegerLiteral | 0x1234 |
| literals.rb:17:1:17:10 | 0xdeadbeef | IntegerLiteral | 0xdeadbeef |
| literals.rb:18:1:18:11 | 0xF00D_face | IntegerLiteral | 0xF00D_face |
| literals.rb:21:1:21:4 | 0123 | IntegerLiteral | 0123 |
| literals.rb:22:1:22:5 | 0o234 | IntegerLiteral | 0o234 |
| literals.rb:23:1:23:6 | 0O45_6 | IntegerLiteral | 0O45_6 |
| literals.rb:26:1:26:10 | 0b10010100 | IntegerLiteral | 0b10010100 |
| literals.rb:27:1:27:11 | 0B011_01101 | IntegerLiteral | 0B011_01101 |
| literals.rb:13:1:13:5 | 0d900 | IntegerLiteral | 0 |
| literals.rb:16:1:16:6 | 0x1234 | IntegerLiteral | 4660 |
| literals.rb:17:1:17:10 | 0xdeadbeef | IntegerLiteral | <none> |
| literals.rb:18:1:18:11 | 0xF00D_face | IntegerLiteral | <none> |
| literals.rb:21:1:21:4 | 0123 | IntegerLiteral | 83 |
| literals.rb:22:1:22:5 | 0o234 | IntegerLiteral | 156 |
| literals.rb:23:1:23:6 | 0O45_6 | IntegerLiteral | 302 |
| literals.rb:26:1:26:10 | 0b10010100 | IntegerLiteral | 148 |
| literals.rb:27:1:27:11 | 0B011_01101 | IntegerLiteral | 109 |
| literals.rb:58:13:58:13 | 2 | IntegerLiteral | 2 |
| literals.rb:58:17:58:17 | 2 | IntegerLiteral | 2 |
| literals.rb:59:15:59:15 | 3 | IntegerLiteral | 3 |
@@ -867,10 +867,10 @@ integerLiterals
| literals.rb:146:14:146:14 | 1 | IntegerLiteral | 1 |
floatLiterals
| literals.rb:30:1:30:5 | 12.34 | FloatLiteral | 12.34 |
| literals.rb:31:1:31:7 | 1234e-2 | FloatLiteral | 1234e-2 |
| literals.rb:32:1:32:7 | 1.234E1 | FloatLiteral | 1.234E1 |
| literals.rb:31:1:31:7 | 1234e-2 | FloatLiteral | 12.34 |
| literals.rb:32:1:32:7 | 1.234E1 | FloatLiteral | 12.34 |
rationalLiterals
| literals.rb:35:1:35:3 | 23r | RationalLiteral | 23r |
| literals.rb:36:1:36:5 | 9.85r | RationalLiteral | 9.85r |
| literals.rb:35:1:35:3 | 23r | RationalLiteral | 23/1 |
| literals.rb:36:1:36:5 | 9.85r | RationalLiteral | 985/100 |
complexLiterals
| literals.rb:39:1:39:2 | 2i | ComplexLiteral | 2i |
| literals.rb:39:1:39:2 | 2i | ComplexLiteral | 0+2i |

View File

@@ -3,16 +3,16 @@ import ruby
query predicate allLiterals(Literal l, string pClass, string valueText) {
pClass = l.getAPrimaryQlClass() and
(
valueText = l.getValueText()
valueText = l.getConstantValue().toString()
or
not exists(l.getValueText()) and valueText = "<none>"
not exists(l.getConstantValue()) and valueText = "<none>"
)
}
query predicate stringlikeLiterals(StringlikeLiteral l, string valueText) {
valueText = l.getValueText()
valueText = l.getConstantValue().toString()
or
not exists(l.getValueText()) and valueText = "<none>"
not exists(l.getConstantValue()) and valueText = "<none>"
}
query predicate stringLiterals(StringLiteral l, string valueText) {

View File

@@ -1,9 +1,9 @@
import ruby
private string getValueText(MethodName m) {
result = m.getValueText()
result = m.getConstantValue().getString()
or
not exists(m.getValueText()) and result = "(none)"
not exists(m.getConstantValue()) and result = "(none)"
}
query predicate undef(UndefStmt u, int i, MethodName m, string name, string pClass) {

View File

@@ -10,7 +10,7 @@ class Conf extends DataFlow::Configuration {
Conf() { this = "Conf" }
override predicate isSource(DataFlow::Node src) {
src.asExpr().getExpr().(StringLiteral).getValueText() = "taint"
src.asExpr().getExpr().(StringLiteral).getConstantValue().isString("taint")
}
override predicate isSink(DataFlow::Node sink) {

View File

@@ -67,7 +67,7 @@ class Conf extends TaintTracking::Configuration {
Conf() { this = "FlowSummaries" }
override predicate isSource(DataFlow::Node src) {
src.asExpr().getExpr().(StringLiteral).getValueText() = "taint"
src.asExpr().getExpr().(StringLiteral).getConstantValue().isString("taint")
}
override predicate isSink(DataFlow::Node sink) {