]> git.99rst.org Git - stevenblack-hosts.git/commitdiff
Merge pull request #3188 from XhmikosR/xmr/codeql
authorSteven Black <redacted>
Tue, 7 Jul 2026 20:37:02 +0000 (13:37 -0700)
committerGitHub <redacted>
Tue, 7 Jul 2026 20:37:02 +0000 (13:37 -0700)
A couple of CodeQL fixes

1  2 
updateHostsFile.py

index a29b2a21bf9f91cde873a21f2e7a944f112d1447,2376bf89aa2062ec68cc02a332b54f774c5c5527..846d8f5d6653b4f6090b9e74fba1f5fcc776234b
@@@ -1018,37 -1009,7 +1009,34 @@@ def remove_dups_and_excl(mergefile, exc
      settings["numberofrules"] = numberofrules
      mergefile.close()
  
-     if outputfile is None:
-         return finalfile
  
 +# Dot-separated labels of [a-z0-9_-], hyphens not at label ends, at least two
 +# labels. Expects a lowercased hostname.
 +VALID_DOMAIN_REGEX = re.compile(
 +    r"(?:[a-z0-9_]|[a-z0-9_][a-z0-9_-]*[a-z0-9_])"
 +    r"(?:\.(?:[a-z0-9_]|[a-z0-9_][a-z0-9_-]*[a-z0-9_]))+"
 +)
 +
 +
 +def is_valid_domain(hostname):
 +    """
 +    Check whether a lowercased hostname looks like a valid domain name.
 +
 +    Parameters
 +    ----------
 +    hostname : str
 +        The hostname to validate.
 +
 +    Returns
 +    -------
 +    valid : bool
 +        Whether the hostname only contains characters allowed in a domain
 +        name and has a valid label structure.
 +    """
 +
 +    return bool(VALID_DOMAIN_REGEX.fullmatch(hostname))
 +
 +
  def normalize_rule(rule, targetip, keep_domain_comments):
      """
      Standardize and format the rule string provided.
git clone https://git.99rst.org/PROJECT