Skip to content

Commit e85e417

Browse files
codyrouxivg
andauthored
Validate arguments to String.sub (#49)
* Validate arguments to String.sub Check for potential situation in which `stop' - start'` is out of bounds of the buffer (which will raise a confusing `Invalid_argument "String.sub / Byte.sub"` error). * Update frontc/clexer.mll strengthens the check Co-authored-by: Ivan Gotovchits <[email protected]>
1 parent ce8c1d6 commit e85e417

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

frontc/clexer.mll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
** Project: FrontC
44
** File: frontc.mll
55
** Version: 4.1
6-
** Author: Hugues Cassé et al
6+
** Author: Hugues Cassé et al
77
*)
88
{
99
open Ctokens
1010
exception Eof
1111
exception InternalError of string
12-
let version = "Clexer V1.0f 10.8.99 Hugues Cassé"
12+
let version = "Clexer V1.0f 10.8.99 Hugues Cassé"
1313

1414

1515
(*
@@ -65,7 +65,7 @@ let underline_error (buffer : string) (start : int) (stop : int) =
6565
(
6666
(if start' > 0 then (String.sub buffer 0 start') else "")
6767
^ "\027[4m"
68-
^ (if (stop' - start') <> 0
68+
^ (if 0 <= start' && start' < stop' && stop <= len
6969
then (String.sub buffer start' (stop' - start' ) )
7070
else ""
7171
)

0 commit comments

Comments
 (0)