|
@@ -1166,7 +1166,6 @@ handle_control_mapaddress(connection_t *conn, uint32_t len, const char *body)
|
|
else
|
|
else
|
|
smartlist_split_string(lines, body, " ",
|
|
smartlist_split_string(lines, body, " ",
|
|
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
|
|
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
|
|
- /* XXXX Make errors conformant. */
|
|
|
|
SMARTLIST_FOREACH(lines, char *, line,
|
|
SMARTLIST_FOREACH(lines, char *, line,
|
|
{
|
|
{
|
|
tor_strlower(line);
|
|
tor_strlower(line);
|
|
@@ -1177,11 +1176,25 @@ handle_control_mapaddress(connection_t *conn, uint32_t len, const char *body)
|
|
if (smartlist_len(elts) == 2) {
|
|
if (smartlist_len(elts) == 2) {
|
|
const char *from = smartlist_get(elts,0);
|
|
const char *from = smartlist_get(elts,0);
|
|
const char *to = smartlist_get(elts,1);
|
|
const char *to = smartlist_get(elts,1);
|
|
|
|
+ size_t anslen = strlen(line)+512;
|
|
|
|
+ char *ans = tor_malloc(anslen);
|
|
if (!is_plausible_address(from)) {
|
|
if (!is_plausible_address(from)) {
|
|
|
|
+ if (!v0) {
|
|
|
|
+ tor_snprintf(ans, anslen,
|
|
|
|
+ "512-syntax error: invalid address '%s'", from);
|
|
|
|
+ smartlist_add(reply, ans);
|
|
|
|
+ } else
|
|
|
|
+ tor_free(ans); /* don't respond if v0 */
|
|
log_warn(LD_CONTROL,
|
|
log_warn(LD_CONTROL,
|
|
"Skipping invalid argument '%s' in MapAddress msg",
|
|
"Skipping invalid argument '%s' in MapAddress msg",
|
|
from);
|
|
from);
|
|
} else if (!is_plausible_address(to)) {
|
|
} else if (!is_plausible_address(to)) {
|
|
|
|
+ if (!v0) {
|
|
|
|
+ tor_snprintf(ans, anslen,
|
|
|
|
+ "512-syntax error: invalid address '%s'", to);
|
|
|
|
+ smartlist_add(reply, ans);
|
|
|
|
+ } else
|
|
|
|
+ tor_free(ans); /* don't respond if v0 */
|
|
log_warn(LD_CONTROL,
|
|
log_warn(LD_CONTROL,
|
|
"Skipping invalid argument '%s' in MapAddress msg", to);
|
|
"Skipping invalid argument '%s' in MapAddress msg", to);
|
|
} else if (!strcmp(from, ".") || !strcmp(from, "0.0.0.0")) {
|
|
} else if (!strcmp(from, ".") || !strcmp(from, "0.0.0.0")) {
|
|
@@ -1189,12 +1202,16 @@ handle_control_mapaddress(connection_t *conn, uint32_t len, const char *body)
|
|
!strcmp(from,".") ? RESOLVED_TYPE_HOSTNAME : RESOLVED_TYPE_IPV4,
|
|
!strcmp(from,".") ? RESOLVED_TYPE_HOSTNAME : RESOLVED_TYPE_IPV4,
|
|
tor_strdup(to));
|
|
tor_strdup(to));
|
|
if (!address) {
|
|
if (!address) {
|
|
|
|
+ if (!v0) {
|
|
|
|
+ tor_snprintf(ans, anslen,
|
|
|
|
+ "451-resource exhausted: skipping '%s'", line);
|
|
|
|
+ smartlist_add(reply, ans);
|
|
|
|
+ } else
|
|
|
|
+ tor_free(ans); /* don't respond if v0 */
|
|
log_warn(LD_CONTROL,
|
|
log_warn(LD_CONTROL,
|
|
"Unable to allocate address for '%s' in MapAddress msg",
|
|
"Unable to allocate address for '%s' in MapAddress msg",
|
|
safe_str(line));
|
|
safe_str(line));
|
|
} else {
|
|
} else {
|
|
- size_t anslen = strlen(address)+strlen(to)+8;
|
|
|
|
- char *ans = tor_malloc(anslen);
|
|
|
|
if (v0)
|
|
if (v0)
|
|
tor_snprintf(ans, anslen, "%s %s", address, to);
|
|
tor_snprintf(ans, anslen, "%s %s", address, to);
|
|
else
|
|
else
|
|
@@ -1204,17 +1221,21 @@ handle_control_mapaddress(connection_t *conn, uint32_t len, const char *body)
|
|
} else {
|
|
} else {
|
|
addressmap_register(from, tor_strdup(to), 1);
|
|
addressmap_register(from, tor_strdup(to), 1);
|
|
if (v0)
|
|
if (v0)
|
|
- smartlist_add(reply, tor_strdup(line));
|
|
|
|
- else {
|
|
|
|
- size_t anslen = strlen(line)+8;
|
|
|
|
- char *ans = tor_malloc(anslen);
|
|
|
|
|
|
+ tor_snprintf(ans, anslen, "%s", line);
|
|
|
|
+ else
|
|
tor_snprintf(ans, anslen, "250-%s", line);
|
|
tor_snprintf(ans, anslen, "250-%s", line);
|
|
- smartlist_add(reply, ans);
|
|
|
|
- }
|
|
|
|
|
|
+ smartlist_add(reply, ans);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- log_warn(LD_CONTROL,
|
|
|
|
- "Skipping MapAddress line with wrong number of items.");
|
|
|
|
|
|
+ if (!v0) {
|
|
|
|
+ size_t anslen = strlen(line)+256;
|
|
|
|
+ char *ans = tor_malloc(anslen);
|
|
|
|
+ tor_snprintf(ans, anslen,
|
|
|
|
+ "512-syntax error: mapping '%s' has wrong number of items.", line);
|
|
|
|
+ smartlist_add(reply, ans);
|
|
|
|
+ }
|
|
|
|
+ log_info(LD_CONTROL, "Skipping MapAddress '%s': wrong "
|
|
|
|
+ "number of items.", safe_str(line));
|
|
}
|
|
}
|
|
SMARTLIST_FOREACH(elts, char *, cp, tor_free(cp));
|
|
SMARTLIST_FOREACH(elts, char *, cp, tor_free(cp));
|
|
smartlist_clear(elts);
|
|
smartlist_clear(elts);
|