mirror of
https://github.com/transmission/transmission
synced 2025-02-22 14:10:34 +00:00
Support IPv6 addresses when whitelisting hosts (see #468)
This commit is contained in:
parent
4b359a52b2
commit
90686f30ce
1 changed files with 16 additions and 2 deletions
|
@ -590,6 +590,16 @@ isAddressAllowed (const tr_rpc_server * server, const char * address)
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool
|
||||
isIPAddressWithOptionalPort (const char * host)
|
||||
{
|
||||
struct sockaddr_storage address;
|
||||
int address_len = sizeof (address);
|
||||
|
||||
/* TODO: move to net.{c,h} */
|
||||
return evutil_parse_sockaddr_port (host, (struct sockaddr *) &address, &address_len) != -1;
|
||||
}
|
||||
|
||||
static bool
|
||||
isHostnameAllowed (const tr_rpc_server * server, struct evhttp_request * req)
|
||||
{
|
||||
|
@ -607,11 +617,15 @@ isHostnameAllowed (const tr_rpc_server * server, struct evhttp_request * req)
|
|||
if (host == NULL)
|
||||
return false;
|
||||
|
||||
/* IP address is always acceptable. */
|
||||
if (isIPAddressWithOptionalPort (host))
|
||||
return true;
|
||||
|
||||
/* Host header might include the port. */
|
||||
char * const hostname = tr_strndup (host, strcspn (host, ":"));
|
||||
|
||||
/* localhost or ipaddress is always acceptable. */
|
||||
if (strcmp (hostname, "localhost") == 0 || strcmp (hostname, "localhost.") == 0 || tr_addressIsIP (hostname))
|
||||
/* localhost is always acceptable. */
|
||||
if (strcmp (hostname, "localhost") == 0 || strcmp (hostname, "localhost.") == 0)
|
||||
{
|
||||
tr_free (hostname);
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue