From 895338119b84eb0b310fc0aa225f7e0dbfb70fc1 Mon Sep 17 00:00:00 2001 From: Hannes Mehnert Date: Wed, 4 Sep 2024 10:32:03 +0200 Subject: [PATCH] require tls 1.0.2 and use the Tls_lwt.read with offset --- albatross.opam | 2 +- tls/vmm_tls_lwt.ml | 14 +++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/albatross.opam b/albatross.opam index 6aca17f..b6837f1 100644 --- a/albatross.opam +++ b/albatross.opam @@ -21,7 +21,7 @@ depends: [ "fmt" {>= "0.8.7"} "x509" {>= "1.0.0"} "tls" {>= "1.0.0"} - "tls-lwt" {>= "1.0.0"} + "tls-lwt" {>= "1.0.2"} "mirage-crypto" {>= "1.0.0"} "mirage-crypto-rng" {>= "1.0.0"} "asn1-combinators" {>= "0.3.0"} diff --git a/tls/vmm_tls_lwt.ml b/tls/vmm_tls_lwt.ml index e092a3a..973436e 100644 --- a/tls/vmm_tls_lwt.ml +++ b/tls/vmm_tls_lwt.ml @@ -8,20 +8,12 @@ let read_tls t = if l = 0 then Lwt.return (Ok ()) else - let buf' = - if off = 0 then buf else Bytes.create l - in - (* TODO Tls_lwt.Unix.read should receive an (optional) "off" parameter. *) - Tls_lwt.Unix.read t buf' >>= function + Tls_lwt.Unix.read t ~off buf >>= function | 0 -> Logs.debug (fun m -> m "TLS: end of file") ; Lwt.return (Error `Eof) - | x when x == l -> - if off = 0 then () else Bytes.blit buf' 0 buf off x; - Lwt.return (Ok ()) - | x when x < l -> - if off = 0 then () else Bytes.blit buf' 0 buf off x; - r_n buf (off + x) tot + | x when x == l -> Lwt.return (Ok ()) + | x when x < l -> r_n buf (off + x) tot | _ -> Logs.err (fun m -> m "TLS: read too much, shouldn't happen") ; Lwt.return (Error `Toomuch)