Merge pull request 'query_abi / query_manifest: catch exceptions from Owee' (#2) from no-exception into main

Reviewed-on: https://git.robur.io/robur/ocaml-solo5-elftool/pulls/2
This commit is contained in:
Reynir Björnsson 2022-01-28 14:42:03 +00:00
commit 8fa3b516c4
2 changed files with 14 additions and 8 deletions

View file

@ -166,7 +166,7 @@ let note_name = "Solo5"
let typ_mft1 = 0x3154464d
let typ_abi1 = 0x31494241
let query_manifest buf =
let query_manifest_exn buf =
let _header, sections = Owee_elf.read_elf buf in
let* section =
Owee_elf.find_section sections ".note.solo5.manifest"
@ -183,7 +183,12 @@ let query_manifest buf =
let* () = guard "extra data" (Owee_buf.at_end cursor) in
parse_mft desc
let query_abi buf =
let query_manifest buf =
try query_manifest_exn buf with
| Out_of_memory -> raise Out_of_memory
| e -> Error (`Msg ("query manifest failure: " ^ Printexc.to_string e))
let query_abi_exn buf =
let _header, sections = Owee_elf.read_elf buf in
let* section =
Owee_elf.find_section sections ".note.solo5.abi"
@ -199,3 +204,8 @@ let query_abi buf =
let desc = Owee_buf.Read.fixed_string cursor descsz in
let* () = guard "extra data" (Owee_buf.at_end cursor) in
parse_abi desc
let query_abi buf =
try query_abi_exn buf with
| Out_of_memory -> raise Out_of_memory
| e -> Error (`Msg ("query abi failure: " ^ Printexc.to_string e))

View file

@ -37,11 +37,7 @@ val pp_abi : Format.formatter -> abi -> unit
* line tool {[solo5-elftool query-abi]}. *)
val query_manifest : Owee_buf.t -> (mft, [> `Msg of string ]) result
(** [query_manifest buf] is the solo5 manifest of [buf], or an error message.
@raise Owee_buf.Invalid_format if [buf] is not valid ELF format *)
(** [query_manifest buf] is the solo5 manifest of [buf], or an error message. *)
val query_abi : Owee_buf.t -> (abi, [> `Msg of string ]) result
(** [query_abi buf] is the solo5 abi of [buf], or an error message.
@raise Owee_buf.Invalid_format if [buf] is not valid ELF format *)
(** [query_abi buf] is the solo5 abi of [buf], or an error message. *)