diff options
author | rl1987 <rl1987@sdf.lonestar.org> | 2018-02-11 16:39:23 +0100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-03-28 07:39:03 -0400 |
commit | 1af016e96e133718546b55c8b7fafd3345aaeeb8 (patch) | |
tree | a877524cac58faf93e1fe622b968013932402e3e /src/common | |
parent | 0e453929d21b030832b0c48fceac0c5688657e15 (diff) | |
download | tor-1af016e96e133718546b55c8b7fafd3345aaeeb8.tar.gz tor-1af016e96e133718546b55c8b7fafd3345aaeeb8.zip |
Do not consider IP strings valid DNS names. Fixes #25055
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/util.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/common/util.c b/src/common/util.c index 1818b4f19e..7c715fb3cd 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -100,6 +100,8 @@ #undef MALLOC_ZERO_WORKS #endif +#include <ctype.h> + /* ===== * Memory management * ===== */ @@ -1110,16 +1112,21 @@ string_is_valid_hostname(const char *string) continue; } - do { - if ((*c >= 'a' && *c <= 'z') || - (*c >= 'A' && *c <= 'Z') || - (*c >= '0' && *c <= '9') || - (*c == '-') || (*c == '_')) + if (c_sl_idx == c_sl_len - 1) { + do { + result = isalpha(*c); c++; - else - result = 0; - } while (result && *c); + } while (result && *c); + } else { + do { + result = (isalnum(*c) || (*c == '-') || (*c == '_')); + c++; + } while (result > 0 && *c); + } + if (result == 0) { + break; + } } SMARTLIST_FOREACH_END(c); SMARTLIST_FOREACH_BEGIN(components, char *, c) { |