Skip to content

Commit 35fa5d8

Browse files
committed
Python move various theXXX() predicates into the appropriate module.
1 parent 2dea0b4 commit 35fa5d8

30 files changed

+211
-126
lines changed

python/ql/src/Exceptions/EmptyExcept.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ predicate subscript(Stmt s) {
6767
predicate encode_decode(Expr ex, ClassObject type) {
6868
exists(string name |
6969
ex.(Call).getFunc().(Attribute).getName() = name |
70-
name = "encode" and type = builtin_object("UnicodeEncodeError")
70+
name = "encode" and type = Object::builtin("UnicodeEncodeError")
7171
or
72-
name = "decode" and type = builtin_object("UnicodeDecodeError")
72+
name = "decode" and type = Object::builtin("UnicodeDecodeError")
7373
)
7474
}
7575

python/ql/src/Exceptions/NotImplemented.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import python
33

44
/** Holds if `notimpl` refers to `NotImplemented` or `NotImplemented()` in the `raise` statement */
55
predicate use_of_not_implemented_in_raise(Raise raise, Expr notimpl) {
6-
notimpl.refersTo(theNotImplementedObject()) and
6+
notimpl.refersTo(Object::notImplemented()) and
77
(
8-
notimpl = raise.getException() or
8+
notimpl = raise.getException() or
99
notimpl = raise.getException().(Call).getFunc()
1010
)
1111
}

python/ql/src/Exceptions/UnguardedNextInGenerator.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
import python
1414

1515
FunctionObject iter() {
16-
result = builtin_object("iter")
16+
result = Object::builtin("iter")
1717
}
1818

1919
FunctionObject next() {
20-
result = builtin_object("next")
20+
result = Object::builtin("next")
2121
}
2222

2323
predicate call_to_iter(CallNode call, EssaVariable sequence) {

python/ql/src/Expressions/Formatting/AdvancedFormatting.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private predicate brace_pair(PossibleAdvancedFormatString fmt, int start, int en
107107
private predicate advanced_format_call(Call format_expr, PossibleAdvancedFormatString fmt, int args) {
108108
exists(CallNode call |
109109
call = format_expr.getAFlowNode() |
110-
call.getFunction().refersTo(theFormatFunction()) and call.getArg(0).refersTo(_, fmt.getAFlowNode()) and
110+
call.getFunction().refersTo(BuiltinFunctionObject::format()) and call.getArg(0).refersTo(_, fmt.getAFlowNode()) and
111111
args = count(format_expr.getAnArg()) - 1
112112
or
113113
call.getFunction().(AttrNode).getObject("format").refersTo(_, fmt.getAFlowNode()) and

python/ql/src/Expressions/UseofApply.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ import python
1313

1414
from CallNode call, ControlFlowNode func
1515
where
16-
major_version() = 2 and call.getFunction() = func and func.refersTo(theApplyFunction())
16+
major_version() = 2 and call.getFunction() = func and func.refersTo(BuiltinFunctionObject::apply())
1717
select call, "Call to the obsolete builtin function 'apply'."

python/ql/src/Expressions/UseofInput.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ import python
1414

1515
from CallNode call, Context context, ControlFlowNode func
1616
where
17-
context.getAVersion().includes(2, _) and call.getFunction() = func and func.refersTo(context, theInputFunction(), _, _)
17+
context.getAVersion().includes(2, _) and call.getFunction() = func and func.refersTo(context, BuiltinFunctionObject::input(), _, _)
1818
select call, "The unsafe built-in function 'input' is used."

python/ql/src/Functions/IncorrectRaiseInSpecialMethod.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ predicate correct_raise(string name, ClassObject ex) {
7070
predicate preferred_raise(string name, ClassObject ex) {
7171
attribute_method(name) and ex = theAttributeErrorType()
7272
or
73-
indexing_method(name) and ex = builtin_object("LookupError")
73+
indexing_method(name) and ex = Object::builtin("LookupError")
7474
or
7575
ordering_method(name) and ex = theTypeErrorType()
7676
or
77-
arithmetic_method(name) and ex = builtin_object("ArithmeticError")
77+
arithmetic_method(name) and ex = Object::builtin("ArithmeticError")
7878
}
7979

8080
predicate no_need_to_raise(string name, string message) {

python/ql/src/Resources/FileOpen.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ predicate function_should_close_parameter(Function func) {
128128
}
129129

130130
predicate function_opens_file(FunctionObject f) {
131-
f = theOpenFunction()
131+
f = BuiltinFunctionObject::open()
132132
or
133133
exists(EssaVariable v, Return ret |
134134
ret.getScope() = f.getFunction() |

python/ql/src/Security/CWE-798/HardcodedCredentials.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ predicate possible_reflective_name(string name) {
4242
or
4343
any(ModuleObject m).getName() = name
4444
or
45-
exists(builtin_object(name))
45+
exists(Object::builtin(name))
4646
}
4747

4848
int char_count(StrConst str) {

python/ql/src/Statements/RedundantAssignment.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ predicate maybe_defined_in_outer_scope(Name n) {
3939
}
4040

4141
Variable relevant_var(Name n) {
42-
n.getVariable() = result and
43-
(corresponding(n, _) or corresponding(_, n))
42+
n.getVariable() = result and
43+
(corresponding(n, _) or corresponding(_, n))
4444
}
4545

4646
predicate same_name(Name n1, Name n2) {
4747
corresponding(n1, n2) and
4848
relevant_var(n1) = relevant_var(n2) and
49-
not exists(builtin_object(n1.getId())) and
49+
not exists(Object::builtin(n1.getId())) and
5050
not maybe_defined_in_outer_scope(n2)
5151
}
5252

0 commit comments

Comments
 (0)