aboutsummaryrefslogtreecommitdiff
path: root/src/feature/dirparse
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2020-08-03 08:54:03 -0400
committerNick Mathewson <nickm@torproject.org>2020-08-03 08:54:03 -0400
commitd1fda62d11139830b0d81d56d0dfd372237d0be6 (patch)
treebcd54004a203fe54e8009256929fc2b408d82f54 /src/feature/dirparse
parent3e3b0b0443b6486553e5cfc18a23a8d7cb7ae4c4 (diff)
parent32b33c0d21ce471d735abbedc26d26998238c380 (diff)
downloadtor-d1fda62d11139830b0d81d56d0dfd372237d0be6.tar.gz
tor-d1fda62d11139830b0d81d56d0dfd372237d0be6.zip
Merge remote-tracking branch 'tor-gitlab/mr/94'
Diffstat (limited to 'src/feature/dirparse')
-rw-r--r--src/feature/dirparse/ns_parse.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/src/feature/dirparse/ns_parse.c b/src/feature/dirparse/ns_parse.c
index d4bcdae973..726da8a64c 100644
--- a/src/feature/dirparse/ns_parse.c
+++ b/src/feature/dirparse/ns_parse.c
@@ -13,6 +13,7 @@
#include "core/or/or.h"
#include "app/config/config.h"
+#include "core/or/protover.h"
#include "core/or/versions.h"
#include "feature/client/entrynodes.h"
#include "feature/dirauth/dirvote.h"
@@ -466,6 +467,10 @@ routerstatus_parse_entry_from_string(memarea_t *area,
}
}
+ // If the protover line is malformed, reject this routerstatus.
+ if (protocols && protover_contains_long_protocol_names(protocols)) {
+ goto err;
+ }
summarize_protover_flags(&rs->pv, protocols, version);
}
@@ -1063,6 +1068,19 @@ extract_shared_random_srvs(networkstatus_t *ns, smartlist_t *tokens)
}
}
+/** Allocate a copy of a protover line, if present. If present but malformed,
+ * set *error to true. */
+static char *
+dup_protocols_string(smartlist_t *tokens, bool *error, directory_keyword kw)
+{
+ directory_token_t *tok = find_opt_by_keyword(tokens, kw);
+ if (!tok)
+ return NULL;
+ if (protover_contains_long_protocol_names(tok->args[0]))
+ *error = true;
+ return tor_strdup(tok->args[0]);
+}
+
/** Parse a v3 networkstatus vote, opinion, or consensus (depending on
* ns_type), from <b>s</b>, and return the result. Return NULL on failure. */
networkstatus_t *
@@ -1184,14 +1202,18 @@ networkstatus_parse_vote_from_string(const char *s,
}
}
- if ((tok = find_opt_by_keyword(tokens, K_RECOMMENDED_CLIENT_PROTOCOLS)))
- ns->recommended_client_protocols = tor_strdup(tok->args[0]);
- if ((tok = find_opt_by_keyword(tokens, K_RECOMMENDED_RELAY_PROTOCOLS)))
- ns->recommended_relay_protocols = tor_strdup(tok->args[0]);
- if ((tok = find_opt_by_keyword(tokens, K_REQUIRED_CLIENT_PROTOCOLS)))
- ns->required_client_protocols = tor_strdup(tok->args[0]);
- if ((tok = find_opt_by_keyword(tokens, K_REQUIRED_RELAY_PROTOCOLS)))
- ns->required_relay_protocols = tor_strdup(tok->args[0]);
+ // Reject the vote if any of the protocols lines are malformed.
+ bool unparseable = false;
+ ns->recommended_client_protocols = dup_protocols_string(tokens, &unparseable,
+ K_RECOMMENDED_CLIENT_PROTOCOLS);
+ ns->recommended_relay_protocols = dup_protocols_string(tokens, &unparseable,
+ K_RECOMMENDED_RELAY_PROTOCOLS);
+ ns->required_client_protocols = dup_protocols_string(tokens, &unparseable,
+ K_REQUIRED_CLIENT_PROTOCOLS);
+ ns->required_relay_protocols = dup_protocols_string(tokens, &unparseable,
+ K_REQUIRED_RELAY_PROTOCOLS);
+ if (unparseable)
+ goto err;
tok = find_by_keyword(tokens, K_VALID_AFTER);
if (parse_iso_time(tok->args[0], &ns->valid_after))
@@ -1453,6 +1475,7 @@ networkstatus_parse_vote_from_string(const char *s,
smartlist_add(ns->routerstatus_list, rs);
} else {
vote_routerstatus_free(rs);
+ goto err; // Malformed routerstatus, reject this vote.
}
} else {
routerstatus_t *rs;
@@ -1463,6 +1486,8 @@ networkstatus_parse_vote_from_string(const char *s,
flav))) {
/* Use exponential-backoff scheduling when downloading microdescs */
smartlist_add(ns->routerstatus_list, rs);
+ } else {
+ goto err; // Malformed routerstatus, reject this vote.
}
}
}