[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r9169: Clean up logic in parse_port_range(); accept 0 on low end an (in tor/trunk: . src/common)
- To: or-cvs@xxxxxxxxxxxxx
- Subject: [or-cvs] r9169: Clean up logic in parse_port_range(); accept 0 on low end an (in tor/trunk: . src/common)
- From: nickm@xxxxxxxx
- Date: Thu, 21 Dec 2006 12:38:16 -0500 (EST)
- Delivered-to: archiver@seul.org
- Delivered-to: or-cvs-outgoing@seul.org
- Delivered-to: or-cvs@seul.org
- Delivery-date: Thu, 21 Dec 2006 12:38:26 -0500
- Reply-to: or-talk@xxxxxxxxxxxxx
- Sender: owner-or-cvs@xxxxxxxxxxxxx
Author: nickm
Date: 2006-12-21 12:38:15 -0500 (Thu, 21 Dec 2006)
New Revision: 9169
Modified:
tor/trunk/
tor/trunk/src/common/util.c
Log:
r11670@Kushana: nickm | 2006-12-21 12:23:55 -0500
Clean up logic in parse_port_range(); accept 0 on low end and 65536 on high end for people who are bad at math.
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/trunk [r11670] on c95137ef-5f19-0410-b913-86e773d04f59
Modified: tor/trunk/src/common/util.c
===================================================================
--- tor/trunk/src/common/util.c 2006-12-21 03:22:59 UTC (rev 9168)
+++ tor/trunk/src/common/util.c 2006-12-21 17:38:15 UTC (rev 9169)
@@ -1745,41 +1745,48 @@
parse_port_range(const char *port, uint16_t *port_min_out,
uint16_t *port_max_out)
{
+ int port_min, port_max, ok;
tor_assert(port_min_out);
tor_assert(port_max_out);
if (!port || *port == '\0' || strcmp(port, "*") == 0) {
- *port_min_out = 1;
- *port_max_out = 65535;
+ port_min = 1;
+ port_max = 65535;
} else {
char *endptr = NULL;
- *port_min_out = (uint16_t) tor_parse_long(port, 10, 1, 65535,
- NULL, &endptr);
- if (*endptr == '-' && *port_min_out) {
+ port_min = tor_parse_long(port, 10, 0, 65535, &ok, &endptr);
+ if (!ok) {
+ log_warn(LD_GENERAL,
+ "Malformed port %s on address range; rejecting.",
+ escaped(port));
+ return -1;
+ } else if (endptr && *endptr == '-') {
port = endptr+1;
endptr = NULL;
- *port_max_out = (uint16_t) tor_parse_long(port, 10, 1, 65535, NULL,
- &endptr);
- if (*endptr || !*port_max_out) {
+ port_max = tor_parse_long(port, 10, 1, 65536, &ok, &endptr);
+ if (!ok) {
log_warn(LD_GENERAL,
"Malformed port %s on address range; rejecting.",
escaped(port));
return -1;
}
- } else if (*endptr || !*port_min_out) {
- log_warn(LD_GENERAL,
- "Malformed port %s on address range; rejecting.",
- escaped(port));
- return -1;
} else {
- *port_max_out = *port_min_out;
+ port_max = port_min;
}
- if (*port_min_out > *port_max_out) {
+ if (port_min > port_max) {
log_warn(LD_GENERAL, "Insane port range on address policy; rejecting.");
return -1;
}
}
+ if (port_min < 1)
+ port_min = 1;
+ if (port_max > 65535)
+ port_max = 65535;
+
+ *port_min_out = (uint16_t) port_min;
+ *port_max_out = (uint16_t) port_max;
+
return 0;
}