summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrl1987 <rl1987@sdf.lonestar.org>2018-02-12 22:21:10 +0100
committerNick Mathewson <nickm@torproject.org>2018-03-28 07:39:03 -0400
commit4413e52f9e2e3898f870df481aea93b1ea5fd836 (patch)
tree060c8b70e8dbb62478ab64a220d02d044dfde889
parentdb850fec3ac402084a9036c0ea7b4523f1120eb1 (diff)
downloadtor-4413e52f9e2e3898f870df481aea93b1ea5fd836.tar.gz
tor-4413e52f9e2e3898f870df481aea93b1ea5fd836.zip
Improve handling of trailing dot
-rw-r--r--src/common/util.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/common/util.c b/src/common/util.c
index a7eaf5389c..096188cfcf 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1106,24 +1106,33 @@ int
string_is_valid_hostname(const char *string)
{
int result = 1;
+ int has_trailing_dot;
+ char *last_label;
smartlist_t *components;
+ if (!string || strlen(string) == 0)
+ return 0;
+
components = smartlist_new();
smartlist_split_string(components,string,".",0,0);
+ /* Allow a single terminating '.' used rarely to indicate domains
+ * are FQDNs rather than relative. */
+ last_label = (char *)smartlist_get(components, smartlist_len(components) - 1);
+ has_trailing_dot = (last_label[0] == '\0');
+ if (has_trailing_dot) {
+ smartlist_pop_last(components);
+ tor_free(last_label);
+ last_label = NULL;
+ }
+
SMARTLIST_FOREACH_BEGIN(components, char *, c) {
if ((c[0] == '-') || (*c == '_')) {
result = 0;
break;
}
- /* Allow a single terminating '.' used rarely to indicate domains
- * are FQDNs rather than relative. */
- if ((c_sl_idx > 0) && (c_sl_idx + 1 == c_sl_len) && !*c) {
- continue;
- }
-
if (c_sl_idx == c_sl_len - 1) {
do {
result = TOR_ISALPHA(*c);