"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "interprocedural_analyses/taint/callGraphBuilder.ml" between
pyre-check-0.0.54.tar.gz and pyre-check-0.0.55.tar.gz

About: Pyre is a performant type checker for Python (ships with Pysa, a security focused static analysis tool).

callGraphBuilder.ml  (pyre-check-0.0.54):callGraphBuilder.ml  (pyre-check-0.0.55)
skipping to change at line 20 skipping to change at line 20
open Analysis open Analysis
open Ast open Ast
module DefaultBuilder = Callgraph.DefaultBuilder module DefaultBuilder = Callgraph.DefaultBuilder
let property_setter_table = Location.WithModule.Table.create () let property_setter_table = Location.WithModule.Table.create ()
let initialize () = let initialize () =
DefaultBuilder.initialize (); DefaultBuilder.initialize ();
Hashtbl.clear property_setter_table Hashtbl.clear property_setter_table
let add_callee ~global_resolution ~target ~callables ~arguments ~dynamic ~qualif let add_callee
ier ~callee = ~global_resolution
~target
~callables
~arguments
~dynamic
~qualifier
~callee_type
~callee
=
let resolution = let resolution =
Analysis.TypeCheck.resolution Analysis.TypeCheck.resolution
global_resolution global_resolution
(* TODO(T65923817): Eliminate the need of creating a dummy context here *) (* TODO(T65923817): Eliminate the need of creating a dummy context here *)
(module TypeCheck.DummyContext) (module TypeCheck.DummyContext)
in in
(* Add argument callables. *) (* Add argument callables. *)
let () = let () =
let add_callables_of_argument argument = let add_callables_of_argument argument =
let callable_and_implicit = let callable_and_implicit =
skipping to change at line 51 skipping to change at line 60
in in
match callable_and_implicit with match callable_and_implicit with
| Some (callable, implicit) -> | Some (callable, implicit) ->
DefaultBuilder.add_callee DefaultBuilder.add_callee
~global_resolution ~global_resolution
~target:implicit ~target:implicit
~callables:(Some [callable]) ~callables:(Some [callable])
~arguments ~arguments
~dynamic:false ~dynamic:false
~qualifier ~qualifier
~callee_type
~callee:argument.Expression.Call.Argument.value ~callee:argument.Expression.Call.Argument.value
| _ -> () | _ -> ()
in in
List.iter arguments ~f:add_callables_of_argument List.iter arguments ~f:add_callables_of_argument
in in
let callables = let callables =
match match
Interprocedural.CallResolution.transform_special_calls Interprocedural.CallResolution.transform_special_calls
~resolution ~resolution
{ Expression.Call.callee; arguments } { Expression.Call.callee; arguments }
skipping to change at line 73 skipping to change at line 83
begin begin
match Resolution.resolve_expression_to_type resolution transformed_cal l with match Resolution.resolve_expression_to_type resolution transformed_cal l with
| Type.Callable callable -> | Type.Callable callable ->
DefaultBuilder.add_callee DefaultBuilder.add_callee
~global_resolution ~global_resolution
~target:None ~target:None
~callables:(Some [callable]) ~callables:(Some [callable])
~arguments:transformed_arguments ~arguments:transformed_arguments
~dynamic:false ~dynamic:false
~qualifier ~qualifier
~callee_type
~callee:transformed_call ~callee:transformed_call
(* Some callables are decorated with a decorator that transforms them to a class that (* Some callables are decorated with a decorator that transforms them to a class that
stores & calls the callable opaquely. From Pysa's perspective, the type of the callable stores & calls the callable opaquely. From Pysa's perspective, the type of the callable
is now `DecoratedClass`, and since we normally rely on the callable type to keep the is now `DecoratedClass`, and since we normally rely on the callable type to keep the
target names around, this means that we will no longer have an accu rate call graph. target names around, this means that we will no longer have an accu rate call graph.
The SpecialCallResolution has a contract that it'll transform calla bles into the The SpecialCallResolution has a contract that it'll transform calla bles into the
underlying callable name for a small, special set of targets, so if we're in this case, underlying callable name for a small, special set of targets, so if we're in this case,
we make the angelic assumption that the base expression has a 1:1 m atch to the actual we make the angelic assumption that the base expression has a 1:1 m atch to the actual
callable that Pysa models. *) callable that Pysa models. *)
skipping to change at line 113 skipping to change at line 124
{ {
Type.Callable.annotation = Type.Any; Type.Callable.annotation = Type.Any;
parameters = Type.Callable.Undefined; parameters = Type.Callable.Undefined;
}; };
overloads = []; overloads = [];
}; };
]) ])
~arguments:transformed_arguments ~arguments:transformed_arguments
~dynamic:false ~dynamic:false
~qualifier ~qualifier
~callee_type
~callee:transformed_call ~callee:transformed_call
| _ -> () ) | _ -> () )
| _ -> () | _ -> ()
end; end;
callables callables
| None -> ( | None -> (
match target, callables with match target, callables with
| Some parent, Some ([{ Type.Callable.kind = Named name; _ }] as callabl es) | Some parent, Some ([{ Type.Callable.kind = Named name; _ }] as callabl es)
when String.equal (Reference.last name) "__init__" -> ( when String.equal (Reference.last name) "__init__" -> (
(* If we've added a __init__ call, it originates from a constructor. Search for __new__ (* If we've added a __init__ call, it originates from a constructor. Search for __new__
skipping to change at line 139 skipping to change at line 151
(Expression.Expression.Name (Expression.Expression.Name
(Expression.Name.Attribute (Expression.Name.Attribute
{ {
Expression.Name.Attribute.base = Type.expression parent ; Expression.Name.Attribute.base = Type.expression parent ;
attribute = "__new__"; attribute = "__new__";
special = false; special = false;
}))) })))
|> function |> function
| Type.Callable callable -> Some (callable :: callables) | Type.Callable callable -> Some (callable :: callables)
| _ -> Some callables ) | _ -> Some callables )
| _, Some [({ Type.Callable.kind = Anonymous; _ } as callable)] ->
(* TODO(T66895305): The names of callable protocol callables aren't
propagated
currently, reconstruct them. *)
if
Option.is_some
(GlobalResolution.attribute_from_annotation
~special_method:true
global_resolution
~parent:callee_type
~name:"__call__")
then
Type.primitive_name callee_type
>>| fun parent ->
[
{
callable with
Type.Callable.kind =
Named (Reference.create ~prefix:(Reference.create parent) "_
_call__");
};
]
else
Some [callable]
| _ -> callables ) | _ -> callables )
in in
DefaultBuilder.add_callee DefaultBuilder.add_callee
~global_resolution ~global_resolution
~target ~target
~callables ~callables
~arguments ~arguments
~dynamic ~dynamic
~qualifier ~qualifier
~callee_type
~callee ~callee
let add_property_callees ~global_resolution ~resolved_base ~attributes ~name ~qu alifier ~location = let add_property_callees ~global_resolution ~resolved_base ~attributes ~name ~qu alifier ~location =
DefaultBuilder.add_property_callees DefaultBuilder.add_property_callees
~global_resolution ~global_resolution
~resolved_base ~resolved_base
~attributes ~attributes
~name ~name
~qualifier ~qualifier
~location ~location
 End of changes. 6 change blocks. 
2 lines changed or deleted 38 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)