tres/secure_channel: Fix to avoid crash when receive malformed packet

This commit is contained in:
Eishun Kondoh 2018-05-02 15:39:58 +09:00
parent bc3c65cfa9
commit 6bba512271
5 changed files with 66 additions and 29 deletions

View file

@ -15,18 +15,22 @@ defmodule Openflow do
end
def read(<<ver::8, type::8, len::16, xid::32, binary2::bytes>>) do
body_len = len - @ofp_header_size
<<body_bin::bytes-size(body_len), rest::bytes>> = binary2
try do
body_len = len - @ofp_header_size
<<body_bin::bytes-size(body_len), rest::bytes>> = binary2
result =
type
|> Openflow.Enums.to_atom(:openflow_codec)
|> do_read(body_bin)
result = type
|> Openflow.Enums.to_atom(:openflow_codec)
|> do_read(body_bin)
case result do
{:ok, struct} -> {:ok, %{struct | version: ver, xid: xid}, rest}
{:error, reason} -> {:error, reason}
end
case result do
{:ok, struct} -> {:ok, %{struct | version: ver, xid: xid}, rest}
{:error, reason} -> {:error, reason}
end
catch
_c, _e ->
{:error, :malformed_packet}
end
end
def to_binary(messages) when is_list(messages) do