Browse Source

catch lexical_cast exceptions

pull/1794/head
orignal 2 years ago
parent
commit
69ca3bc75d
  1. 59
      libi2pd/RouterInfo.cpp

59
libi2pd/RouterInfo.cpp

@ -257,20 +257,38 @@ namespace data
if (!ecode && !address->host.is_unspecified ()) isHost = true; if (!ecode && !address->host.is_unspecified ()) isHost = true;
} }
else if (!strcmp (key, "port")) else if (!strcmp (key, "port"))
address->port = boost::lexical_cast<int>(value); {
try
{
address->port = boost::lexical_cast<int>(value);
}
catch (std::exception& ex)
{
LogPrint (eLogWarning, "RouterInfo: 'port' exception ", ex.what ());
}
}
else if (!strcmp (key, "mtu")) else if (!strcmp (key, "mtu"))
{ {
if (address->ssu) if (address->ssu)
address->ssu->mtu = boost::lexical_cast<int>(value); {
try
{
address->ssu->mtu = boost::lexical_cast<int>(value);
}
catch (std::exception& ex)
{
LogPrint (eLogWarning, "RouterInfo: 'mtu' exception ", ex.what ());
}
}
else else
LogPrint (eLogWarning, "RouterInfo: Unexpected field 'mtu' for NTCP"); LogPrint (eLogWarning, "RouterInfo: Unexpected field 'mtu' for NTCP2");
} }
else if (!strcmp (key, "key")) else if (!strcmp (key, "key"))
{ {
if (address->ssu) if (address->ssu)
isIntroKey = (Base64ToByteStream (value, strlen (value), address->i, 32) == 32); isIntroKey = (Base64ToByteStream (value, strlen (value), address->i, 32) == 32);
else else
LogPrint (eLogWarning, "RouterInfo: Unexpected field 'key' for NTCP"); LogPrint (eLogWarning, "RouterInfo: Unexpected field 'key' for NTCP2");
} }
else if (!strcmp (key, "caps")) else if (!strcmp (key, "caps"))
address->caps = ExtractAddressCaps (value); address->caps = ExtractAddressCaps (value);
@ -327,13 +345,40 @@ namespace data
introducer.iHost = boost::asio::ip::address::from_string (value, ecode); introducer.iHost = boost::asio::ip::address::from_string (value, ecode);
} }
else if (!strcmp (key, "iport")) else if (!strcmp (key, "iport"))
introducer.iPort = boost::lexical_cast<int>(value); {
try
{
introducer.iPort = boost::lexical_cast<int>(value);
}
catch (std::exception& ex)
{
LogPrint (eLogWarning, "RouterInfo: 'iport' exception ", ex.what ());
}
}
else if (!strcmp (key, "itag")) else if (!strcmp (key, "itag"))
introducer.iTag = boost::lexical_cast<uint32_t>(value); {
try
{
introducer.iTag = boost::lexical_cast<uint32_t>(value);
}
catch (std::exception& ex)
{
LogPrint (eLogWarning, "RouterInfo: 'itag' exception ", ex.what ());
}
}
else if (!strcmp (key, "ikey") || !strcmp (key, "ih")) else if (!strcmp (key, "ikey") || !strcmp (key, "ih"))
Base64ToByteStream (value, strlen (value), introducer.iKey, 32); Base64ToByteStream (value, strlen (value), introducer.iKey, 32);
else if (!strcmp (key, "iexp")) else if (!strcmp (key, "iexp"))
introducer.iExp = boost::lexical_cast<uint32_t>(value); {
try
{
introducer.iExp = boost::lexical_cast<uint32_t>(value);
}
catch (std::exception& ex)
{
LogPrint (eLogWarning, "RouterInfo: 'iexp' exception ", ex.what ());
}
}
} }
if (!s) return; if (!s) return;
} }

Loading…
Cancel
Save