control: Catch DML errors when parsing control messages

This commit is contained in:
Joshua Scott 2018-04-11 00:50:10 +01:00
parent 88f98fd84c
commit 599afed56f
3 changed files with 36 additions and 6 deletions

View File

@ -1,5 +1,6 @@
#include "ki/protocol/control/ClientHello.h" #include "ki/protocol/control/ClientHello.h"
#include "ki/dml/Record.h" #include "ki/dml/Record.h"
#include "ki/protocol/exception.h"
namespace ki namespace ki
{ {
@ -64,7 +65,16 @@ namespace control
auto *timestamp = record.add_field<dml::INT>("m_timestamp"); auto *timestamp = record.add_field<dml::INT>("m_timestamp");
auto *milliseconds = record.add_field<dml::UINT>("m_milliseconds"); auto *milliseconds = record.add_field<dml::UINT>("m_milliseconds");
auto *session_id = record.add_field<dml::USHRT>("m_session_id"); auto *session_id = record.add_field<dml::USHRT>("m_session_id");
record.read_from(istream); try
{
record.read_from(istream);
}
catch (dml::parse_error &e)
{
std::ostringstream oss;
oss << "Error reading ClientHello payload: " << e.what();
throw parse_error(oss.str());
}
m_timestamp = timestamp->get_value(); m_timestamp = timestamp->get_value();
m_milliseconds = milliseconds->get_value(); m_milliseconds = milliseconds->get_value();

View File

@ -1,5 +1,6 @@
#include "ki/protocol/control/Ping.h" #include "ki/protocol/control/Ping.h"
#include "ki/dml/Record.h" #include "ki/dml/Record.h"
#include "ki/protocol/exception.h"
namespace ki namespace ki
{ {
@ -59,7 +60,16 @@ namespace control
auto *session_id = record.add_field<dml::USHRT>("m_session_id"); auto *session_id = record.add_field<dml::USHRT>("m_session_id");
auto *milliseconds = record.add_field<dml::USHRT>("m_milliseconds"); auto *milliseconds = record.add_field<dml::USHRT>("m_milliseconds");
auto *minutes = record.add_field<dml::UBYT>("m_minutes"); auto *minutes = record.add_field<dml::UBYT>("m_minutes");
record.read_from(istream); try
{
record.read_from(istream);
}
catch (dml::parse_error &e)
{
std::ostringstream oss;
oss << "Error reading Ping payload: " << e.what();
throw parse_error(oss.str());
}
m_session_id = session_id->get_value(); m_session_id = session_id->get_value();
m_milliseconds = milliseconds->get_value(); m_milliseconds = milliseconds->get_value();

View File

@ -1,5 +1,6 @@
#include "ki/protocol/control/ServerHello.h" #include "ki/protocol/control/ServerHello.h"
#include "ki/dml/Record.h" #include "ki/dml/Record.h"
#include "ki/protocol/exception.h"
namespace ki namespace ki
{ {
@ -62,7 +63,16 @@ namespace control
record.add_field<dml::UINT>("unknown"); record.add_field<dml::UINT>("unknown");
auto *timestamp = record.add_field<dml::INT>("m_timestamp"); auto *timestamp = record.add_field<dml::INT>("m_timestamp");
auto *milliseconds = record.add_field<dml::UINT>("m_milliseconds"); auto *milliseconds = record.add_field<dml::UINT>("m_milliseconds");
record.read_from(istream); try
{
record.read_from(istream);
}
catch (dml::parse_error &e)
{
std::ostringstream oss;
oss << "Error reading ServerHello payload: " << e.what();
throw parse_error(oss.str());
}
m_session_id = session_id->get_value(); m_session_id = session_id->get_value();
m_timestamp = timestamp->get_value(); m_timestamp = timestamp->get_value();