Skip to content

Commit

Permalink
fix parsing: stricter checks for CRLF
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Oct 14, 2024
1 parent 3dd2a48 commit d38eb85
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/headers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ let parse_ ~(buf : Buf.t) (bs : IO.Input.t) : t =
let rec loop acc =
match IO.Input.read_line_using_opt ~buf bs with
| None -> raise End_of_file
| Some "" -> assert false
| Some "\r" -> acc
| Some line when line.[String.length line - 1] <> '\r' ->
bad_reqf 400 "bad header line, not ended in CRLF"
| Some line ->
let k, v =
try
Expand Down
3 changes: 3 additions & 0 deletions src/core/request.ml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ let parse_req_start ~client_addr ~get_time_s ~buf (bs : IO.Input.t) :
try
let line = IO.Input.read_line_using ~buf bs in
Log.debug (fun k -> k "parse request line: %S" line);
if line <> "" && line.[String.length line - 1] <> '\r' then
bad_reqf 400 "invalid status line, not ending in CRLF";
let start_time = get_time_s () in
let meth, path, version =
try
Expand Down

0 comments on commit d38eb85

Please sign in to comment.