]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add a paranoia check in string_is_valid_nonrfc_hostname()
authorNick Mathewson <nickm@torproject.org>
Wed, 28 Mar 2018 11:48:18 +0000 (07:48 -0400)
committerNick Mathewson <nickm@torproject.org>
Wed, 28 Mar 2018 11:48:18 +0000 (07:48 -0400)
The earlier checks in this function should ensure that components is
always nonempty.  But in case somebody messes with them in the
future, let's add an extra check to make sure we aren't crashing.

src/common/util.c

index 90aaf0ebeb1b0e1ec261bf49cb4334be5c374522..a68fd30d09a30d362a7bda7f4d1696facdbdfe0a 100644 (file)
@@ -1125,6 +1125,9 @@ string_is_valid_nonrfc_hostname(const char *string)
 
   smartlist_split_string(components,string,".",0,0);
 
+  if (BUG(smartlist_len(components) == 0))
+    return 0; // LCOV_EXCL_LINE should be impossible given the earlier checks.
+
   /* Allow a single terminating '.' used rarely to indicate domains
    * are FQDNs rather than relative. */
   last_label = (char *)smartlist_get(components,