Skip to content

Commit 2477a6a

Browse files
committed
Add comments to taint analysis.
1 parent 2ac4024 commit 2477a6a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/analyses/tutorials/taint.ml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let is_sink varinfo = Cil.hasAttribute "taint_sink" varinfo.vattr
1111
let is_source varinfo = Cil.hasAttribute "taint_source" varinfo.vattr
1212

1313

14-
(* Fake variable to handle returning from a function *)
14+
(** "Fake" variable to handle returning from a function *)
1515
let return_varinfo = dummyFunDec.svar
1616

1717
module Spec : Analyses.MCPSpec with module D = SetDomain.Make(CilType.Varinfo) and module C = Lattice.Unit =
@@ -25,6 +25,7 @@ struct
2525
(* We are context insensitive in this analysis *)
2626
let context _ _ = ()
2727

28+
(** Determines whether an expression [e] is tainted, given a [state]. *)
2829
let rec is_exp_tainted (state:D.t) (e:Cil.exp) = match e with
2930
(* Recurse over the structure in the expression, retruning true if any varinfo appearing in the expression is tainted *)
3031
| AddrOf v
@@ -46,6 +47,8 @@ struct
4647
false
4748

4849
(* transfer functions *)
50+
51+
(** Handles assignment of [rval] to [lval]. *)
4952
let assign ctx (lval:lval) (rval:exp) : D.t =
5053
match lval with
5154
| Var v,_ ->
@@ -55,19 +58,28 @@ struct
5558
D.remove v ctx.local
5659
| _ -> ctx.local
5760

61+
(** Handles conditional branching yielding truth value [tv]. *)
5862
let branch ctx (exp:exp) (tv:bool) : D.t =
63+
(* Nothing needs to be done *)
5964
ctx.local
6065

66+
(** Handles going from start node of function [f] into the function body of [f].
67+
Meant to handle e.g. initializiation of local variables. *)
6168
let body ctx (f:fundec) : D.t =
6269
(* Nothing needs to be done here, as the (non-formals) locals are initally untainted *)
6370
ctx.local
6471

72+
(** Handles the [return] statement, i.e. "return exp" or "return", in function [f]. *)
6573
let return ctx (exp:exp option) (f:fundec) : D.t =
6674
(* We add a fake variable to indicate the return value is tainted *)
6775
match exp with
6876
| Some e when is_exp_tainted ctx.local e -> D.add return_varinfo ctx.local
6977
| _ -> ctx.local
7078

79+
(** For a function call "lval = f(args)" or "f(args)",
80+
[enter] returns a caller state, and the inital state of the callee.
81+
In [enter], the caller state can ususally be return unchanged, as [combine] (below)
82+
will compute the caller state after the function call, given the return state of the callee. *)
7183
let enter ctx (lval: lval option) (f:fundec) (args:exp list) : (D.t * D.t) list =
7284
let caller_local = ctx.local in
7385
(* Create list of (formal, actual_exp)*)
@@ -76,12 +88,18 @@ struct
7688
(* first component is state of caller, second component is state of callee *)
7789
[caller_local, callee_state]
7890

91+
(** For a function call "lval = f(args)" or "f(args)",
92+
computes the state of the caller after the call.
93+
Argument [callee_local] is the state at the return node of [f]. *)
7994
let combine ctx (lval:lval option) fexp (f:fundec) (args:exp list) fc (callee_local:D.t) : D.t =
8095
let caller_local = ctx.local in
8196
match lval with
8297
| Some (Var v,_) when D.mem return_varinfo callee_local -> D.add v caller_local
8398
| _ -> caller_local
8499

100+
(** For a call to a _special_ function f "lval = f(args)" or "f(args)",
101+
computes the caller state after the function call.
102+
For this analysis, source and sink functions will be considered _special_ and have to be treated here. *)
85103
let special ctx (lval: lval option) (f:varinfo) (arglist:exp list) : D.t =
86104
(* here you should check if f is a sink / source and handle it appropriately *)
87105
if is_source f then

0 commit comments

Comments
 (0)