mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
when an exit node gets a malformed begin cell, don't complain to
the node operator, since he can't do anything about it. svn:r6733
This commit is contained in:
parent
3c4205c872
commit
fad85f173a
@ -1486,8 +1486,8 @@ is_local_IP(uint32_t ip)
|
|||||||
* 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(int severity, const char *addrport, char **address,
|
||||||
uint16_t *port_out)
|
uint32_t *addr, uint16_t *port_out)
|
||||||
{
|
{
|
||||||
const char *colon;
|
const char *colon;
|
||||||
char *_address = NULL;
|
char *_address = NULL;
|
||||||
@ -1501,14 +1501,14 @@ parse_addr_port(const char *addrport, char **address, uint32_t *addr,
|
|||||||
_address = tor_strndup(addrport, colon-addrport);
|
_address = tor_strndup(addrport, colon-addrport);
|
||||||
_port = (int) tor_parse_long(colon+1,10,1,65535,NULL,NULL);
|
_port = (int) tor_parse_long(colon+1,10,1,65535,NULL,NULL);
|
||||||
if (!_port) {
|
if (!_port) {
|
||||||
log_warn(LD_GENERAL, "Port %s out of range", escaped(colon+1));
|
log_fn(severity, LD_GENERAL, "Port %s out of range", escaped(colon+1));
|
||||||
ok = 0;
|
ok = 0;
|
||||||
}
|
}
|
||||||
if (!port_out) {
|
if (!port_out) {
|
||||||
char *esc_addrport = esc_for_log(addrport);
|
char *esc_addrport = esc_for_log(addrport);
|
||||||
log_warn(LD_GENERAL,
|
log_fn(severity, LD_GENERAL,
|
||||||
"Port %s given on %s when not required",
|
"Port %s given on %s when not required",
|
||||||
escaped(colon+1), esc_addrport);
|
escaped(colon+1), esc_addrport);
|
||||||
tor_free(esc_addrport);
|
tor_free(esc_addrport);
|
||||||
ok = 0;
|
ok = 0;
|
||||||
}
|
}
|
||||||
@ -1520,7 +1520,7 @@ parse_addr_port(const char *addrport, char **address, uint32_t *addr,
|
|||||||
if (addr) {
|
if (addr) {
|
||||||
/* There's an addr pointer, so we need to resolve the hostname. */
|
/* There's an addr pointer, so we need to resolve the hostname. */
|
||||||
if (tor_lookup_hostname(_address,addr)) {
|
if (tor_lookup_hostname(_address,addr)) {
|
||||||
log_warn(LD_NET, "Couldn't look up %s", escaped(_address));
|
log_fn(severity, LD_NET, "Couldn't look up %s", escaped(_address));
|
||||||
ok = 0;
|
ok = 0;
|
||||||
*addr = 0;
|
*addr = 0;
|
||||||
}
|
}
|
||||||
|
@ -168,8 +168,8 @@ int path_is_relative(const char *filename);
|
|||||||
/* Net helpers */
|
/* Net helpers */
|
||||||
int is_internal_IP(uint32_t ip, int for_listening);
|
int is_internal_IP(uint32_t ip, int for_listening);
|
||||||
int is_local_IP(uint32_t ip);
|
int is_local_IP(uint32_t ip);
|
||||||
int parse_addr_port(const char *addrport, char **address, uint32_t *addr,
|
int parse_addr_port(int severity, const char *addrport, char **address,
|
||||||
uint16_t *port);
|
uint32_t *addr, uint16_t *port_out);
|
||||||
int parse_port_range(const char *port, uint16_t *port_min_out,
|
int parse_port_range(const char *port, uint16_t *port_min_out,
|
||||||
uint16_t *port_max_out);
|
uint16_t *port_max_out);
|
||||||
int parse_addr_and_port_range(const char *s, uint32_t *addr_out,
|
int parse_addr_and_port_range(const char *s, uint32_t *addr_out,
|
||||||
|
@ -2040,7 +2040,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
|
|||||||
for (line = options->SocksListenAddress; line; line = line->next) {
|
for (line = options->SocksListenAddress; line; line = line->next) {
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
if (parse_addr_port(line->value, &address, &addr, &port)<0)
|
if (parse_addr_port(LOG_WARN, line->value, &address, &addr, &port)<0)
|
||||||
continue; /* We'll warn about this later. */
|
continue; /* We'll warn about this later. */
|
||||||
if (!is_internal_IP(addr, 1) &&
|
if (!is_internal_IP(addr, 1) &&
|
||||||
(!old_options || !config_lines_eq(old_options->SocksListenAddress,
|
(!old_options || !config_lines_eq(old_options->SocksListenAddress,
|
||||||
@ -2338,7 +2338,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
|
|||||||
REJECT("Failed to parse accounting options. See logs for details.");
|
REJECT("Failed to parse accounting options. See logs for details.");
|
||||||
|
|
||||||
if (options->HttpProxy) { /* parse it now */
|
if (options->HttpProxy) { /* parse it now */
|
||||||
if (parse_addr_port(options->HttpProxy, NULL,
|
if (parse_addr_port(LOG_WARN, options->HttpProxy, NULL,
|
||||||
&options->HttpProxyAddr, &options->HttpProxyPort) < 0)
|
&options->HttpProxyAddr, &options->HttpProxyPort) < 0)
|
||||||
REJECT("HttpProxy failed to parse or resolve. Please fix.");
|
REJECT("HttpProxy failed to parse or resolve. Please fix.");
|
||||||
if (options->HttpProxyPort == 0) { /* give it a default */
|
if (options->HttpProxyPort == 0) { /* give it a default */
|
||||||
@ -2352,7 +2352,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options->HttpsProxy) { /* parse it now */
|
if (options->HttpsProxy) { /* parse it now */
|
||||||
if (parse_addr_port(options->HttpsProxy, NULL,
|
if (parse_addr_port(LOG_WARN, options->HttpsProxy, NULL,
|
||||||
&options->HttpsProxyAddr, &options->HttpsProxyPort) <0)
|
&options->HttpsProxyAddr, &options->HttpsProxyPort) <0)
|
||||||
REJECT("HttpsProxy failed to parse or resolve. Please fix.");
|
REJECT("HttpsProxy failed to parse or resolve. Please fix.");
|
||||||
if (options->HttpsProxyPort == 0) { /* give it a default */
|
if (options->HttpsProxyPort == 0) { /* give it a default */
|
||||||
@ -3127,8 +3127,8 @@ parse_redirect_line(smartlist_t *result, config_line_t *line, char **msg)
|
|||||||
if (0==strcasecmp(smartlist_get(elements,1), "pass")) {
|
if (0==strcasecmp(smartlist_get(elements,1), "pass")) {
|
||||||
r->is_redirect = 0;
|
r->is_redirect = 0;
|
||||||
} else {
|
} else {
|
||||||
if (parse_addr_port(smartlist_get(elements,1),NULL,&r->addr_dest,
|
if (parse_addr_port(LOG_WARN, smartlist_get(elements,1),NULL,
|
||||||
&r->port_dest)) {
|
&r->addr_dest, &r->port_dest)) {
|
||||||
*msg = tor_strdup("Error parsing dest address in RedirectExit line");
|
*msg = tor_strdup("Error parsing dest address in RedirectExit line");
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
@ -3193,7 +3193,7 @@ parse_dir_server_line(const char *line, int validate_only)
|
|||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
addrport = smartlist_get(items, 0);
|
addrport = smartlist_get(items, 0);
|
||||||
if (parse_addr_port(addrport, &address, NULL, &port)<0) {
|
if (parse_addr_port(LOG_WARN, addrport, &address, NULL, &port)<0) {
|
||||||
log_warn(LD_CONFIG, "Error parsing DirServer address '%s'", addrport);
|
log_warn(LD_CONFIG, "Error parsing DirServer address '%s'", addrport);
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
@ -522,7 +522,7 @@ connection_create_listener(const char *listenaddress, uint16_t listenport,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
memset(&listenaddr,0,sizeof(struct sockaddr_in));
|
memset(&listenaddr,0,sizeof(struct sockaddr_in));
|
||||||
if (parse_addr_port(listenaddress, &address, &addr, &usePort)<0) {
|
if (parse_addr_port(LOG_WARN, listenaddress, &address, &addr, &usePort)<0) {
|
||||||
log_warn(LD_CONFIG,
|
log_warn(LD_CONFIG,
|
||||||
"Error parsing/resolving ListenAddress %s", listenaddress);
|
"Error parsing/resolving ListenAddress %s", listenaddress);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -893,7 +893,7 @@ retry_listeners(int type, config_line_t *cfg,
|
|||||||
{
|
{
|
||||||
char *address=NULL;
|
char *address=NULL;
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
if (! parse_addr_port(wanted->value, &address, NULL, &port)) {
|
if (!parse_addr_port(LOG_WARN, wanted->value, &address, NULL, &port)) {
|
||||||
int addr_matches = !strcasecmp(address, conn->address);
|
int addr_matches = !strcasecmp(address, conn->address);
|
||||||
tor_free(address);
|
tor_free(address);
|
||||||
if (! port)
|
if (! port)
|
||||||
|
@ -1587,16 +1587,19 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
if (!memchr(cell->payload+RELAY_HEADER_SIZE, 0, rh.length)) {
|
if (!memchr(cell->payload+RELAY_HEADER_SIZE, 0, rh.length)) {
|
||||||
log_warn(LD_PROTOCOL,"relay begin cell has no \\0. Dropping.");
|
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
|
||||||
|
"Relay begin cell has no \\0. Dropping.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (parse_addr_port(cell->payload+RELAY_HEADER_SIZE,&address,NULL,&port)<0) {
|
if (parse_addr_port(LOG_PROTOCOL_WARN, cell->payload+RELAY_HEADER_SIZE,
|
||||||
log_warn(LD_PROTOCOL,"Unable to parse addr:port in relay begin cell. "
|
&address,NULL,&port)<0) {
|
||||||
"Dropping.");
|
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
|
||||||
|
"Unable to parse addr:port in relay begin cell. Dropping.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (port==0) {
|
if (port==0) {
|
||||||
log_warn(LD_PROTOCOL,"Missing port in relay begin cell. Dropping.");
|
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
|
||||||
|
"Missing port in relay begin cell. Dropping.");
|
||||||
tor_free(address);
|
tor_free(address);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ parse_port_config(const char *string)
|
|||||||
} else {
|
} else {
|
||||||
addrport = smartlist_get(sl,1);
|
addrport = smartlist_get(sl,1);
|
||||||
if (strchr(addrport, ':') || strchr(addrport, '.')) {
|
if (strchr(addrport, ':') || strchr(addrport, '.')) {
|
||||||
if (parse_addr_port(addrport, NULL, &addr, &p)<0) {
|
if (parse_addr_port(LOG_WARN, addrport, NULL, &addr, &p)<0) {
|
||||||
log_warn(LD_CONFIG,"Unparseable address in hidden service port "
|
log_warn(LD_CONFIG,"Unparseable address in hidden service port "
|
||||||
"configuration.");
|
"configuration.");
|
||||||
goto err;
|
goto err;
|
||||||
|
@ -807,27 +807,28 @@ test_util(void)
|
|||||||
|
|
||||||
/* Test parse_addr_port */
|
/* Test parse_addr_port */
|
||||||
cp = NULL; u32 = 3; u16 = 3;
|
cp = NULL; u32 = 3; u16 = 3;
|
||||||
test_assert(!parse_addr_port("1.2.3.4", &cp, &u32, &u16));
|
test_assert(!parse_addr_port(LOG_WARN, "1.2.3.4", &cp, &u32, &u16));
|
||||||
test_streq(cp, "1.2.3.4");
|
test_streq(cp, "1.2.3.4");
|
||||||
test_eq(u32, 0x01020304u);
|
test_eq(u32, 0x01020304u);
|
||||||
test_eq(u16, 0);
|
test_eq(u16, 0);
|
||||||
tor_free(cp);
|
tor_free(cp);
|
||||||
test_assert(!parse_addr_port("4.3.2.1:99", &cp, &u32, &u16));
|
test_assert(!parse_addr_port(LOG_WARN, "4.3.2.1:99", &cp, &u32, &u16));
|
||||||
test_streq(cp, "4.3.2.1");
|
test_streq(cp, "4.3.2.1");
|
||||||
test_eq(u32, 0x04030201u);
|
test_eq(u32, 0x04030201u);
|
||||||
test_eq(u16, 99);
|
test_eq(u16, 99);
|
||||||
tor_free(cp);
|
tor_free(cp);
|
||||||
test_assert(!parse_addr_port("nonexistent.address:4040", &cp, NULL, &u16));
|
test_assert(!parse_addr_port(LOG_WARN, "nonexistent.address:4040",
|
||||||
|
&cp, NULL, &u16));
|
||||||
test_streq(cp, "nonexistent.address");
|
test_streq(cp, "nonexistent.address");
|
||||||
test_eq(u16, 4040);
|
test_eq(u16, 4040);
|
||||||
tor_free(cp);
|
tor_free(cp);
|
||||||
test_assert(!parse_addr_port("localhost:9999", &cp, &u32, &u16));
|
test_assert(!parse_addr_port(LOG_WARN, "localhost:9999", &cp, &u32, &u16));
|
||||||
test_streq(cp, "localhost");
|
test_streq(cp, "localhost");
|
||||||
test_eq(u32, 0x7f000001u);
|
test_eq(u32, 0x7f000001u);
|
||||||
test_eq(u16, 9999);
|
test_eq(u16, 9999);
|
||||||
tor_free(cp);
|
tor_free(cp);
|
||||||
u32 = 3;
|
u32 = 3;
|
||||||
test_assert(!parse_addr_port("localhost", NULL, &u32, &u16));
|
test_assert(!parse_addr_port(LOG_WARN, "localhost", NULL, &u32, &u16));
|
||||||
test_eq(cp, NULL);
|
test_eq(cp, NULL);
|
||||||
test_eq(u32, 0x7f000001u);
|
test_eq(u32, 0x7f000001u);
|
||||||
test_eq(u16, 0);
|
test_eq(u16, 0);
|
||||||
|
@ -217,7 +217,7 @@ main(int argc, char **argv)
|
|||||||
sockshost = 0x7f000001u; /* localhost */
|
sockshost = 0x7f000001u; /* localhost */
|
||||||
socksport = 9050; /* 9050 */
|
socksport = 9050; /* 9050 */
|
||||||
} else if (n_args == 2) {
|
} else if (n_args == 2) {
|
||||||
if (parse_addr_port(arg[1], NULL, &sockshost, &socksport)<0) {
|
if (parse_addr_port(LOG_WARN, arg[1], NULL, &sockshost, &socksport)<0) {
|
||||||
fprintf(stderr, "Couldn't parse/resolve address %s", arg[1]);
|
fprintf(stderr, "Couldn't parse/resolve address %s", arg[1]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user