Add an extra prop330 test, and clarifying comments.

This test makes sure that we reject "upload=" URLs with bad IP
addresses.

Also, add a warning when we can't parse the address.
This commit is contained in:
Nick Mathewson 2021-03-24 10:19:21 -04:00
parent db14801b04
commit ebb826f4a1
2 changed files with 23 additions and 2 deletions

View File

@ -5500,6 +5500,8 @@ parse_dirauth_dirport(dir_server_t *ds, const char *flag)
&dirport.addr, &dirport.port, -1);
if (ds != NULL && rv == 0) {
trusted_dir_server_add_dirport(ds, usage, &dirport);
} else if (rv == -1) {
log_warn(LD_CONFIG, "Unable to parse address in authority flag %s",flag);
}
tor_free(addr_string);

View File

@ -44,7 +44,7 @@ test_dirauth_port_parsing(void *arg)
rv = parse_dir_authority_line(
"moria1 orport=9101 "
"v3ident=D586D18309DED4CD6D57C18FDB97EFA96D330566 "
"upload=https://128.31.0.39:9131/ " // not recognized
"upload=https://128.31.0.39:9131/ " // https is not recognized
"128.31.0.39:9131 9695 DFC3 5FFE B861 329B 9F1A B04C 4639 7020 CE31",
NO_DIRINFO, 1);
tt_int_op(rv,OP_EQ,-1);
@ -54,11 +54,30 @@ test_dirauth_port_parsing(void *arg)
rv = parse_dir_authority_line(
"moria1 orport=9101 "
"v3ident=D586D18309DED4CD6D57C18FDB97EFA96D330566 "
"upload=http://128.31.0.39:9131/tor " // not supported
"upload=http://128.31.0.39:9131/tor " // suffix is not supported
"128.31.0.39:9131 9695 DFC3 5FFE B861 329B 9F1A B04C 4639 7020 CE31",
NO_DIRINFO, 1);
tt_int_op(rv,OP_EQ,-1);
expect_log_msg_containing("Unsupported URL prefix");
mock_clean_saved_logs();
rv = parse_dir_authority_line(
"moria1 orport=9101 "
"v3ident=D586D18309DED4CD6D57C18FDB97EFA96D330566 "
"upload=http://128.31.0.256:9131/ " // "256" is not ipv4.
"128.31.0.39:9131 9695 DFC3 5FFE B861 329B 9F1A B04C 4639 7020 CE31",
NO_DIRINFO, 1);
tt_int_op(rv,OP_EQ,-1);
expect_log_msg_containing("Unable to parse address");
rv = parse_dir_authority_line(
"moria1 orport=9101 "
"v3ident=D586D18309DED4CD6D57C18FDB97EFA96D330566 "
"upload=http://xyz.example.com/ " // hostnames not supported.
"128.31.0.39:9131 9695 DFC3 5FFE B861 329B 9F1A B04C 4639 7020 CE31",
NO_DIRINFO, 1);
tt_int_op(rv,OP_EQ,-1);
expect_log_msg_containing("Unable to parse address");
done:
teardown_capture_of_logs();