summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-08-05 01:51:19 +0000
committerNick Mathewson <nickm@torproject.org>2005-08-05 01:51:19 +0000
commit666ab41e2bc95b9159fa13d347ad832074513614 (patch)
tree464d31bc9a0c577975430e876d90a901952435fd
parent35b04df4fd2818cc60e38ff584981d13da5649d1 (diff)
downloadtor-666ab41e2bc95b9159fa13d347ad832074513614.tar.gz
tor-666ab41e2bc95b9159fa13d347ad832074513614.zip
parse_addr_port was vague about what to do when port_out was NULL. Make it behave usefully.
svn:r4716
-rw-r--r--src/common/util.c18
1 files changed, 12 insertions, 6 deletions
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) {
* <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
* resolve the host portion of the string and store it into
- * *<b>addr</b> (in host byte order). If <b>port</b> is provided,
- * store the port number into *<b>port</b>, or 0 if no port is given.
+ * *<b>addr</b> (in host byte order). If <b>port_out</b> is provided,
+ * 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.
*/
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;
}