[classloads] restrict loads via fields

Reviewed By: ezgicicek

Differential Revision: D13817232

fbshipit-source-id: 470d5ce11
master
Nikos Gorogiannis 6 years ago committed by Facebook Github Bot
parent a8c946f1d9
commit c1a00b2358

@ -7,11 +7,19 @@
open! IStd open! IStd
module L = Logging module L = Logging
(* Sources: Java Virtual Machine Specification
- Chapter 5. Loading, Linking and Initializing
- Chapter 6. The Java Virtual Machine Instruction Set
*)
(* TODO (* TODO
- Casts - Casts (checkcast)
- Const literals for class objects? - instanceof
- Const literals for class objects? (ldc / ldc_w)
- catch / throw with exception classes - catch / throw with exception classes
*) - sync(class object)
- multidimensional arrays (multinewarray) ?
*)
module Payload = SummaryPayload.Make (struct module Payload = SummaryPayload.Make (struct
type t = ClassLoadsDomain.summary type t = ClassLoadsDomain.summary
@ -58,9 +66,8 @@ let add_type proc_desc tenv loc typ astate =
let rec add_loads_of_exp proc_desc tenv loc (exp : Exp.t) (typ : Typ.t) astate = let rec add_loads_of_exp proc_desc tenv loc (exp : Exp.t) (typ : Typ.t) astate =
match exp with match exp with
| Lvar _ ->
add_type proc_desc tenv loc typ astate
| Sizeof {typ= {desc= Tarray {elt}}} -> | Sizeof {typ= {desc= Tarray {elt}}} ->
(* anewarray *)
add_type proc_desc tenv loc elt astate add_type proc_desc tenv loc elt astate
| Cast (_, e) | UnOp (_, e, _) | Exn e -> | Cast (_, e) | UnOp (_, e, _) | Exn e ->
add_loads_of_exp proc_desc tenv loc e typ astate add_loads_of_exp proc_desc tenv loc e typ astate
@ -68,14 +75,16 @@ let rec add_loads_of_exp proc_desc tenv loc (exp : Exp.t) (typ : Typ.t) astate =
add_loads_of_exp proc_desc tenv loc e1 typ astate add_loads_of_exp proc_desc tenv loc e1 typ astate
|> add_loads_of_exp proc_desc tenv loc e2 typ |> add_loads_of_exp proc_desc tenv loc e2 typ
| Lfield (e, _, typ') -> | Lfield (e, _, typ') ->
add_loads_of_exp proc_desc tenv loc e typ' astate (* getfield / getstatic / putfield / putstatic *)
| Var _ | Const _ | Closure _ | Sizeof _ | Lindex _ -> add_type proc_desc tenv loc typ' astate |> add_loads_of_exp proc_desc tenv loc e typ'
| Var _ | Const _ | Closure _ | Sizeof _ | Lindex _ | Lvar _ ->
astate astate
let exec_instr pdesc tenv astate _ (instr : Sil.instr) = let exec_instr pdesc tenv astate _ (instr : Sil.instr) =
match instr with match instr with
| Call (_, Const (Cfun callee), args, loc, _) -> | Call (_, Const (Cfun callee), args, loc, _) ->
(* invokeinterface / invokespecial / invokestatic / invokevirtual / new *)
List.fold args ~init:astate ~f:(fun acc (exp, typ) -> List.fold args ~init:astate ~f:(fun acc (exp, typ) ->
add_loads_of_exp pdesc tenv loc exp typ acc ) add_loads_of_exp pdesc tenv loc exp typ acc )
|> do_call pdesc callee loc |> do_call pdesc callee loc

@ -0,0 +1,41 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
class Fields {
FieldsA a;
Fields() {
a = new FieldsA();
}
void foo() {
System.out.println(a.b.c);
}
public static void main(String args[]) {
Fields f = new Fields();
f.foo();
}
}
class FieldsA {
FieldsA() {
b = new FieldsB();
}
FieldsB b;
}
class FieldsB {
FieldsB() {
c = null;
}
FieldsCNoLoad c;
}
class FieldsCNoLoad {}

@ -22,10 +22,10 @@ class StaticA {
class StaticB { class StaticB {
// no load here // no load here
static StaticC c = null; static StaticCNoLoad c = null;
} }
class StaticC {} class StaticCNoLoad {}
class StaticD { class StaticD {
static int static_data = 5; static int static_data = 5;

Loading…
Cancel
Save