summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2018-12-09 22:34:56 +0100
committerPhilipp Gesang <phg@phi-gamma.net>2018-12-09 22:36:18 +0100
commit30557c0fdfdc8eacf481f41ab4c97536763c0fa9 (patch)
tree52cdb1696cd8063b77b00966785fc3ab4e1fcfda
parent4a754036826405dd488b0718315b434c9cb726d0 (diff)
downloadocaml-sid-30557c0fdfdc8eacf481f41ab4c97536763c0fa9.tar.gz
sid.ml: give hex ia reader enough leeway for sloppy parsing
In MS mode we need for much shorter strings to pass through to the hex parser.
-rw-r--r--sid.ml14
1 files changed, 12 insertions, 2 deletions
diff --git a/sid.ml b/sid.ml
index 17c8124..0bcba50 100644
--- a/sid.ml
+++ b/sid.ml
@@ -92,7 +92,12 @@ module Con_strict = struct
let name = "strict"
let parse_hex_ia s p =
- assert (p <= String.length s - ident_auth_hexlen);
+ if p > String.length s - ident_auth_hexlen then
+ raise (Invalid_argument
+ (Printf.sprintf
+ "Invalid SID [%s]: conformant string encoding mandates \
+ exactly 12 hex digits"
+ s)) else
let e = p + ident_auth_hexlen - 1 in
let b = Bytes.make ident_auth_hexlen '\x2a' in
Bytes.set b 0 '0'; (* hex indicator for U64.of_string *)
@@ -240,9 +245,14 @@ module MkStringFmt (Con : Conformance) = struct
Con.name (U64.to_string ia))) else
p, ia
+ (* Below constant determines the lowest length at which it is sensible
+ to test for the “-0x…” component that indicates a hex encoded ia. We
+ require at least one hex digit to allow non-conformant parsing modes. *)
+ let min_hexlen = String.length "S-1-0xf"
+
let read_ident_auth s p =
let r = String.length s - p in
- if r < ident_auth_hexlen then ident_auth_decimal s p else (* hex can’t fit *)
+ if r < min_hexlen then ident_auth_decimal s p else
match s.[p], s.[p+1] with
| '0', 'x' -> read_ident_auth_hex s p
| _ -> ident_auth_decimal s p