diff options
author | rl1987 <rl1987@sdf.lonestar.org> | 2014-10-12 20:39:00 +0300 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-11-04 00:36:37 -0500 |
commit | e8e45ff13ed86d8851bab77d65d899d0ca6e3b89 (patch) | |
tree | 08b48055e4ba8d1dd79cbb42324d7de6216a6a18 /src/common | |
parent | 1ea9a6fd72b66ec634446cbd2119641a5ed1e703 (diff) | |
download | tor-e8e45ff13ed86d8851bab77d65d899d0ca6e3b89.tar.gz tor-e8e45ff13ed86d8851bab77d65d899d0ca6e3b89.zip |
Introducing helper function to validate IPv4 address strings.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/util.c | 19 | ||||
-rw-r--r-- | src/common/util.h | 1 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/common/util.c b/src/common/util.c index 606b9e1ea0..ba9d78afac 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -957,8 +957,19 @@ string_is_key_value(int severity, const char *string) return 1; } -/** Return true iff <b>string</b> is valid DNS name, as defined in - * RFC 1035 Section 2.3.1. +/** Return true if <b>string</b> represents a valid IPv4 adddress in + * 'a.b.c.d' form. + */ +int +string_is_valid_ipv4_address(const char *string) +{ + struct sockaddr_in sockaddr; + + return (tor_inet_pton(AF_INET,string,&sockaddr) == 1); +} + +/** Return true iff <b>string</b> matches a pattern of DNS names + * that we allow Tor clients to connect to. */ int string_is_valid_hostname(const char *string) @@ -988,6 +999,10 @@ string_is_valid_hostname(const char *string) } SMARTLIST_FOREACH_END(c); + SMARTLIST_FOREACH_BEGIN(components, char *, c) { + tor_free(c); + } SMARTLIST_FOREACH_END(c); + smartlist_free(components); return result; diff --git a/src/common/util.h b/src/common/util.h index 2634adc62b..dcb54f0aea 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -228,6 +228,7 @@ const char *find_str_at_start_of_line(const char *haystack, int string_is_C_identifier(const char *string); int string_is_key_value(int severity, const char *string); int string_is_valid_hostname(const char *string); +int string_is_valid_ipv4_address(const char *string); int tor_mem_is_zero(const char *mem, size_t len); int tor_digest_is_zero(const char *digest); |