diff options
author | cypherpunks <cypherpunks@torproject.org> | 2020-02-08 21:16:26 +0000 |
---|---|---|
committer | cypherpunks <cypherpunks@torproject.org> | 2020-02-09 01:24:47 +0000 |
commit | c2b95da4d49504281f7c30c8f523cd492be932a7 (patch) | |
tree | 4012ce929b08de8583f425f72213bc40d4bc8acb /src/feature/dirparse | |
parent | 8d89aa5eeaef2c009c7fc8250eacc0ed32ebde64 (diff) | |
download | tor-c2b95da4d49504281f7c30c8f523cd492be932a7.tar.gz tor-c2b95da4d49504281f7c30c8f523cd492be932a7.zip |
dirparse: add helper for recommended/required protocols
Diffstat (limited to 'src/feature/dirparse')
-rw-r--r-- | src/feature/dirparse/ns_parse.c | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/src/feature/dirparse/ns_parse.c b/src/feature/dirparse/ns_parse.c index 6172a57bbb..5ba87176aa 100644 --- a/src/feature/dirparse/ns_parse.c +++ b/src/feature/dirparse/ns_parse.c @@ -1053,6 +1053,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 * @@ -1169,26 +1182,17 @@ networkstatus_parse_vote_from_string(const char *s, const char **eos_out, } // Reject the vote if any of the protocols lines are malformed. - if ((tok = find_opt_by_keyword(tokens, K_RECOMMENDED_CLIENT_PROTOCOLS))) { - if (protover_contains_long_protocol_names(tok->args[0])) - goto err; - ns->recommended_client_protocols = tor_strdup(tok->args[0]); - } - if ((tok = find_opt_by_keyword(tokens, K_RECOMMENDED_RELAY_PROTOCOLS))) { - if (protover_contains_long_protocol_names(tok->args[0])) - goto err; - ns->recommended_relay_protocols = tor_strdup(tok->args[0]); - } - if ((tok = find_opt_by_keyword(tokens, K_REQUIRED_CLIENT_PROTOCOLS))) { - if (protover_contains_long_protocol_names(tok->args[0])) - goto err; - ns->required_client_protocols = tor_strdup(tok->args[0]); - } - if ((tok = find_opt_by_keyword(tokens, K_REQUIRED_RELAY_PROTOCOLS))) { - if (protover_contains_long_protocol_names(tok->args[0])) - goto err; - ns->required_relay_protocols = tor_strdup(tok->args[0]); - } + 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)) |