Skip to content

Commit

Permalink
Fix crash in string.interpolate (Fixes: #2883)
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Feb 12, 2023
1 parent 5f7de88 commit d38ca95
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Fixed:
* Fixed input polling stop (#2769)
* Fixed crash in external processes when received a `Unix.EINTR`
event (#2861)
* Fixed crash in `string.interpolate` (#2883)
* Cleaned up srt support.

---
Expand Down
25 changes: 16 additions & 9 deletions src/tools/utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
*****************************************************************************)

(* Util to log exception and backtrace together
when log level is set to info and just exception
as severe otherwise. Backtrace should be captured as early
as possible. *)
let log_exception ~(log : Log.t) ~bt msg =
if log#active 4 (* info *) then log#info "%s\n%s" msg bt
else log#severe "%s" msg

(* Force locale to C *)
external force_locale : unit -> unit = "liquidsoap_set_locale" [@@noalloc]

Expand Down Expand Up @@ -380,6 +388,7 @@ let unbreak_md md =
* and interpolates them just like make does, using the hash table for
* variable definitions. *)
let interpolate =
let log = Log.make ["string"; "interpolate"] in
(* TODO Use PCRE *)
let quoted = "\"\\(\\([^\"\\]\\|\\(\\\\\"\\)\\)*\\)\"" in
(* 3 groups *)
Expand Down Expand Up @@ -418,7 +427,13 @@ let interpolate =
if p = "\\" then Str.matched_group 2 s
else p ^ find (Str.matched_group 3 s))
in
interpolate (process_if s)
try interpolate (process_if s)
with exn ->
let bt = Printexc.get_backtrace () in
log_exception ~log ~bt
(Printf.sprintf "Error while interpolating string: %s"
(Printexc.to_string exn));
s

(** [which s] is equivalent to /usr/bin/which s, raises Not_found on error *)
let which ~path s =
Expand Down Expand Up @@ -869,14 +884,6 @@ let string_of_matrix a =
done;
Strings.Mutable.to_string ans

(* Util to log exception and backtrace together
when log level is set to info and just exception
as severe otherwise. Backtrace should be captured as early
as possible. *)
let log_exception ~(log : Log.t) ~bt msg =
if log#active 4 (* info *) then log#info "%s\n%s" msg bt
else log#severe "%s" msg

(** Operations on versions of Liquidsoap. *)
module Version = struct
type t = int list * string
Expand Down

0 comments on commit d38ca95

Please sign in to comment.