vbmithr / ocaml-websocket

Websocket library for OCaml
ISC License
161 stars 44 forks source link

fix: don't use Bytes.unsafe_{of,to}_string for not owned strings #134

Closed ushitora-anqou closed 3 months ago

ushitora-anqou commented 3 months ago

Websocket module uses Bytes.unsafe_{of,to}_string improperly. For example, write_frame_to_buf's argument fr.content isn't owned and is modified by Bytes.set in xor, but Bytes.unsafe_of_string is applied to it. That is, when a user calls write_frame_to_buf, fr.content is unexpectedly modified.

This PR fixes the above issue. As far as I understand, all uses of Bytes.unsafe_{to,of}_string are applied to non-owned strings. So this PR fixes them to use the safe counterparts.