diff --git a/src/common/util.c b/src/common/util.c index e762b1853e..ea726d1135 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1135,13 +1135,15 @@ int is_local_IP(uint32_t ip) { * address is provided, set *address to a copy of the * host portion of the string. If addr is provided, try to * resolve the host portion of the string and store it into - * *addr (in host byte order). If port is provided, - * store the port number into *port, or 0 if no port is given. + * *addr (in host byte order). If port_out is provided, + * store the port number into *port_out, or 0 if no port is given. + * If port_out is NULL, then there must be no port number in + * addrport. * Return 0 on success, -1 on failure. */ int parse_addr_port(const char *addrport, char **address, uint32_t *addr, - uint16_t *port) + uint16_t *port_out) { const char *colon; char *_address = NULL; @@ -1149,7 +1151,6 @@ parse_addr_port(const char *addrport, char **address, uint32_t *addr, int ok = 1; tor_assert(addrport); - tor_assert(port); colon = strchr(addrport, ':'); 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); ok = 0; } + if (!port_out) { + log_fn(LOG_WARN, "Port '%s' given on '%s' when not required", colon+1, + addrport); + ok = 0; + } } else { _address = tor_strdup(addrport); _port = 0; @@ -1181,8 +1187,8 @@ parse_addr_port(const char *addrport, char **address, uint32_t *addr, *address = NULL; tor_free(_address); } - if (port) - *port = ok ? ((uint16_t) _port) : 0; + if (port_out) + *port_out = ok ? ((uint16_t) _port) : 0; return ok ? 0 : -1; }