From 0938564084d12cdc9dab56851df0f1f471b15d09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Tavares?= Date: Mon, 15 Jul 2024 17:29:07 +0100 Subject: [PATCH] configuration file --- .gitignore | 2 + README.md | 3 +- bin/dune | 10 +- bin/main.ml | 47 +++- config.json | 264 ++++++++++++++++++ graphjs-results/code/normalized.js | 7 + graphjs-results/graph/graph.svg | 211 ++++++++++++++ graphjs-results/graph/graph_stats.json | 1 + graphjs-results/graph/nodes.csv | 13 + graphjs-results/graph/rels.csv | 19 ++ lib/mdg/analyse.ml | 90 +++--- lib/mdg/structures/config.ml | 114 ++++++++ lib/mdg/structures/state.ml | 16 +- .../cram/array-expressions.t/run.t | 6 +- .../cram/arrow-function-expressions.t/run.t | 10 +- .../cram/assignment-expressions.t/run.t | 2 +- .../cram/await-expressions.t/run.t | 6 +- .../cram/binary-expressions.t/run.t | 8 +- .../cram/call-expressions.t/run.t | 8 +- .../cram/class-declarations.t/run.t | 6 +- .../cram/class-expressions.t/run.t | 6 +- test/normalization/cram/conditionals.t/run.t | 8 +- .../normalization/cram/for-statements.t/run.t | 12 +- .../cram/function-declarations.t/run.t | 10 +- .../cram/function-expressions.t/run.t | 4 +- test/normalization/cram/if-statements.t/run.t | 8 +- .../cram/labeled-statements.t/run.t | 6 +- test/normalization/cram/literals.t/run.t | 8 +- .../cram/logical-expressions.t/run.t | 10 +- .../cram/member-expressions.t/run.t | 4 +- .../cram/new-expressions.t/run.t | 2 +- .../cram/object-expressions.t/run.t | 16 +- test/normalization/cram/rest-elements.t/run.t | 14 +- .../cram/sequence-expressions.t/run.t | 6 +- .../cram/spread-elements.t/run.t | 4 +- .../cram/switch-statements.t/run.t | 20 +- .../cram/template-expressions.t/run.t | 12 +- .../normalization/cram/try-statements.t/run.t | 8 +- .../cram/unary-expressions.t/run.t | 6 +- .../cram/variable-declarations.t/run.t | 8 +- .../cram/while-statements.t/run.t | 12 +- .../cram/yield-expressions.t/run.t | 4 +- 42 files changed, 852 insertions(+), 179 deletions(-) create mode 100644 config.json create mode 100644 graphjs-results/code/normalized.js create mode 100644 graphjs-results/graph/graph.svg create mode 100644 graphjs-results/graph/graph_stats.json create mode 100644 graphjs-results/graph/nodes.csv create mode 100644 graphjs-results/graph/rels.csv create mode 100644 lib/mdg/structures/config.ml diff --git a/.gitignore b/.gitignore index a48a64c..73e3458 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,5 @@ setup.log # Local OPAM switch _opam/ + +package-lock.json diff --git a/README.md b/README.md index e2de4c1..54534e6 100644 --- a/README.md +++ b/README.md @@ -20,5 +20,6 @@ opam install . --deps-only --with-test ```shell-session dune build -dune runtest +dune test +dune install ``` diff --git a/bin/dune b/bin/dune index 275427b..8998988 100644 --- a/bin/dune +++ b/bin/dune @@ -1,4 +1,12 @@ (executable (public_name ast_gen) (name main) - (libraries auxiliary ast mdg cmdliner)) \ No newline at end of file + (libraries auxiliary ast mdg cmdliner) +) + +(install + (section lib) + (files + (../config.json as config.json) + ) +) \ No newline at end of file diff --git a/bin/main.ml b/bin/main.ml index eced887..9368fd0 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1,24 +1,22 @@ open Cmdliner -let main (filename : string) (output_path : string) (verbose : bool) (generate_mdg : bool) : int = +let rec main (filename : string) (output_path : string) (config_path : string) (_multifile : bool) (generate_mdg : bool) (verbose : bool) : int = let filename = Auxiliary.File_system.real_path filename in (* STEP 0 : Generate AST using Flow library *) match Auxiliary.Js_parser.from_file filename with | Ok ast -> (* create output fs structure *) - let graph_dir = output_path ^ "/graph/" in - let run_dir = output_path ^ "/run/" in - Auxiliary.File_system.create_dir graph_dir; - Auxiliary.File_system.create_dir run_dir; + let code_dir, graph_dir, _ = setup_output output_path in (* STEP 1 : Normalize AST *) let norm_program = Ast.Normalize.program ast filename in let js_program = Ast.Pp.Js.print norm_program in - Auxiliary.File_system.write_to_file (graph_dir ^ "normalized.js") js_program; + Auxiliary.File_system.write_to_file (code_dir ^ "normalized.js") js_program; (* STEP 2 : Generate MDG for the normalized code *) if generate_mdg then ( - let graph = Mdg.Analyse.program verbose norm_program in + let config = Mdg.Config.read config_path in + let graph = Mdg.Analyse.program verbose config norm_program in Mdg.Pp.Dot.output graph_dir graph; Mdg.Pp.CSV.output graph_dir graph ); @@ -28,29 +26,48 @@ let main (filename : string) (output_path : string) (verbose : bool) (generate_m Format.eprintf "%s@." msg; 1 +and setup_output (output_path : string) : (string * string * string) = + let code_dir = output_path ^ "/code/" in + let graph_dir = output_path ^ "/graph/" in + let run_dir = output_path ^ "/run/" in + Auxiliary.File_system.create_dir code_dir; + Auxiliary.File_system.create_dir graph_dir; + Auxiliary.File_system.create_dir run_dir; + + code_dir, graph_dir, run_dir + (* setup comand line interface using CMDLiner library*) let input_file : string Term.t = - let doc = "" in + let doc = "Path to JavaScript file (.js) or directory containing JavaScript files for analysis." in let docv = "FILE" in Arg.(required & pos 0 (some non_dir_file) None & info [] ~doc ~docv) -let verbose : bool Term.t = - let doc = "Enable verbose mode" in - Arg.(value & flag & info ["v"; "verbose"] ~doc) +let multifile : bool Term.t = + let doc = "Analysis of a file and its dependencies instead of a single file." in + Arg.(value & flag & info ["m"; "multifile"] ~doc) let mdg : bool Term.t = - let doc = "Generate mdg" in + let doc = "Generates Multiversion Dependency Graph." in Arg.(value & flag & info ["mdg"] ~doc) let output_path : string Term.t = - let doc = "Output folder path" in + let doc = "Path to store all output files." in let default_path = "graphjs-results" in - Arg.(value & opt string default_path & info ["o"] ~doc) + Arg.(value & opt string default_path & info ["o"; "output"] ~doc) + +let config_path : string Term.t = + let doc = "Path to configuration file." in + let default_path = "config.json" in + Arg.(value & opt non_dir_file default_path & info ["c"; "config"] ~doc) + +let verbose : bool Term.t = + let doc = "Verbose mode." in + Arg.(value & flag & info ["v"; "verbose"] ~doc) let cli = - let cmd = Term.(const main $ input_file $ output_path $ verbose $ mdg) in + let cmd = Term.(const main $ input_file $ output_path $ config_path $ multifile $ mdg $ verbose) in let info = Cmd.info "ast_gen" in Cmd.v info cmd diff --git a/config.json b/config.json new file mode 100644 index 0000000..353f2c0 --- /dev/null +++ b/config.json @@ -0,0 +1,264 @@ +{ + "sinks": { + "code-injection": [ + { + "sink": "eval", + "type": "function", + "args": [ 1 ] + }, + { + "sink": "Function", + "type": "function", + "args": [ 1, 2, 3, 4 ] + }, + { + "sink": "require", + "type": "function", + "args": [ 1 ] + }, + { + "sink": "Function", + "type": "new", + "args": [ 1, 2, 3, 4 ] + }, + { + "sink": "runInContext", + "type": "package", + "packages": [ + {"package": "vm", "args": [ 1 ]} + ] + }, + { + "sink": "runInNewContext", + "type": "package", + "packages": [ + {"package": "vm", "args": [ 1 ]} + ] + }, + { + "sink": "default", + "type": "package", + "packages": [ + {"package": "gray-matter", "args": [ 1 ]} + ] + } + ], + "command-injection": [ + { + "sink": "exec", + "type": "package", + "packages": [ + {"package": "child_process", "args": [ 1 ]}, + {"package": "mz/child_process", "args": [ 1 ]}, + {"package": "shelljs", "args": [ 1 ]}, + {"package": "platform-command", "args": [ 1 ]} + ] + }, + { + "sink": "execSync", + "type": "package", + "packages": [ + {"package": "child_process", "args": [ 1 ]} + ] + }, + { + "sink": "execAsync", + "type": "package", + "packages": [ + {"package": "async-execute", "args": [ 1 ]} + ] + }, + { + "sink": "execFile", + "type": "package", + "packages": [ + {"package": "child_process", "args": [ 1, 2 ]} + ] + }, + { + "sink": "shell", + "type": "package", + "packages": [ + {"package": "execa", "args": [ 1 ]} + ] + }, + { + "sink": "spawn", + "type": "package", + "packages": [ + {"package": "child_process", "args": [ 1, 2 ]} + ] + }, + { + "sink": "write", + "type": "package", + "packages": [ + {"package": "comandante", "args": [ 1 ]} + ] + }, + { + "sink": "cross-spawn", + "type": "function", + "args": [ 1, 2 ] + }, + { + "sink": "im-metadata", + "type": "function", + "args": [ 1 ] + }, + { + "sink": "meta-exec", + "type": "function", + "args": [ 1 ] + } + ], + "path-traversal": [ + { + "sink": "readFile", + "type": "package", + "packages": [ + {"package": "fs", "args": [ 1 ]} + ] + }, + { + "sink": "readFileSync", + "type": "package", + "packages": [ + {"package": "fs", "args": [ 1 ]} + ] + }, + { + "sink": "writeFile", + "type": "package", + "packages": [ + {"package": "fs", "args": [ 1 ]} + ] + }, + { + "sink": "writeFileSync", + "type": "package", + "packages": [ + {"package": "fs", "args": [ 1 ]} + ] + }, + { + "sink": "createReadStream", + "type": "package", + "packages": [ + {"package": "fs", "args": [ 1 ]} + ] + } + ] + }, + "sources": [ + { + "source": "argv", + "type": "package", + "packages": [ + {"package": "process", "args": [ 0 ]}, + {"package": "yargs", "args": [ 0 ]} + ] + } + ], + "functions-signatures": { + "normalize": { + "package": "path", + "args_types": ["string"] + }, + "join": { + "package": "path", + "args_types": ["string"], + "rest?": true + }, + "resolve": { + "package": "path", + "args_types": ["string"], + "rest?": true + }, + "isAbsolute": { + "package": "path", + "args_types": ["string"] + }, + "relative": { + "package": "path", + "args_types": ["string", "string"] + }, + "dirname": { + "package": "path", + "args_types": ["string"] + }, + "basename": { + "package": "path", + "args_types": ["string", "string"] + }, + "extname": { + "package": "path", + "args_types": ["string"] + }, + "parse": { + "package": "path", + "args_types": ["string"] + }, + "format": { + "package": "path", + "args_types": ["Object"] + } + }, + "prototypes": { + "array": [ + "concat", + "every", + "filter", + "find", + "findIndex", + "forEach", + "includes", + "indexOf", + "join", + "lastIndexOf", + "map", + "pop", + "push", + "reduce", + "reduceRight", + "reverse", + "shift", + "slice", + "some", + "sort", + "splice", + "unshift" + ], + "string": [ + "charAt", + "charCodeAt", + "codePointAt", + "concat", + "endsWith", + "includes", + "indexOf", + "lastIndexOf", + "localeCompare", + "match", + "normalize", + "padEnd", + "padStart", + "repeat", + "replace", + "search", + "slice", + "split", + "startsWith", + "substring", + "toLocaleLowerCase", + "toLocaleUpperCase", + "toLowerCase", + "toString", + "toUpperCase", + "trim", + "trimEnd", + "trimStart", + "valueOf" + ] + } +} \ No newline at end of file diff --git a/graphjs-results/code/normalized.js b/graphjs-results/code/normalized.js new file mode 100644 index 0000000..fa64889 --- /dev/null +++ b/graphjs-results/code/normalized.js @@ -0,0 +1,7 @@ +let f; +f = function (o, x, y, z) { + z_dash = z + 1; + let v1; + v1 = o[x]; + v1[y] = z_dash; +} diff --git a/graphjs-results/graph/graph.svg b/graphjs-results/graph/graph.svg new file mode 100644 index 0000000..5837b81 --- /dev/null +++ b/graphjs-results/graph/graph.svg @@ -0,0 +1,211 @@ + + + + + + +G + + + +f_3 : f + +f_3 : f + + + +l_3 : f + +l_3 : f + + + +f_3 : f->l_3 : f + + +D + + + +p_1 : this + +p_1 : this + + + +f_3 : f->p_1 : this + + +param this + + + +p_2 : o + +p_2 : o + + + +f_3 : f->p_2 : o + + +param 0 + + + +p_3 : x + +p_3 : x + + + +f_3 : f->p_3 : x + + +param 1 + + + +p_4 : y + +p_4 : y + + + +f_3 : f->p_4 : y + + +param 2 + + + +p_5 : z + +p_5 : z + + + +f_3 : f->p_5 : z + + +param 3 + + + +l_0 : z_dash + +l_0 : z_dash + + + +l_1 : o.* + +l_1 : o.* + + + +l_2 : v1 + +l_2 : v1 + + + +l_1 : o.*->l_2 : v1 + + +V(*) + + + +l_2 : v1->l_0 : z_dash + + +P(*) + + + +l_literal : literal value + +l_literal : literal value + + + +l_literal : literal value->l_0 : z_dash + + +D + + + +l_tsource : taint source + +l_tsource : taint source + + + +l_tsource : taint source->p_1 : this + + +TAINT + + + +l_tsource : taint source->p_2 : o + + +TAINT + + + +l_tsource : taint source->p_3 : x + + +TAINT + + + +l_tsource : taint source->p_4 : y + + +TAINT + + + +l_tsource : taint source->p_5 : z + + +TAINT + + + +p_2 : o->l_1 : o.* + + +P(*) + + + +p_3 : x->l_1 : o.* + + +D + + + +p_4 : y->l_2 : v1 + + +D + + + +p_5 : z->l_0 : z_dash + + +D + + + diff --git a/graphjs-results/graph/graph_stats.json b/graphjs-results/graph/graph_stats.json new file mode 100644 index 0000000..7578d3b --- /dev/null +++ b/graphjs-results/graph/graph_stats.json @@ -0,0 +1 @@ +{ "edges": 18, "nodes": 12} \ No newline at end of file diff --git a/graphjs-results/graph/nodes.csv b/graphjs-results/graph/nodes.csv new file mode 100644 index 0000000..4d95fe7 --- /dev/null +++ b/graphjs-results/graph/nodes.csv @@ -0,0 +1,13 @@ +Id:ID¿Type¿SubType¿IdentifierName¿Raw¿InternalStructure¿Location¿Code¿Label:LABEL +5¿PDG_OBJECT¿¿o¿¿¿{"start":{"line":0,"column":0},"end":{"line":0,"column":0},"fname":""}¿¿PDG_OBJECT +12¿PDG_OBJECT¿¿v1¿¿¿{"start":{"line":3,"column":4},"end":{"line":3,"column":11},"fname":"/Users/tomastavares/projects/ast-gen/test/paper_examples/test.js"}¿¿PDG_OBJECT +13¿PDG_OBJECT¿¿¿¿¿{"start":{"line":0,"column":0},"end":{"line":0,"column":0},"fname":""}¿¿PDG_OBJECT +4¿PDG_OBJECT¿¿this¿¿¿{"start":{"line":0,"column":0},"end":{"line":0,"column":0},"fname":""}¿¿PDG_OBJECT +10¿PDG_OBJECT¿¿z_dash¿¿¿{"start":{"line":2,"column":13},"end":{"line":2,"column":18},"fname":"/Users/tomastavares/projects/ast-gen/test/paper_examples/test.js"}¿¿PDG_OBJECT +11¿PDG_OBJECT¿¿o.*¿¿¿{"start":{"line":3,"column":4},"end":{"line":3,"column":8},"fname":"/Users/tomastavares/projects/ast-gen/test/paper_examples/test.js"}¿¿PDG_OBJECT +7¿PDG_OBJECT¿¿y¿¿¿{"start":{"line":0,"column":0},"end":{"line":0,"column":0},"fname":""}¿¿PDG_OBJECT +9¿PDG_OBJECT¿¿f¿¿¿{"start":{"line":1,"column":0},"end":{"line":4,"column":1},"fname":"/Users/tomastavares/projects/ast-gen/test/paper_examples/test.js"}¿¿PDG_OBJECT +3¿PDG_FUNC¿¿f¿¿¿{"start":{"line":0,"column":0},"end":{"line":0,"column":0},"fname":""}¿¿PDG_FUNC +8¿PDG_OBJECT¿¿z¿¿¿{"start":{"line":0,"column":0},"end":{"line":0,"column":0},"fname":""}¿¿PDG_OBJECT +2¿TAINT_SOURCE¿¿TAINT_SOURCE¿¿¿{"start":{"line":0,"column":0},"end":{"line":0,"column":0},"fname":""}¿¿TAINT_SOURCE +6¿PDG_OBJECT¿¿x¿¿¿{"start":{"line":0,"column":0},"end":{"line":0,"column":0},"fname":""}¿¿PDG_OBJECT diff --git a/graphjs-results/graph/rels.csv b/graphjs-results/graph/rels.csv new file mode 100644 index 0000000..7754625 --- /dev/null +++ b/graphjs-results/graph/rels.csv @@ -0,0 +1,19 @@ +FromId:START_ID¿ToId:END_ID¿RelationLabel:TYPE¿RelationType¿IdentifierName¿ArgumentIndex¿ParamIndex¿StmtIndex¿ElementIndex¿ExpressionIndex¿MethodIndex¿SourceObjName¿IsProp +12¿10¿PDG¿SO¿*¿¿¿¿¿¿¿¿false +13¿10¿PDG¿DEP¿¿¿¿¿¿¿¿¿false +8¿10¿PDG¿DEP¿¿¿¿¿¿¿¿¿false +2¿4¿PDG¿TAINT¿¿¿¿¿¿¿¿¿false +2¿5¿PDG¿TAINT¿¿¿¿¿¿¿¿¿false +2¿6¿PDG¿TAINT¿¿¿¿¿¿¿¿¿false +2¿7¿PDG¿TAINT¿¿¿¿¿¿¿¿¿false +2¿8¿PDG¿TAINT¿¿¿¿¿¿¿¿¿false +5¿11¿PDG¿SO¿*¿¿¿¿¿¿¿¿false +11¿12¿PDG¿NV¿*¿¿¿¿¿¿¿¿false +7¿12¿PDG¿DEP¿¿¿¿¿¿¿¿¿false +3¿9¿PDG¿DEP¿¿¿¿¿¿¿¿¿false +3¿4¿REF¿param¿¿¿this¿¿¿¿¿¿false +3¿5¿REF¿param¿¿¿0¿¿¿¿¿¿false +3¿6¿REF¿param¿¿¿1¿¿¿¿¿¿false +3¿7¿REF¿param¿¿¿2¿¿¿¿¿¿false +3¿8¿REF¿param¿¿¿3¿¿¿¿¿¿false +6¿11¿PDG¿DEP¿¿¿¿¿¿¿¿¿false diff --git a/lib/mdg/analyse.ml b/lib/mdg/analyse.ml index f626c5f..b45fbfe 100644 --- a/lib/mdg/analyse.ml +++ b/lib/mdg/analyse.ml @@ -10,9 +10,9 @@ open State let verbose = ref false;; -let rec program (is_verbose : bool) ((_, program) : m Program.t) : Graph.t = +let rec program (is_verbose : bool) (config : Config.t) ((_, program) : m Program.t) : Graph.t = verbose := is_verbose; - let state = empty_state in + let state = empty_state config in let state' = initialize_functions state program.functions in analyse_sequence state' program.body; @@ -22,6 +22,7 @@ and analyse (state : state) (statement : m Statement.t) : unit = let graph = state.graph in let store = state.store in let contx = state.context in + let confg = state.config in (* aliases *) let eval_expr = eval_expr store state.this in @@ -31,14 +32,11 @@ and analyse (state : state) (statement : m Statement.t) : unit = let add_call_edge = Graph.add_call_edge graph in let add_ref_call_edge = Graph.add_ref_call_edge graph in let add_ret_edge = Graph.add_ret_edge graph in - let add_sink_edge = Graph.add_sink_edge graph in let store_update = Store.update store in let alloc = Graph.alloc graph in let falloc = Graph.alloc_function graph in - let salloc = Graph.alloc_tsink graph in let add_node = Graph.add_obj_node graph in let add_cnode = Graph.add_call_node graph in - let add_tsink = Graph.add_taint_sink graph in let add_ret_node = Graph.add_return_node graph in let add_property = Graph.staticAddProperty graph in let add_property' = Graph.dynamicAddProperty graph in @@ -50,7 +48,8 @@ and analyse (state : state) (statement : m Statement.t) : unit = let get_func_id = Functions.Context.get_func_id contx in let is_last_definition = Functions.Context.is_last_definition contx in let visit = Functions.Context.visit contx in - let get_curr_func = Functions.Context.get_current_function contx in + let get_curr_func = Functions.Context.get_current_function contx in + let get_func_sink_info = Config.get_function_sink_info confg in (match statement with (* -------- A S S I G N - E X P R -------- *) @@ -63,7 +62,7 @@ and analyse (state : state) (statement : m Statement.t) : unit = let func_id : Functions.Id.t = {uid = id; name = Identifier.get_name left} in (* functions with the same name can be nested inside the same context (only consider the last definition with such name) *) - if is_last_definition func_id then + if is_last_definition func_id then ( (* ! add object that represents the function *) let l_i = alloc id in add_node l_i (Identifier.get_name left) loc; @@ -76,7 +75,8 @@ and analyse (state : state) (statement : m Statement.t) : unit = (* setup new store with only the param and corresponding locations *) let param_locs = get_param_locs func_id in let new_state = {state with store = param_locs; context = visit func_id} in - analyse_sequence new_state body; + analyse_sequence new_state body + ); (* -------- A S S I G N - O P -------- *) @@ -174,16 +174,8 @@ and analyse (state : state) (statement : m Statement.t) : unit = ) _Lss; (* checks if it is a sink and process it accordingly *) - (* ! not loading from config *) - if (f = "eval" || f = "exec") then ( - let l_tsink = salloc id_call in - add_tsink l_tsink f loc; - add_sink_edge l_call l_tsink f; - - List.iter ( fun _Ls -> - LocationSet.apply (fun l -> add_dep_edge l l_tsink) _Ls - ) _Lss; - ); + let sink_info = get_func_sink_info f in + option_may (add_func_sink_node graph id_call l_call loc _Lss) sink_info; (* ! add ref call edge (shotcut) from function definition to this call *) let f_orig = get_curr_func () in @@ -277,7 +269,8 @@ and analyse (state : state) (statement : m Statement.t) : unit = print_endline "Store: "; Store.print store; ) - + +(* ------- P R I M I T I V E F U N C T I O N S --------*) and analyse_sequence (state : state) = List.iter (analyse state) and ifp (f : state -> unit) (state : state) : unit = @@ -289,7 +282,22 @@ and ifp (f : state -> unit) (state : state) : unit = Store.lub state.store store'; if not (Store.equal state.store store') then ifp f state - + +and eval_expr (store : Store.t) (this : LocationSet.t) (expr : m Expression.t) : LocationSet.t = + match expr with + | (_, Identifier _) as id -> + let id = Identifier.from_expression id in + Store.get store id + + | _, Literal _ -> Store.loc_literal + + | _, This _ -> this + + | _, TemplateLiteral {expressions; _} -> + List.fold_left (fun acc elem -> LocationSet.union acc (eval_expr store this elem)) LocationSet.empty expressions + + +(* ----- A N A L I S Y S F U N C T I O N S ----- *) and analyse_method_call (state : state) (loc : Location.t) (left : m Identifier.t) (_object : m Expression.t) (property : property) (arguments : m Expression.t list) (id_call : int) (id_retn : int) : unit = (* ! is this a way to represent it? *) (* aliases *) @@ -336,23 +344,6 @@ and analyse_method_call (state : state) (loc : Location.t) (left : m Identifier. add_ret_edge l_call l_retn; store_update left (LocationSet.singleton l_retn); -and eval_expr (store : Store.t) (this : LocationSet.t) (expr : m Expression.t) : LocationSet.t = - match expr with - | (_, Identifier _) as id -> - let id = Identifier.from_expression id in - Store.get store id - - | _, Literal _ -> Store.loc_literal - - | _, This _ -> this - - | _, TemplateLiteral {expressions; _} -> - List.fold_left (fun acc elem -> LocationSet.union acc (eval_expr store this elem)) LocationSet.empty expressions - - -and property_lookup_name (left : m Identifier.t) (_object : m Expression.t) (property : string) : string = - let obj_prop = Expression.get_id _object ^ "." ^ property in - if Identifier.is_generated left then obj_prop else Identifier.get_name left ^ ", " ^ obj_prop and initialize_functions (state : state) (funcs_info : Functions.Info.t) : state = let l_tsource = loc_taint_source in @@ -380,4 +371,27 @@ and initialize_functions (state : state) (funcs_info : Functions.Info.t) : state in Functions.Info.iter (init_func_header state) funcs_info; - {state with context = Functions.Context.create funcs_info } \ No newline at end of file + {state with context = Functions.Context.create funcs_info } + +(* ----- O T H E R F U N C T I O N S ------ *) +and property_lookup_name (left : m Identifier.t) (_object : m Expression.t) (property : string) : string = + let obj_prop = Expression.get_id _object ^ "." ^ property in + if Identifier.is_generated left then obj_prop else Identifier.get_name left ^ ", " ^ obj_prop + +and add_func_sink_node (graph : Graph.t) (id_call : int) (l_call : location) (loc : Location.t) (args : LocationSet.t list) (sink_info : Config.functionSink) : unit = + let salloc = Graph.alloc_tsink graph in + let add_tsink = Graph.add_taint_sink graph in + let add_sink_edge = Graph.add_sink_edge graph in + let add_dep_edge = Graph.add_dep_edge graph in + let sink_name = sink_info.sink in + + let l_tsink = salloc id_call in + add_tsink l_tsink sink_name loc; + add_sink_edge l_call l_tsink sink_name; + + (* add depedency edges from dangerous inputs (arguments) to taint sink *) + let dangerous_inputs = sink_info.args in + List.iter (fun dangerous_index -> + let arg_locs = List.nth args (dangerous_index - 1) in + LocationSet.apply (fun l -> add_dep_edge l l_tsink) arg_locs + ) dangerous_inputs \ No newline at end of file diff --git a/lib/mdg/structures/config.ml b/lib/mdg/structures/config.ml new file mode 100644 index 0000000..38191dc --- /dev/null +++ b/lib/mdg/structures/config.ml @@ -0,0 +1,114 @@ +open Yojson.Basic.Util +open Auxiliary.Functions + +(* -------- T Y P E S -------- *) +type package = { + package : string; + args : int list +} + +type functionSink = { + sink : string; + args : int list +} + +type newSink = { + sink : string; + args : int list +} + +type packageSink = { + sink : string; + packages : package list +} + +type packageSource = { + source : string; + packages : package list +} + +type t = { + functions : functionSink list; + news : newSink list; + packageSinks : packageSink list; + packageSources : packageSource list; +} + + +(* -------- C O N F I G F U N C T I O N S -------- *) +let rec read (config_path : string) : t = + let functions' : functionSink list ref = ref [] in + let news' : newSink list ref = ref [] in + let packageSinks' : packageSink list ref = ref [] in + let packageSources' : packageSource list ref = ref [] in + let config_json = Yojson.Basic.from_file config_path in + + let sinks = config_json |> member "sinks" in + if sinks != `Null then ( + List.iter (fun (_vuln_type, sinks) -> + let sinks = sinks |> to_list in + + List.iter (fun sink -> + let sink_name = sink |> member "sink" |> to_string in + let sink_type = sink |> member "type" |> to_string in + + match sink_type with + | "new" -> + let args = List.map (to_int) (sink |> member "args" |> to_list) in + let new_sink : newSink = {sink = sink_name; args = args} in + news' := new_sink :: !news' + + | "function" -> + let args = List.map (to_int) (sink |> member "args" |> to_list) in + let func_sink : functionSink = {sink = sink_name; args = args} in + functions' := func_sink :: !functions' + + | "package" -> + let packages = List.map (to_package) (sink |> member "packages" |> to_list) in + let package_sink : packageSink = {sink = sink_name; packages = packages} in + packageSinks' := package_sink :: !packageSinks' + + | _ -> failwith ("sink type " ^ sink_type ^ " not allowed") + ) sinks + ) (sinks |> to_assoc) + ); + + let sources = config_json |> member "sources" in + if sources != `Null then ( + List.iter (fun source -> + let source_name = source |> member "source" |> to_string in + let source_type = source |> member "type" |> to_string in + + match source_type with + | "package" -> + let packages = List.map (to_package) (source |> member "packages" |> to_list) in + let package_source : packageSource = {source = source_name; packages = packages} in + packageSources' := package_source :: !packageSources' + + | _ -> failwith ("source type " ^ source_type ^ " not allowed") + + ) (sources |> to_list) + ); + + (* return *) + { functions = !functions' ; + news = !news' ; + packageSinks = !packageSinks' ; + packageSources = !packageSources'; } + +and to_package (package_json : Yojson.Basic.t) : package = + let package_name = package_json |> member "package" |> to_string in + let args = List.map (to_int) (package_json |> member "args" |> to_list) in + + (* return *) + { package = package_name; + args = args } + + +let get_function_sink_name (sink_info : functionSink) : string = sink_info.sink + +let get_function_sink_info (config : t) (func_name : string) : functionSink option = + let sink_infos = (List.filter (((=) func_name) << get_function_sink_name) config.functions) in + List.nth_opt sink_infos 0 + + diff --git a/lib/mdg/structures/state.ml b/lib/mdg/structures/state.ml index adba0fb..a7aeef6 100644 --- a/lib/mdg/structures/state.ml +++ b/lib/mdg/structures/state.ml @@ -18,17 +18,19 @@ let register, setup, was_changed = reg, push, pop;; type state = { - graph : Graph.t; - store : Store.t; - this : LocationSet.t; + graph : Graph.t; + store : Store.t; + this : LocationSet.t; + config : Config.t; (* function information *) context : Functions.Context.t; } -let empty_state = { - graph = Graph.empty register; - store = Store.empty (); - this = Store.loc_this; +let empty_state (config : Config.t) = { + graph = Graph.empty register; + store = Store.empty (); + this = Store.loc_this; + config = config; (* function information *) context = Functions.Context.empty; } diff --git a/test/normalization/cram/array-expressions.t/run.t b/test/normalization/cram/array-expressions.t/run.t index 0b6a025..f64c91e 100644 --- a/test/normalization/cram/array-expressions.t/run.t +++ b/test/normalization/cram/array-expressions.t/run.t @@ -1,4 +1,4 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = []; let v2; @@ -8,7 +8,7 @@ v3 = 1 + 2; v1["1"] = v3; - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = []; let v2; @@ -24,7 +24,7 @@ v5 = eval('hello'); v1["1"] = v5; - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = []; v1["0"] = 23; diff --git a/test/normalization/cram/arrow-function-expressions.t/run.t b/test/normalization/cram/arrow-function-expressions.t/run.t index fd6e06e..5d9931c 100644 --- a/test/normalization/cram/arrow-function-expressions.t/run.t +++ b/test/normalization/cram/arrow-function-expressions.t/run.t @@ -1,4 +1,4 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let x; x = function (z) { let v1; @@ -8,7 +8,7 @@ return v2; } - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; let x; x = function (z) { let v1; @@ -18,7 +18,7 @@ return v2; } - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = function (z) { let v2; @@ -29,7 +29,7 @@ } a.b = v1; - $ ast_gen input-code-4.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-4.js -o out; cat out/code/normalized.js; echo; rm -fr out; const a; let v1; v1 = []; @@ -45,7 +45,7 @@ } a = v1.find(v2); - $ ast_gen input-code-5.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-5.js -o out; cat out/code/normalized.js; echo; rm -fr out; const a; let v1; v1 = []; diff --git a/test/normalization/cram/assignment-expressions.t/run.t b/test/normalization/cram/assignment-expressions.t/run.t index b30ed08..1126c7f 100644 --- a/test/normalization/cram/assignment-expressions.t/run.t +++ b/test/normalization/cram/assignment-expressions.t/run.t @@ -1,4 +1,4 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let x; x = 1; diff --git a/test/normalization/cram/await-expressions.t/run.t b/test/normalization/cram/await-expressions.t/run.t index 69220f4..ed4e573 100644 --- a/test/normalization/cram/await-expressions.t/run.t +++ b/test/normalization/cram/await-expressions.t/run.t @@ -1,11 +1,11 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let f1; f1 = function () { let x; x = await 10; } - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; let f1; f1 = function () { let x; @@ -16,7 +16,7 @@ x = await v2; } - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; let f; f = function (x) { let a; diff --git a/test/normalization/cram/binary-expressions.t/run.t b/test/normalization/cram/binary-expressions.t/run.t index 721a602..abe4783 100644 --- a/test/normalization/cram/binary-expressions.t/run.t +++ b/test/normalization/cram/binary-expressions.t/run.t @@ -1,15 +1,15 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = 1 + 2; - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = x + y; - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; x = y + z; - $ ast_gen input-code-4.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-4.js -o out; cat out/code/normalized.js; echo; rm -fr out; const x; x = y + z; diff --git a/test/normalization/cram/call-expressions.t/run.t b/test/normalization/cram/call-expressions.t/run.t index 4eef43f..263ac90 100644 --- a/test/normalization/cram/call-expressions.t/run.t +++ b/test/normalization/cram/call-expressions.t/run.t @@ -1,22 +1,22 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; const x; let v1; v1 = 1 + 2; x = eval('1 + 2', v1); - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = 23 + 19; let v2; v2 = Math.min(23, v1); - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = f(); let v2; v2 = v1(); - $ ast_gen input-code-4.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-4.js -o out; cat out/code/normalized.js; echo; rm -fr out; cmd = []; cmd["0"] = "1"; cmd["1"] = "2"; diff --git a/test/normalization/cram/class-declarations.t/run.t b/test/normalization/cram/class-declarations.t/run.t index 87b02f6..d4649e0 100644 --- a/test/normalization/cram/class-declarations.t/run.t +++ b/test/normalization/cram/class-declarations.t/run.t @@ -1,4 +1,4 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let Foo; Foo = function () { } @@ -6,7 +6,7 @@ v2 = new Bar(); Foo.prototype = v2; - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; let Foo; Foo = function () { } @@ -18,7 +18,7 @@ } v2.foo = v3; - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; let Foo; Foo = function () { let v3; diff --git a/test/normalization/cram/class-expressions.t/run.t b/test/normalization/cram/class-expressions.t/run.t index 47cec2b..2973583 100644 --- a/test/normalization/cram/class-expressions.t/run.t +++ b/test/normalization/cram/class-expressions.t/run.t @@ -1,4 +1,4 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v; Foo = function () { } @@ -6,7 +6,7 @@ v2 = new Bar(); Foo.prototype = v2; - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v; Foo = function () { } @@ -18,7 +18,7 @@ } v2.foo = v3; - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v; Foo = function () { let v3; diff --git a/test/normalization/cram/conditionals.t/run.t b/test/normalization/cram/conditionals.t/run.t index c9bfef7..a16617a 100644 --- a/test/normalization/cram/conditionals.t/run.t +++ b/test/normalization/cram/conditionals.t/run.t @@ -1,4 +1,4 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let status; let v1; if (true) { @@ -8,7 +8,7 @@ } status = v1; - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; let x; x = 6; let status; @@ -28,7 +28,7 @@ } status = v1; - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; let x; x = 0; let v1; @@ -43,7 +43,7 @@ } x = v1; - $ ast_gen input-code-4.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-4.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; if (stderr) { let v2; diff --git a/test/normalization/cram/for-statements.t/run.t b/test/normalization/cram/for-statements.t/run.t index 6fdc8fb..cbc8746 100644 --- a/test/normalization/cram/for-statements.t/run.t +++ b/test/normalization/cram/for-statements.t/run.t @@ -1,4 +1,4 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let src; src = []; src["0"] = 1; @@ -11,14 +11,14 @@ y = dest[p]; } - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; for (let v1 in src) { p = v1; x = src[p]; y = dest[p]; } - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; let extend; extend = function (dest, src) { for (var p in src) { @@ -27,7 +27,7 @@ } } - $ ast_gen input-code-4.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-4.js -o out; cat out/code/normalized.js; echo; rm -fr out; let iterable; iterable = []; iterable["0"] = 10; @@ -38,9 +38,9 @@ v1 = console.log(value); } - $ ast_gen input-code-5.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-5.js -o out; cat out/code/normalized.js; echo; rm -fr out; ast_gen: internal error, uncaught exception: Failure("hd") - cat: out/graph/normalized.js: No such file or directory + cat: out/code/normalized.js: No such file or directory diff --git a/test/normalization/cram/function-declarations.t/run.t b/test/normalization/cram/function-declarations.t/run.t index 7ddfe4b..92663a4 100644 --- a/test/normalization/cram/function-declarations.t/run.t +++ b/test/normalization/cram/function-declarations.t/run.t @@ -1,11 +1,11 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let f1; f1 = function () { let x; x = 0; } - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; let f; f = function (x, y, z) { let v1; @@ -13,7 +13,7 @@ x = x + 1; } - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; let count; count = function () { var i; @@ -27,7 +27,7 @@ } } - $ ast_gen input-code-4.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-4.js -o out; cat out/code/normalized.js; echo; rm -fr out; let positive; positive = function (n) { let v1; @@ -40,7 +40,7 @@ } } - $ ast_gen input-code-5.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-5.js -o out; cat out/code/normalized.js; echo; rm -fr out; let f; f = function () { } diff --git a/test/normalization/cram/function-expressions.t/run.t b/test/normalization/cram/function-expressions.t/run.t index a2e0fb5..0b124f4 100644 --- a/test/normalization/cram/function-expressions.t/run.t +++ b/test/normalization/cram/function-expressions.t/run.t @@ -1,11 +1,11 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let z; z = function () { let v1; v1 = 1 + 1; } - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; let f; f = function () { let v1; diff --git a/test/normalization/cram/if-statements.t/run.t b/test/normalization/cram/if-statements.t/run.t index 62e8bea..3a851ce 100644 --- a/test/normalization/cram/if-statements.t/run.t +++ b/test/normalization/cram/if-statements.t/run.t @@ -1,10 +1,10 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; if (true) { let v1; v1 = 1 + 2; } - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; let x; x = 'Oi'; let v1; @@ -21,7 +21,7 @@ z = v3 + 3; } - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = x === y; if (v1) { @@ -29,7 +29,7 @@ v2 = alert("They are the same!"); } - $ ast_gen input-code-4.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-4.js -o out; cat out/code/normalized.js; echo; rm -fr out; const x; x = 1; let y; diff --git a/test/normalization/cram/labeled-statements.t/run.t b/test/normalization/cram/labeled-statements.t/run.t index 330c2e4..f70ba71 100644 --- a/test/normalization/cram/labeled-statements.t/run.t +++ b/test/normalization/cram/labeled-statements.t/run.t @@ -1,16 +1,16 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; lbl: break lbl; - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; lbl1: lbl2: break lbl1; - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; lbl: let v1; v1 = x === true; diff --git a/test/normalization/cram/literals.t/run.t b/test/normalization/cram/literals.t/run.t index c3f88c8..6034a27 100644 --- a/test/normalization/cram/literals.t/run.t +++ b/test/normalization/cram/literals.t/run.t @@ -1,8 +1,8 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; - $ ast_gen input-code-4.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-4.js -o out; cat out/code/normalized.js; echo; rm -fr out; diff --git a/test/normalization/cram/logical-expressions.t/run.t b/test/normalization/cram/logical-expressions.t/run.t index 36edc80..878000e 100644 --- a/test/normalization/cram/logical-expressions.t/run.t +++ b/test/normalization/cram/logical-expressions.t/run.t @@ -1,10 +1,10 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = 2 + 1; let v2; v2 = 1 && v1; - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = true && false; if (v1) { @@ -12,19 +12,19 @@ v1 = 1; } - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = 1 && 2; let v2; v2 = v1 && 3; - $ ast_gen input-code-4.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-4.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = 1 + 2; let v2; v2 = v1 && 1; - $ ast_gen input-code-5.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-5.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = x.f; let v2; diff --git a/test/normalization/cram/member-expressions.t/run.t b/test/normalization/cram/member-expressions.t/run.t index e51ba9a..4e20ce0 100644 --- a/test/normalization/cram/member-expressions.t/run.t +++ b/test/normalization/cram/member-expressions.t/run.t @@ -1,11 +1,11 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let x; x = {}; x.p = 'p'; let y; y = x.p; - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; const y; let v1; v1 = f(); diff --git a/test/normalization/cram/new-expressions.t/run.t b/test/normalization/cram/new-expressions.t/run.t index bc55c06..f98a97f 100644 --- a/test/normalization/cram/new-expressions.t/run.t +++ b/test/normalization/cram/new-expressions.t/run.t @@ -1,4 +1,4 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; const x; let v1; v1 = 1 + 2; diff --git a/test/normalization/cram/object-expressions.t/run.t b/test/normalization/cram/object-expressions.t/run.t index bd5be91..17a8292 100644 --- a/test/normalization/cram/object-expressions.t/run.t +++ b/test/normalization/cram/object-expressions.t/run.t @@ -1,22 +1,22 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let x; x = {}; - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; let x; x = {}; x.p = 'p'; - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = {}; - $ ast_gen input-code-4.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-4.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = {}; v1.x = 23; - $ ast_gen input-code-5.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-5.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = {}; v1.x = 23; @@ -32,14 +32,14 @@ } v1.y = v4; - $ ast_gen input-code-6.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-6.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = {}; let v2; v2 = 23 + 19; v1.x = v2; - $ ast_gen input-code-7.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-7.js -o out; cat out/code/normalized.js; echo; rm -fr out; let customer; customer = {}; let v1; @@ -48,7 +48,7 @@ customer.name = v1; customer.role = 'user'; - $ ast_gen input-code-8.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-8.js -o out; cat out/code/normalized.js; echo; rm -fr out; var map; map = {}; map["%r"] = repo; diff --git a/test/normalization/cram/rest-elements.t/run.t b/test/normalization/cram/rest-elements.t/run.t index b3d85da..3deaea8 100644 --- a/test/normalization/cram/rest-elements.t/run.t +++ b/test/normalization/cram/rest-elements.t/run.t @@ -1,9 +1,9 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let f; f = function (arg1) { } - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; let param1; let otherParams; let v1; @@ -13,7 +13,7 @@ v2 = v1.slice; otherParams = v2(1); - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; let array; let otherParams; let v1; @@ -23,7 +23,7 @@ v2 = v1.slice; otherParams = v2(1); - $ ast_gen input-code-4.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-4.js -o out; cat out/code/normalized.js; echo; rm -fr out; let array; let otherParams; let v1; @@ -33,14 +33,14 @@ v2 = v1.slice; otherParams = v2(1); - $ ast_gen input-code-5.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-5.js -o out; cat out/code/normalized.js; echo; rm -fr out; const a; let v1; v1 = {}; v1.a = 3; a = v1.a; - $ ast_gen input-code-6.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-6.js -o out; cat out/code/normalized.js; echo; rm -fr out; const a; const b; let v1; @@ -48,7 +48,7 @@ a = v1.a; b = v1.b; - $ ast_gen input-code-7.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-7.js -o out; cat out/code/normalized.js; echo; rm -fr out; const a; const b; let v1; diff --git a/test/normalization/cram/sequence-expressions.t/run.t b/test/normalization/cram/sequence-expressions.t/run.t index ce70b25..d4175dc 100644 --- a/test/normalization/cram/sequence-expressions.t/run.t +++ b/test/normalization/cram/sequence-expressions.t/run.t @@ -1,4 +1,4 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = 1; let v2; @@ -8,7 +8,7 @@ let v4; v4 = 4; - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = 1 + 2; let v2; @@ -20,7 +20,7 @@ let v5; v5 = v3; - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; x = 0; y = {}; let v1; diff --git a/test/normalization/cram/spread-elements.t/run.t b/test/normalization/cram/spread-elements.t/run.t index a298884..3907e93 100644 --- a/test/normalization/cram/spread-elements.t/run.t +++ b/test/normalization/cram/spread-elements.t/run.t @@ -1,6 +1,6 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; ast_gen: internal error, uncaught exception: Failure("cannot process spread array element") - cat: out/graph/normalized.js: No such file or directory + cat: out/code/normalized.js: No such file or directory diff --git a/test/normalization/cram/switch-statements.t/run.t b/test/normalization/cram/switch-statements.t/run.t index f8027c8..8d4d7a3 100644 --- a/test/normalization/cram/switch-statements.t/run.t +++ b/test/normalization/cram/switch-statements.t/run.t @@ -1,4 +1,4 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = 23 + 19; switch (v1) { @@ -14,7 +14,7 @@ } - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = 23 + 19; switch (v1) { @@ -29,7 +29,7 @@ } - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = 23 + 19; switch (v1) { @@ -46,17 +46,17 @@ } - $ ast_gen input-code-4.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-4.js -o out; cat out/code/normalized.js; echo; rm -fr out; switch (42) { } - $ ast_gen input-code-5.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-5.js -o out; cat out/code/normalized.js; echo; rm -fr out; switch (42) { case 23: } - $ ast_gen input-code-6.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-6.js -o out; cat out/code/normalized.js; echo; rm -fr out; switch (x) { case 0: let v1; @@ -69,7 +69,7 @@ } - $ ast_gen input-code-7.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-7.js -o out; cat out/code/normalized.js; echo; rm -fr out; switch (x) { case 0: let v1; @@ -81,7 +81,7 @@ } - $ ast_gen input-code-8.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-8.js -o out; cat out/code/normalized.js; echo; rm -fr out; switch (x) { case 0: let v1; @@ -99,7 +99,7 @@ } - $ ast_gen input-code-9.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-9.js -o out; cat out/code/normalized.js; echo; rm -fr out; switch (x) { case 0: let v1; @@ -122,7 +122,7 @@ } - $ ast_gen input-code-10.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-10.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = 2 + 3; let v2; diff --git a/test/normalization/cram/template-expressions.t/run.t b/test/normalization/cram/template-expressions.t/run.t index 36cb378..8dec122 100644 --- a/test/normalization/cram/template-expressions.t/run.t +++ b/test/normalization/cram/template-expressions.t/run.t @@ -1,16 +1,16 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; const x; x = `string`; - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; const x; x = `string` + `concat`; - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; const x; x = `template ${expr}`; - $ ast_gen input-code-4.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-4.js -o out; cat out/code/normalized.js; echo; rm -fr out; const x; x = `string`; const temp; @@ -18,9 +18,9 @@ v1 = x + 2; temp = `head template ${v1} end tail`; - $ ast_gen input-code-5.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-5.js -o out; cat out/code/normalized.js; echo; rm -fr out; ast_gen: internal error, uncaught exception: Failure("Unknown expression type to normalize (object on (9, 15) to (9, 60))") - cat: out/graph/normalized.js: No such file or directory + cat: out/code/normalized.js: No such file or directory diff --git a/test/normalization/cram/try-statements.t/run.t b/test/normalization/cram/try-statements.t/run.t index 331db26..4868368 100644 --- a/test/normalization/cram/try-statements.t/run.t +++ b/test/normalization/cram/try-statements.t/run.t @@ -1,4 +1,4 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; try { let v1; v1 = 1 + 2; @@ -7,7 +7,7 @@ v2 = 1 + 2; } - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; try { let v1; v1 = 1 + 2; @@ -19,7 +19,7 @@ v2 = 1 + 2; } - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; try { let v1; v1 = f(); @@ -31,7 +31,7 @@ v2 = alert("done"); } - $ ast_gen input-code-4.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-4.js -o out; cat out/code/normalized.js; echo; rm -fr out; let f; f = function (x) { try { diff --git a/test/normalization/cram/unary-expressions.t/run.t b/test/normalization/cram/unary-expressions.t/run.t index cbd02cb..cb56139 100644 --- a/test/normalization/cram/unary-expressions.t/run.t +++ b/test/normalization/cram/unary-expressions.t/run.t @@ -1,15 +1,15 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let v1; v1 = !false; - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; const x; x = 0; let v1; v1 = x; x = x + 1; - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; let f; f = function (x) { let v1; diff --git a/test/normalization/cram/variable-declarations.t/run.t b/test/normalization/cram/variable-declarations.t/run.t index 9b99b5c..605a39f 100644 --- a/test/normalization/cram/variable-declarations.t/run.t +++ b/test/normalization/cram/variable-declarations.t/run.t @@ -1,18 +1,18 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let x; x = 1; - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; let x; x = 1 + 2; - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; let x; let y; x = 1 + 2; y = 3; - $ ast_gen input-code-4.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-4.js -o out; cat out/code/normalized.js; echo; rm -fr out; var x; var y; y = x + 1; diff --git a/test/normalization/cram/while-statements.t/run.t b/test/normalization/cram/while-statements.t/run.t index ddc02c1..10f9a04 100644 --- a/test/normalization/cram/while-statements.t/run.t +++ b/test/normalization/cram/while-statements.t/run.t @@ -1,10 +1,10 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; while (false) { let v1; v1 = 1 + 2; } - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; let x; x = 0; let v1; @@ -16,7 +16,7 @@ v1 = x < 1; } - $ ast_gen input-code-3.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-3.js -o out; cat out/code/normalized.js; echo; rm -fr out; let x; x = 0; let v1; @@ -28,7 +28,7 @@ v1 = x < 1; } - $ ast_gen input-code-4.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-4.js -o out; cat out/code/normalized.js; echo; rm -fr out; let x; x = 0; let v1; @@ -41,7 +41,7 @@ v1 = x < 1; } - $ ast_gen input-code-5.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-5.js -o out; cat out/code/normalized.js; echo; rm -fr out; var i; i = 0; let v1; @@ -55,7 +55,7 @@ v1 = i < 10; } - $ ast_gen input-code-6.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-6.js -o out; cat out/code/normalized.js; echo; rm -fr out; var i; i = 0; let v1; diff --git a/test/normalization/cram/yield-expressions.t/run.t b/test/normalization/cram/yield-expressions.t/run.t index 8d0c5a1..92dfd0e 100644 --- a/test/normalization/cram/yield-expressions.t/run.t +++ b/test/normalization/cram/yield-expressions.t/run.t @@ -1,10 +1,10 @@ - $ ast_gen input-code-1.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-1.js -o out; cat out/code/normalized.js; echo; rm -fr out; let foo; foo = function (index) { yield index; } - $ ast_gen input-code-2.js -o out; cat out/graph/normalized.js; echo; rm -fr out; + $ ast_gen input-code-2.js -o out; cat out/code/normalized.js; echo; rm -fr out; let foo; foo = function (index) { let v1;