diff --git a/tools/ocaml/libs/xb/partial.ml b/tools/ocaml/libs/xb/partial.ml index b6e2a716e2..3aa8927eb7 100644 --- a/tools/ocaml/libs/xb/partial.ml +++ b/tools/ocaml/libs/xb/partial.ml @@ -36,7 +36,7 @@ let of_string s = This will leave the guest connection is a bad state and will be hard to recover from without restarting the connection (ie rebooting the guest) *) - let dlen = min xenstore_payload_max dlen in + let dlen = max 0 (min xenstore_payload_max dlen) in { tid = tid; rid = rid; @@ -46,8 +46,8 @@ let of_string s = } let append pkt s sz = - if pkt.len > 4096 then failwith "Buffer.add: cannot grow buffer"; - Buffer.add_string pkt.buf (String.sub s 0 sz) + if Buffer.length pkt.buf + sz > xenstore_payload_max then failwith "Buffer.add: cannot grow buffer"; + Buffer.add_substring pkt.buf s 0 sz let to_complete pkt = pkt.len - (Buffer.length pkt.buf) diff --git a/tools/ocaml/xenstored/process.ml b/tools/ocaml/xenstored/process.ml index ce39ce28b5..6cb990ee7f 100644 --- a/tools/ocaml/xenstored/process.ml +++ b/tools/ocaml/xenstored/process.ml @@ -722,7 +722,7 @@ let do_input store cons doms con = History.reconnect con; info "%s reconnection complete" (Connection.get_domstr con); None - | Failure exp -> + | Invalid_argument exp | Failure exp -> error "caught exception %s" exp; error "got a bad client %s" (sprintf "%-8s" (Connection.get_domstr con)); Connection.mark_as_bad con;