Skip to content

Commit

Permalink
Fix server node_state request crash on invalid node id (issue #983)
Browse files Browse the repository at this point in the history
  • Loading branch information
sim642 committed Feb 15, 2023
1 parent 59127e9 commit e974e3a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/framework/node.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ let find_fundec (node: t) =
| Function fd -> fd
| FunctionEntry fd -> fd

(** @raise Not_found *)
let of_id s =
let ix = Str.search_forward (Str.regexp {|[0-9]+$|}) s 0 in
let id = int_of_string (Str.string_after s ix) in
Expand All @@ -68,5 +69,5 @@ let of_id s =
match prefix with
| "ret" -> Function fundec
| "fun" -> FunctionEntry fundec
| _ -> invalid_arg "Node.of_id: invalid prefix"
| _ -> raise Not_found

11 changes: 7 additions & 4 deletions src/util/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,13 @@ let () =
type params = { nid: string } [@@deriving of_yojson]
type response = Yojson.Safe.t [@@deriving to_yojson]
let process { nid } serv =
let n = Node.of_id nid in
match !Control.current_node_state_json n with
| Some json -> json
| None -> Response.Error.(raise (make ~code:InvalidRequest ~message:"not analyzed, non-existent or dead node" ()))
match Node.of_id nid with
| n ->
begin match !Control.current_node_state_json n with
| Some json -> json
| None -> Response.Error.(raise (make ~code:InvalidRequest ~message:"not analyzed, non-existent or dead node" ()))
end
| exception Not_found -> Response.Error.(raise (make ~code:InvalidRequest ~message:"not analyzed or non-existent node" ()))
end);

register (module struct
Expand Down

0 comments on commit e974e3a

Please sign in to comment.