From 046082194a73c329f01dd6a9d0ffcee008b936e6 Mon Sep 17 00:00:00 2001 From: Andre Maroneze <andre.maroneze@cea.fr> Date: Fri, 7 May 2021 17:17:43 +0200 Subject: [PATCH] [Eva] avoid crash in -eva-audit due to malformed JSON file --- src/libraries/utils/json.mli | 1 + src/plugins/value/utils/eva_audit.ml | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libraries/utils/json.mli b/src/libraries/utils/json.mli index ebfa936330d..2549b3ae076 100644 --- a/src/libraries/utils/json.mli +++ b/src/libraries/utils/json.mli @@ -178,6 +178,7 @@ val merge_array : Filepath.Normalized.t -> Yojson.Basic.t -> unit (** [from_file path] opens [path] and stores its JSON object in a memory cache, to be used by the other related functions. + @raise Yojson.Json_error if [path] is a malformed JSON file. @since Frama-C+dev *) val from_file: Filepath.Normalized.t -> Yojson.Basic.t diff --git a/src/plugins/value/utils/eva_audit.ml b/src/plugins/value/utils/eva_audit.ml index f7e10c46cf0..c376dfe5fca 100644 --- a/src/plugins/value/utils/eva_audit.ml +++ b/src/plugins/value/utils/eva_audit.ml @@ -135,10 +135,14 @@ let check_warning_status json name (module Plugin: Log.Messages) = (Pretty_utils.pp_list ~sep:", " Format.pp_print_string) should_be_enabled let check_configuration path = - let json = Json.from_file path in - check_correctness_parameters json; - check_warning_status json "Kernel" (module Kernel); - check_warning_status json "Eva" (module Value_parameters) + try + let json = Json.from_file path in + check_correctness_parameters json; + check_warning_status json "Kernel" (module Kernel); + check_warning_status json "Eva" (module Value_parameters) + with Yojson.Json_error msg -> + Kernel.abort "error reading JSON file %a: %s" + Filepath.Normalized.pretty path msg let print_configuration path = print_correctness_parameters path; -- GitLab