diff options
author | David Goulet <dgoulet@torproject.org> | 2020-06-15 15:02:08 -0400 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2020-06-23 09:25:36 -0400 |
commit | 47f9edde699ad687884b6222b557c10dee2592c9 (patch) | |
tree | 0c9d84200f85884e5f20ddb1f679684c2f4439c1 /src/test/test_config.c | |
parent | d3bcbccab9d50fd0dafc682f7ee63902ea344be7 (diff) | |
download | tor-47f9edde699ad687884b6222b557c10dee2592c9.tar.gz tor-47f9edde699ad687884b6222b557c10dee2592c9.zip |
config: Change Address to be a LINELIST
With prop312, we want to support IPv4 and IPv6 thus multiple Address statement
(up to 2) will be accepted.
For this, "Address" option becomes a LINELIST so we can properly process the
IPv4 or/and IPv6.
Part of #33233
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/test/test_config.c')
-rw-r--r-- | src/test/test_config.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/test/test_config.c b/src/test/test_config.c index 095eb24c49..2b44505329 100644 --- a/src/test/test_config.c +++ b/src/test/test_config.c @@ -1190,6 +1190,7 @@ test_config_resolve_my_address(void *arg) { or_options_t *options; uint32_t resolved_addr; + char buf[1024]; const char *method_used; char *hostname_out = NULL; int retval; @@ -1215,8 +1216,8 @@ test_config_resolve_my_address(void *arg) * If options->Address is a valid IPv4 address string, we want * the corresponding address to be parsed and returned. */ - - options->Address = tor_strdup("128.52.128.105"); + strlcpy(buf, "Address 128.52.128.105\n", sizeof(buf)); + config_get_lines(buf, &(options->Address), 0); retval = resolve_my_address(LOG_NOTICE,options,&resolved_addr, &method_used,&hostname_out); @@ -1226,7 +1227,7 @@ test_config_resolve_my_address(void *arg) tt_want(hostname_out == NULL); tt_assert(resolved_addr == 0x80348069); - tor_free(options->Address); + config_free_lines(options->Address); /* * CASE 2: @@ -1237,8 +1238,8 @@ test_config_resolve_my_address(void *arg) MOCK(tor_lookup_hostname,tor_lookup_hostname_01010101); - tor_free(options->Address); - options->Address = tor_strdup("www.torproject.org"); + strlcpy(buf, "Address www.torproject.org\n", sizeof(buf)); + config_get_lines(buf, &(options->Address), 0); prev_n_hostname_01010101 = n_hostname_01010101; @@ -1253,7 +1254,7 @@ test_config_resolve_my_address(void *arg) UNMOCK(tor_lookup_hostname); - tor_free(options->Address); + config_free_lines(options->Address); tor_free(hostname_out); /* @@ -1264,7 +1265,6 @@ test_config_resolve_my_address(void *arg) */ resolved_addr = 0; - tor_free(options->Address); options->Address = NULL; MOCK(tor_gethostname,tor_gethostname_replacement); @@ -1295,8 +1295,8 @@ test_config_resolve_my_address(void *arg) */ resolved_addr = 0; - tor_free(options->Address); - options->Address = tor_strdup("127.0.0.1"); + strlcpy(buf, "Address 127.0.0.1\n", sizeof(buf)); + config_get_lines(buf, &(options->Address), 0); retval = resolve_my_address(LOG_NOTICE,options,&resolved_addr, &method_used,&hostname_out); @@ -1304,7 +1304,7 @@ test_config_resolve_my_address(void *arg) tt_want(resolved_addr == 0); tt_int_op(retval, OP_EQ, -1); - tor_free(options->Address); + config_free_lines(options->Address); tor_free(hostname_out); /* @@ -1317,8 +1317,8 @@ test_config_resolve_my_address(void *arg) prev_n_hostname_failure = n_hostname_failure; - tor_free(options->Address); - options->Address = tor_strdup("www.tor-project.org"); + strlcpy(buf, "Address www.tor-project.org\n", sizeof(buf)); + config_get_lines(buf, &(options->Address), 0); retval = resolve_my_address(LOG_NOTICE,options,&resolved_addr, &method_used,&hostname_out); @@ -1328,7 +1328,8 @@ test_config_resolve_my_address(void *arg) UNMOCK(tor_lookup_hostname); - tor_free(options->Address); + config_free_lines(options->Address); + options->Address = NULL; tor_free(hostname_out); /* @@ -1451,8 +1452,8 @@ test_config_resolve_my_address(void *arg) prev_n_hostname_failure = n_hostname_failure; - tor_free(options->Address); - options->Address = tor_strdup("some_hostname"); + strlcpy(buf, "Address some_hostname\n", sizeof(buf)); + config_get_lines(buf, &(options->Address), 0); retval = resolve_my_address(LOG_NOTICE, options, &resolved_addr, &method_used,&hostname_out); @@ -1484,7 +1485,7 @@ test_config_resolve_my_address(void *arg) * and address from step 6. */ - tor_free(options->Address); + config_free_lines(options->Address); options->Address = NULL; MOCK(tor_gethostname,tor_gethostname_replacement); @@ -1563,7 +1564,7 @@ test_config_resolve_my_address(void *arg) UNMOCK(tor_gethostname); done: - tor_free(options->Address); + config_free_lines(options->Address); tor_free(options->DirAuthorities); or_options_free(options); tor_free(hostname_out); |