summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2018-10-30 00:50:20 +0100
committerPhilipp Gesang <phg@phi-gamma.net>2018-10-30 01:15:04 +0100
commitd7abe889accfc4a8e41d97d5f2327fde0ce9ca64 (patch)
tree3796ced04b2be2f6423b090aeb97863618503dbb
parent1d5a7501bbf2a33c60b24a71254b0c42939568aa (diff)
downloadocaml-sid-d7abe889accfc4a8e41d97d5f2327fde0ce9ca64.tar.gz
sid: fix off by one parsing bug
In the string representation, hyphen is always succeeded by a number so we need to terminate at input length minus one.
-rw-r--r--sid.ml2
-rw-r--r--sid_test.ml5
2 files changed, 6 insertions, 1 deletions
diff --git a/sid.ml b/sid.ml
index a2590fd..c6c7d3d 100644
--- a/sid.ml
+++ b/sid.ml
@@ -94,7 +94,7 @@ module StringFmt = struct
let p = 4 in
let p, ia = read_decimal_u64 s p in
let sa = ref [] and p' = ref p in
- while !p' < n && List.length !sa < max_subauth_count do
+ while !p' < n - 1 && List.length !sa < max_subauth_count do
expect_char s '-' !p';
let np, d = read_decimal_u32 s (!p' + 1) in
sa := d :: !sa;
diff --git a/sid_test.ml b/sid_test.ml
index f34e4b0..61e5366 100644
--- a/sid_test.ml
+++ b/sid_test.ml
@@ -72,6 +72,10 @@ let sf_parse_ia_junk_fail () =
assert_equal
e "Invalid SID [S-I-3-3-7]: expected ā€˜1ā€™ at position 2, found ā€˜Iā€™"
+let sf_parse_trailing_ok () =
+ let s = unwrap_of_string "S-1-0-0-" in
+ assert_equal (Sid.to_string s) "S-1-0-0"
+
let sf_parse_long_ok () =
let s = unwrap_of_string "S-1-1-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14"
and l = max_sid in
@@ -274,6 +278,7 @@ let string_format_test = "string-format-syntax" >:::
; "parse-empty-fail" >:: sf_parse_empty_fail
; "parse-junk-fail" >:: sf_parse_junk_fail
; "parse-ia-junk-fail" >:: sf_parse_ia_junk_fail
+ ; "parse-trailing-ok" >:: sf_parse_trailing_ok
; "parse-long-ok" >:: sf_parse_long_ok
; "parse-too-long-ok" >:: sf_parse_too_long_ok
]