Skip to content

validate_hostname() returns -1 on UTF-8 conversion failure, which converts to true in its bool return type #13483

Description

@maskit

validate_hostname() in src/tscore/X509HostnameValidator.cc has return type bool, but on ASN1_STRING_to_UTF8() failure it does:

astrlen = ASN1_STRING_to_UTF8(&astr, str);

if (astrlen < 0) {
  return -1;
}

-1 implicitly converts to true when returned from a bool function, so a UTF-8 conversion failure on the certificate CN is reported as a successful hostname match instead of a failure.

This traces back to the original addition of the function in 1649abc (2015) and is present on current master, independent of any other in-flight work. It was noticed during review of #13476 (OpenSSL 4 build-compatibility fixes), which touches nearby lines for unrelated reasons but does not change this logic.

Suggested fix

return false; instead of return -1;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions