mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 03:37:49 +02:00
[RI] validate addresses when parsing RI
This commit is contained in:
parent
5da9abe26e
commit
67fd77987e
2 changed files with 19 additions and 17 deletions
|
@ -15,6 +15,7 @@
|
||||||
#include "NetDb.hpp"
|
#include "NetDb.hpp"
|
||||||
#include "RouterContext.h"
|
#include "RouterContext.h"
|
||||||
#include "RouterInfo.h"
|
#include "RouterInfo.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
|
@ -207,21 +208,22 @@ namespace data
|
||||||
if (!strcmp (key, "host"))
|
if (!strcmp (key, "host"))
|
||||||
{
|
{
|
||||||
boost::system::error_code ecode;
|
boost::system::error_code ecode;
|
||||||
address->host = boost::asio::ip::address::from_string (value, ecode);
|
auto hostaddr = boost::asio::ip::address::from_string (value, ecode); // store in temporary variable
|
||||||
if (!ecode)
|
if (!ecode)
|
||||||
{
|
{
|
||||||
#if BOOST_VERSION >= 104900
|
#if BOOST_VERSION >= 104900
|
||||||
if (!address->host.is_unspecified ()) // check if address is valid
|
if (!hostaddr.is_unspecified () && !i2p::util::net::IsInReservedRange(hostaddr)) // check if address is valid
|
||||||
#else
|
#else
|
||||||
address->host.to_string (ecode);
|
hostaddr.to_string (ecode);
|
||||||
if (!ecode)
|
if (!ecode && !i2p::util::net::IsInReservedRange(hostaddr))
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
address->host = hostaddr;
|
||||||
// add supported protocol
|
// add supported protocol
|
||||||
if (address->host.is_v4 ())
|
if (address->host.is_v4 ())
|
||||||
supportedTransports |= (address->transportStyle == eTransportNTCP) ? eNTCPV4 : eSSUV4;
|
supportedTransports |= (address->transportStyle == eTransportNTCP) ? (isNTCP2Only ? eNTCP2V4 : eNTCPV4) : eSSUV4;
|
||||||
else
|
else
|
||||||
supportedTransports |= (address->transportStyle == eTransportNTCP) ? eNTCPV6 : eSSUV6;
|
supportedTransports |= (address->transportStyle == eTransportNTCP) ? (isNTCP2Only ? eNTCP2V6 : eNTCPV6) : eSSUV6;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,9 @@ int inet_pton_xp(int af, const char *src, void *dst)
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define address_pair_v4(a,b) { boost::asio::ip::address_v4::from_string (a).to_ulong (), boost::asio::ip::address_v4::from_string (b).to_ulong () }
|
||||||
|
#define address_pair_v6(a,b) { boost::asio::ip::address_v6::from_string (a).to_bytes (), boost::asio::ip::address_v6::from_string (b).to_bytes () }
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
namespace util
|
namespace util
|
||||||
|
@ -340,9 +343,6 @@ namespace net
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#define address_pair_v4(a,b) { boost::asio::ip::address_v4::from_string (a).to_ulong (), boost::asio::ip::address_v4::from_string (b).to_ulong () }
|
|
||||||
#define address_pair_v6(a,b) { boost::asio::ip::address_v6::from_string (a).to_bytes (), boost::asio::ip::address_v6::from_string (b).to_bytes () }
|
|
||||||
|
|
||||||
bool IsInReservedRange(const boost::asio::ip::address& host) {
|
bool IsInReservedRange(const boost::asio::ip::address& host) {
|
||||||
// https://en.wikipedia.org/wiki/Reserved_IP_addresses
|
// https://en.wikipedia.org/wiki/Reserved_IP_addresses
|
||||||
if(host.is_v4())
|
if(host.is_v4())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue