diff options
author | rl1987 <rl1987@sdf.lonestar.org> | 2018-02-12 19:52:47 +0100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-03-28 07:39:03 -0400 |
commit | b0ba4aa7e98af030e0e1be19a58ab7a6f00fa423 (patch) | |
tree | 2d7baf06082aa409c25252a068f6c560eedd2923 /src/common/util.c | |
parent | df529c60936ef290c917d09d51820680cd31cc8b (diff) | |
download | tor-b0ba4aa7e98af030e0e1be19a58ab7a6f00fa423.tar.gz tor-b0ba4aa7e98af030e0e1be19a58ab7a6f00fa423.zip |
Fix bracketed IPv6 string validation
Diffstat (limited to 'src/common/util.c')
-rw-r--r-- | src/common/util.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/common/util.c b/src/common/util.c index 7c715fb3cd..ea0ec3daee 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1079,9 +1079,22 @@ string_is_valid_ipv6_address(const char *string) int string_is_valid_dest(const char *string) { - return string_is_valid_ipv4_address(string) || + char *tmp = NULL; + int retval; + + tor_assert(string); + tor_assert(strlen(string) > 0); + + if (string[0] == '[' && string[strlen(string) - 1] == ']') + string = tmp = tor_strndup(string + 1, strlen(string) - 2); + + retval = string_is_valid_ipv4_address(string) || string_is_valid_ipv6_address(string) || string_is_valid_hostname(string); + + tor_free(tmp); + + return retval; } /** Return true iff <b>string</b> matches a pattern of DNS names |