From 602ae8c4597a2d4af51772e426df3d6f155df026 Mon Sep 17 00:00:00 2001 From: Athish Pranav D Date: Fri, 9 Aug 2024 09:38:20 +0530 Subject: [PATCH] Added check to parser header till trailing \r\n Signed-off-by: Athish Pranav D --- cohttp/src/header_io.ml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cohttp/src/header_io.ml b/cohttp/src/header_io.ml index eb12ae962c..1f8df0b88c 100644 --- a/cohttp/src/header_io.ml +++ b/cohttp/src/header_io.ml @@ -16,6 +16,8 @@ * }}}*) +exception Invalid_headers + let split_header str = match Stringext.split ~max:2 ~on:':' str with | [ x; y ] -> [ x; String.trim y ] @@ -29,11 +31,12 @@ module Make (IO : S.IO) = struct (* consume also trailing "^\r\n$" line *) let rec parse_headers' headers = read_line ic >>= function - | Some "" | None -> return headers + | Some "" -> return headers | Some line -> ( match split_header line with | [ hd; tl ] -> parse_headers' (Header.add headers hd tl) - | _ -> return headers) + | _ -> raise Invalid_headers) + | None -> raise Invalid_headers in parse_headers' (Header.init ())