From 30557c0fdfdc8eacf481f41ab4c97536763c0fa9 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sun, 9 Dec 2018 22:34:56 +0100 Subject: 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. --- sid.ml | 14 ++++++++++++-- 1 file 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 -- cgit v1.2.3