Browse Source

Add test for num value in tmp file

 - Prevent to big num value in tmp file to go out of the
   cmd list
Leo 11 years ago
parent
commit
465af5cd01
1 changed files with 11 additions and 4 deletions
  1. 11 4
      exec_cmd.ml

+ 11 - 4
exec_cmd.ml

@@ -42,10 +42,17 @@ let what_next ~tmp ~cmd_list =
   let tmp_json = Yojson.Basic.from_file tmp in
   let open Yojson.Basic.Util in
   let num_next = tmp_json |> member "num" |> to_int in (* Number of the next cmd to run *)
-  let cmd_to_exec = List.nth cmd_list num_next in
-    match cmd_to_exec with
-      | None -> ""
-      | Some x -> x
+    (*Verify that the number is not out of the list *)
+    if (List.length cmd_list) < num_next
+    then
+      ""
+        else
+          begin
+            let cmd_to_exec = List.nth cmd_list num_next in
+              match cmd_to_exec with
+                | None -> ""
+                | Some x -> x
+          end
 ;;
 
 (* Log when a program has been launched in a file in /tmp