Skip to content

Commit 445223c

Browse files
shannonzhufacebook-github-bot
authored andcommitted
Remove leading underscore in __global_sink, __user_controlled, __tito
Summary: The naming convention for these test functions will break if we start handling private names correctly in classes, see docs on private name mangling: https://docs.python.org/3/reference/expressions.html?highlight=mangling At runtime, it's impossible to access a function named with a leading double underscore from inside a class: ``` >>> def __toplevel(x: int) -> int: ... return x ... >>> class Foo: ... def test(self): ... print(__toplevel(1)) ... >>> Foo().test() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in test NameError: name '_Foo__toplevel' is not defined ``` This diff is a no-op except adjusting the naming of these test helpers to lead with a single underscore instead. Reviewed By: grievejia Differential Revision: D30161410 fbshipit-source-id: 48d8120e198af61bf39671383c24bb1b444ad83e
1 parent 14db1a0 commit 445223c

File tree

12 files changed

+44
-44
lines changed

12 files changed

+44
-44
lines changed

source/interprocedural_analyses/taint/test/backwardAnalysisTest.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -927,20 +927,20 @@ let test_starred context =
927927
~context
928928
{|
929929
def sink_in_starred(arg):
930-
__tito( *[ 1, _test_sink(arg), "foo" ] )
930+
_tito( *[ 1, _test_sink(arg), "foo" ] )
931931

932932
def sink_in_starred_starred(arg):
933-
__tito( **{
933+
_tito( **{
934934
"a": 1,
935935
"b": _test_sink(arg),
936936
"c": "foo",
937937
})
938938

939939
def tito_in_starred(arg):
940-
return __tito( *[ 1, arg, "foo" ] )
940+
return _tito( *[ 1, arg, "foo" ] )
941941

942942
def tito_in_starred_starred(arg):
943-
return __tito( **{
943+
return _tito( **{
944944
"a": 1,
945945
"b": arg,
946946
"c": "foo",
@@ -1431,7 +1431,7 @@ let test_assignment context =
14311431
~context
14321432
{|
14331433
def assigns_to_sink(assigned_to_sink):
1434-
taint.__global_sink = assigned_to_sink
1434+
taint._global_sink = assigned_to_sink
14351435
|}
14361436
[
14371437
outcome

source/interprocedural_analyses/taint/test/fixpointTest.ml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ let test_fixpoint context =
4545
assert_fixpoint
4646
~context
4747
{|
48-
from builtins import _test_source, _test_sink, __user_controlled
48+
from builtins import _test_source, _test_sink, _user_controlled
4949
def bar():
5050
return _test_source()
5151

@@ -70,7 +70,7 @@ let test_fixpoint context =
7070
bad(x)
7171

7272
def rce_problem():
73-
x = __user_controlled()
73+
x = _user_controlled()
7474
eval(x)
7575

7676
class TestMethods:
@@ -112,11 +112,11 @@ let test_fixpoint context =
112112
list_sink(x)
113113

114114
def getattr_obj_no_match():
115-
obj = __user_controlled()
115+
obj = _user_controlled()
116116
getattr(obj, 'foo')
117117

118118
def getattr_field_match(some_obj):
119-
field = __user_controlled()
119+
field = _user_controlled()
120120
return getattr(some_obj, field)
121121

122122
def deep_tito(tito, no_tito):
@@ -125,11 +125,11 @@ let test_fixpoint context =
125125
return y
126126

127127
def test_deep_tito_no_match():
128-
obj = deep_tito(__user_controlled(), _test_source())
128+
obj = deep_tito(_user_controlled(), _test_source())
129129
getattr('obj', obj.f.g)
130130

131131
def test_deep_tito_match():
132-
obj = deep_tito(__user_controlled(), _test_source())
132+
obj = deep_tito(_user_controlled(), _test_source())
133133
getattr('obj', obj.g.f)
134134

135135
class Class:
@@ -287,10 +287,10 @@ let test_combined_analysis context =
287287
def qualifier.combined_model(x, y: TaintSink[Demo], z: TaintInTaintOut): ...
288288
|}
289289
{|
290-
from builtins import _test_sink, __user_controlled
290+
from builtins import _test_sink, _user_controlled
291291
def combined_model(x, y, z):
292292
_test_sink(x)
293-
return x or __user_controlled()
293+
return x or _user_controlled()
294294
|}
295295
~expect:
296296
{
@@ -320,10 +320,10 @@ let test_skipped_analysis context =
320320
def qualifier.skipped_model(x, y: TaintSink[Demo], z: TaintInTaintOut): ...
321321
|}
322322
{|
323-
from builtins import _test_sink, __user_controlled
323+
from builtins import _test_sink, _user_controlled
324324
def skipped_model(x, y, z):
325325
_test_sink(x)
326-
return x or __user_controlled()
326+
return x or _user_controlled()
327327
|}
328328
~expect:
329329
{
@@ -350,11 +350,11 @@ let test_sanitized_analysis context =
350350
def qualifier.sanitized_model(x, y: TaintSink[Demo], z: TaintInTaintOut): ...
351351
|}
352352
{|
353-
from builtins import _test_sink, __user_controlled
353+
from builtins import _test_sink, _user_controlled
354354
def sanitized_model(x, y, z):
355-
eval(__user_controlled())
355+
eval(_user_controlled())
356356
_test_sink(x)
357-
return x or __user_controlled()
357+
return x or _user_controlled()
358358
|}
359359
~expect:
360360
{
@@ -435,7 +435,7 @@ let test_overrides context =
435435
assert_fixpoint
436436
~context
437437
{|
438-
from builtins import _test_source, _test_sink, __user_controlled
438+
from builtins import _test_source, _test_sink, _user_controlled
439439
class Base:
440440
def split(self):
441441
pass
@@ -461,7 +461,7 @@ let test_overrides context =
461461

462462
class E(Base):
463463
def some_source(self):
464-
return __user_controlled()
464+
return _user_controlled()
465465

466466
def test_obscure_override(b: Base):
467467
return b.split()

source/interprocedural_analyses/taint/test/forwardAnalysisTest.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ let test_taint_in_taint_out_application context =
481481

482482
def taint_with_tito():
483483
y = simple_source()
484-
x = __tito(y)
484+
x = _tito(y)
485485
return x
486486
|}
487487
[outcome ~kind:`Function ~returns:[Sources.NamedSource "Test"] "qualifier.simple_source"];
@@ -867,15 +867,15 @@ let test_starred context =
867867
{|
868868
def source_in_starred():
869869
list = [ 1, _test_source(), "foo" ]
870-
return __tito( *list )
870+
return _tito( *list )
871871

872872
def source_in_starred_starred():
873873
dict = {
874874
"a": 1,
875875
"b": _test_source(),
876876
"c": "foo",
877877
}
878-
return __tito( **dict )
878+
return _tito( **dict )
879879
|}
880880
[
881881
outcome ~kind:`Function ~returns:[Sources.NamedSource "Test"] "qualifier.source_in_starred";

source/interprocedural_analyses/taint/test/integration/maximum_trace_length.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This source code is licensed under the MIT license found in the
44
# LICENSE file in the root directory of this source tree.
55

6-
from builtins import _test_sink, _test_source, __tito
6+
from builtins import _test_sink, _test_source, _tito
77

88

99
def source_distance_zero():
@@ -55,5 +55,5 @@ def issue_source_one_sink_two():
5555

5656

5757
def multi_sink(x):
58-
y = __tito(x, x.foo)
58+
y = _tito(x, x.foo)
5959
sink_distance_one(y)

source/interprocedural_analyses/taint/test/integration/maximum_trace_length.py.cg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ maximum_trace_length.issue_source_one_sink_two (fun) -> [maximum_trace_length.si
55
maximum_trace_length.issue_source_one_sink_zero (fun) -> [maximum_trace_length.sink_distance_zero (fun) maximum_trace_length.source_distance_one (fun)]
66
maximum_trace_length.issue_source_two_sink_one (fun) -> [maximum_trace_length.sink_distance_one (fun) maximum_trace_length.source_distance_two (fun)]
77
maximum_trace_length.issue_source_zero_sink_zero (fun) -> [maximum_trace_length.sink_distance_zero (fun) maximum_trace_length.source_distance_zero (fun)]
8-
maximum_trace_length.multi_sink (fun) -> [__tito (fun) maximum_trace_length.sink_distance_one (fun)]
8+
maximum_trace_length.multi_sink (fun) -> [_tito (fun) maximum_trace_length.sink_distance_one (fun)]
99
maximum_trace_length.sink_distance_one (fun) -> [maximum_trace_length.sink_distance_zero (fun)]
1010
maximum_trace_length.sink_distance_two (fun) -> [maximum_trace_length.sink_distance_one (fun)]
1111
maximum_trace_length.sink_distance_zero (fun) -> [_test_sink (fun)]

source/interprocedural_analyses/taint/test/integration/remote_code_execution.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# This source code is licensed under the MIT license found in the
44
# LICENSE file in the root directory of this source tree.
55

6-
from builtins import __user_controlled
6+
from builtins import _user_controlled
77

88

99
def rce_problem():
10-
x = __user_controlled()
10+
x = _user_controlled()
1111
eval(x)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
@generated
22
Call dependencies
3-
remote_code_execution.rce_problem (fun) -> [__user_controlled (fun) eval (fun)]
3+
remote_code_execution.rce_problem (fun) -> [_user_controlled (fun) eval (fun)]

source/interprocedural_analyses/taint/test/integration/remote_code_execution.py.models

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
"filename": "remote_code_execution.py",
2121
"line": 10,
2222
"start": 8,
23-
"end": 27
23+
"end": 26
2424
},
2525
"leaves": [
26-
{ "kind": "UserControlled", "name": "__user_controlled" }
26+
{ "kind": "UserControlled", "name": "_user_controlled" }
2727
]
2828
}
2929
]

source/interprocedural_analyses/taint/test/missingFlowsTest.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ let test_obscure context =
6060
def test_obscure.obscure(x): ...
6161
|}
6262
{|
63-
from builtins import _test_source, _test_sink, __user_controlled
63+
from builtins import _test_source, _test_sink, _user_controlled
6464

6565
def obscure(x): ...
6666

@@ -74,7 +74,7 @@ let test_obscure context =
7474
obscure(_test_source())
7575

7676
def user_controlled():
77-
return __user_controlled()
77+
return _user_controlled()
7878

7979
def indirect_issue():
8080
to_obscure_x(user_controlled(), 0)
@@ -134,7 +134,7 @@ let test_type context =
134134
~missing_flows:TaintConfiguration.Type
135135
~handle:"test_type.py"
136136
{|
137-
from builtins import _test_source, _test_sink, __user_controlled
137+
from builtins import _test_source, _test_sink, _user_controlled
138138

139139
def to_unknown_callee_x(x, y, f):
140140
f(x)
@@ -146,7 +146,7 @@ let test_type context =
146146
f(_test_source())
147147

148148
def user_controlled():
149-
return __user_controlled()
149+
return _user_controlled()
150150

151151
def indirect_issue(f):
152152
to_unknown_callee_x(user_controlled(), 0, f)

source/interprocedural_analyses/taint/test/testHelper.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,16 +338,16 @@ let run_with_taint_models tests ~name =
338338
{|
339339
def _test_sink(arg: TaintSink[Test, Via[special_sink]]): ...
340340
def _test_source() -> TaintSource[Test, Via[special_source]]: ...
341-
def __tito( *x: TaintInTaintOut, **kw: TaintInTaintOut): ...
341+
def _tito( *x: TaintInTaintOut, **kw: TaintInTaintOut): ...
342342
def eval(arg: TaintSink[RemoteCodeExecution]): ...
343-
def __user_controlled() -> TaintSource[UserControlled]: ...
343+
def _user_controlled() -> TaintSource[UserControlled]: ...
344344
def getattr(
345345
o: TaintInTaintOut[Via[object]],
346346
name: TaintSink[GetAttr],
347347
default: TaintInTaintOut[Via[default]] = ...,
348348
): ...
349349

350-
taint.__global_sink: TaintSink[Test] = ...
350+
taint._global_sink: TaintSink[Test] = ...
351351
ClassWithSinkAttribute.attribute: TaintSink[Test] = ...
352352

353353
def copy(obj: TaintInTaintOut[Via[copy]]): ...

0 commit comments

Comments
 (0)