mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
parse_addr_port was vague about what to do when port_out was NULL. Make it behave usefully.
svn:r4716
This commit is contained in:
parent
35b04df4fd
commit
666ab41e2b
@ -1135,13 +1135,15 @@ int is_local_IP(uint32_t ip) {
|
|||||||
* <b>address</b> is provided, set *<b>address</b> to a copy of the
|
* <b>address</b> is provided, set *<b>address</b> to a copy of the
|
||||||
* host portion of the string. If <b>addr</b> is provided, try to
|
* host portion of the string. If <b>addr</b> is provided, try to
|
||||||
* resolve the host portion of the string and store it into
|
* resolve the host portion of the string and store it into
|
||||||
* *<b>addr</b> (in host byte order). If <b>port</b> is provided,
|
* *<b>addr</b> (in host byte order). If <b>port_out</b> is provided,
|
||||||
* store the port number into *<b>port</b>, or 0 if no port is given.
|
* store the port number into *<b>port_out</b>, or 0 if no port is given.
|
||||||
|
* If <b>port_out</b> is NULL, then there must be no port number in
|
||||||
|
* <b>addrport</b>.
|
||||||
* Return 0 on success, -1 on failure.
|
* Return 0 on success, -1 on failure.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
parse_addr_port(const char *addrport, char **address, uint32_t *addr,
|
parse_addr_port(const char *addrport, char **address, uint32_t *addr,
|
||||||
uint16_t *port)
|
uint16_t *port_out)
|
||||||
{
|
{
|
||||||
const char *colon;
|
const char *colon;
|
||||||
char *_address = NULL;
|
char *_address = NULL;
|
||||||
@ -1149,7 +1151,6 @@ parse_addr_port(const char *addrport, char **address, uint32_t *addr,
|
|||||||
int ok = 1;
|
int ok = 1;
|
||||||
|
|
||||||
tor_assert(addrport);
|
tor_assert(addrport);
|
||||||
tor_assert(port);
|
|
||||||
|
|
||||||
colon = strchr(addrport, ':');
|
colon = strchr(addrport, ':');
|
||||||
if (colon) {
|
if (colon) {
|
||||||
@ -1159,6 +1160,11 @@ parse_addr_port(const char *addrport, char **address, uint32_t *addr,
|
|||||||
log_fn(LOG_WARN, "Port '%s' out of range", colon+1);
|
log_fn(LOG_WARN, "Port '%s' out of range", colon+1);
|
||||||
ok = 0;
|
ok = 0;
|
||||||
}
|
}
|
||||||
|
if (!port_out) {
|
||||||
|
log_fn(LOG_WARN, "Port '%s' given on '%s' when not required", colon+1,
|
||||||
|
addrport);
|
||||||
|
ok = 0;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
_address = tor_strdup(addrport);
|
_address = tor_strdup(addrport);
|
||||||
_port = 0;
|
_port = 0;
|
||||||
@ -1181,8 +1187,8 @@ parse_addr_port(const char *addrport, char **address, uint32_t *addr,
|
|||||||
*address = NULL;
|
*address = NULL;
|
||||||
tor_free(_address);
|
tor_free(_address);
|
||||||
}
|
}
|
||||||
if (port)
|
if (port_out)
|
||||||
*port = ok ? ((uint16_t) _port) : 0;
|
*port_out = ok ? ((uint16_t) _port) : 0;
|
||||||
|
|
||||||
return ok ? 0 : -1;
|
return ok ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user