소스 검색

Add a paranoia check in string_is_valid_nonrfc_hostname()

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.
Nick Mathewson 6 년 전
부모
커밋
d4bf1f6c8e
1개의 변경된 파일3개의 추가작업 그리고 0개의 파일을 삭제
  1. 3 0
      src/common/util.c

+ 3 - 0
src/common/util.c

@@ -1125,6 +1125,9 @@ string_is_valid_nonrfc_hostname(const char *string)
 
 
   smartlist_split_string(components,string,".",0,0);
   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
   /* Allow a single terminating '.' used rarely to indicate domains
    * are FQDNs rather than relative. */
    * are FQDNs rather than relative. */
   last_label = (char *)smartlist_get(components,
   last_label = (char *)smartlist_get(components,