Browse Source

catch lexical_cast exceptions

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

49
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"))
{
try
{
address->port = boost::lexical_cast<int>(value); 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)
{
try
{
address->ssu->mtu = boost::lexical_cast<int>(value); 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,14 +345,41 @@ 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"))
{
try
{
introducer.iPort = boost::lexical_cast<int>(value); 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"))
{
try
{
introducer.iTag = boost::lexical_cast<uint32_t>(value); 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"))
{
try
{
introducer.iExp = boost::lexical_cast<uint32_t>(value); 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;
} }
if (address->transportStyle == eTransportNTCP) if (address->transportStyle == eTransportNTCP)

Loading…
Cancel
Save