Skip to content

Commit 2352cf7

Browse files
authored
QL: Merge pull request #114 from github/erik-krogh/consistency
fix the signature of regexpCapture and regexpFind
2 parents 8e6bc11 + ddc0ade commit 2352cf7

6 files changed

Lines changed: 26 additions & 3 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import codeql_ql.ast.internal.Builtins::BuildinsConsistency

ql/src/codeql_ql/ast/Ast.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class PredicateOrBuiltin extends TPredOrBuiltin, AstNode {
201201

202202
Type getReturnType() { none() }
203203

204-
int getArity() { result = count(this.getParameterType(_)) }
204+
int getArity() { result = count(int i | exists(this.getParameterType(i))) }
205205

206206
predicate isPrivate() { none() }
207207
}

ql/src/codeql_ql/ast/internal/Builtins.qll

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ predicate isBuiltinMember(string sig) {
3535
"string int.toString()", "string string.charAt(int)", "int string.indexOf(string)",
3636
"int string.indexOf(string, int, int)", "predicate string.isLowercase()",
3737
"predicate string.isUppercase()", "int string.length()", "predicate string.matches(string)",
38-
"string string.prefix(int)", "string regexpCapture(string, int)",
39-
"string regexpFind(string, int, int)", "predicate string.regexpMatch(string)",
38+
"string string.prefix(int)", "string string.regexpCapture(string, int)",
39+
"string string.regexpFind(string, int, int)", "predicate string.regexpMatch(string)",
4040
"string string.regexpReplaceAll(string, string)", "string string.replaceAll(string, string)",
4141
"string string.splitAt(string)", "string string.splitAt(string, int)",
4242
"string string.substring(int, int)", "string string.suffix(int)", "date string.toDate()",
@@ -58,6 +58,18 @@ predicate isBuiltinMember(string qual, string ret, string name, string args) {
5858
)
5959
}
6060

61+
module BuildinsConsistency {
62+
query predicate noBuildinParse(string sig) {
63+
isBuiltinMember(sig) and
64+
not exists(sig.regexpCapture("(\\w+) (\\w+)\\.(\\w+)\\(([\\w, ]*)\\)", _))
65+
}
66+
67+
query predicate noBuildinClasslessParse(string sig) {
68+
isBuiltinClassless(sig) and
69+
not exists(sig.regexpCapture("(\\w+) (\\w+)\\(([\\w, ]*)\\)", _))
70+
}
71+
}
72+
6173
bindingset[args]
6274
string getArgType(string args, int i) { result = args.splitAt(",", i).trim() }
6375

ql/test/callgraph/Foo.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ module Aliases {
3131
alias0() // <- works
3232
}
3333
}
34+
35+
module Buildins {
36+
predicate replaceAll(string s) { "foo".replaceAll("foo", "bar") = s }
37+
38+
predicate regexpCapture(string s) { "foo".regexpCapture("\\w", 1) = s }
39+
}

ql/test/callgraph/callgraph.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
| Foo.qll:29:5:29:16 | PredicateCall | Foo.qll:26:3:26:32 | ClasslessPredicate alias2 |
77
| Foo.qll:31:5:31:12 | PredicateCall | Foo.qll:22:3:22:32 | ClasslessPredicate myThing0 |
88
| Foo.qll:31:5:31:12 | PredicateCall | Foo.qll:24:3:24:32 | ClasslessPredicate alias0 |
9+
| Foo.qll:36:36:36:65 | MemberCall | file://:0:0:0:0 | replaceAll |
10+
| Foo.qll:38:39:38:67 | MemberCall | file://:0:0:0:0 | regexpCapture |

ql/test/printAst/printAst.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ nodes
220220
| file://:0:0:0:0 | none | semmle.label | [BuiltinPredicate] none |
221221
| file://:0:0:0:0 | pow | semmle.label | [BuiltinPredicate] pow |
222222
| file://:0:0:0:0 | prefix | semmle.label | [BuiltinPredicate] prefix |
223+
| file://:0:0:0:0 | regexpCapture | semmle.label | [BuiltinPredicate] regexpCapture |
224+
| file://:0:0:0:0 | regexpFind | semmle.label | [BuiltinPredicate] regexpFind |
223225
| file://:0:0:0:0 | regexpMatch | semmle.label | [BuiltinPredicate] regexpMatch |
224226
| file://:0:0:0:0 | regexpReplaceAll | semmle.label | [BuiltinPredicate] regexpReplaceAll |
225227
| file://:0:0:0:0 | replaceAll | semmle.label | [BuiltinPredicate] replaceAll |

0 commit comments

Comments
 (0)