<commit_before>/*
 * author: <NAME> <<EMAIL>>
 */

#include "AltName.hxx"
#include "GeneralName.hxx"

static void
FillNameList(std::list<std::string> &list, OpenSSL::GeneralNames src)
{
    for (const auto &name : src) {
        if (name.GetType() == GEN_DNS) {
            const auto dns_name = name.GetDnsName();
            if (dns_name.IsNull())
                continue;

            list.push_back(std::string(dns_name.data, dns_name.size));
        }
    }
}

gcc_pure
std::list<std::string>
GetSubjectAltNames(X509 &cert)
{
    std::list<std::string> list;

    for (int i = 0;
         (i = X509_get_ext_by_NID(&cert, NID_subject_alt_name, i)) >= 0;) {
        auto ext = X509_get_ext(&cert, i);
        if (ext == nullptr)
            continue;

        OpenSSL::UniqueGeneralNames gn(reinterpret_cast<GENERAL_NAMES *>(X509V3_EXT_d2i(ext)));
        if (!gn)
            continue;

        FillNameList(list, gn);
    }

    return list;
}<commit_msg>ssl/AltName: start search at index 0 (off-by-one bug)<commit_after>/*
 * author: <NAME> <<EMAIL>>
 */

#include "AltName.hxx"
#include "GeneralName.hxx"

static void
FillNameList(std::list<std::string> &list, OpenSSL::GeneralNames src)
{
    for (const auto &name : src) {
        if (name.GetType() == GEN_DNS) {
            const auto dns_name = name.GetDnsName();
            if (dns_name.IsNull())
                continue;

            list.push_back(std::string(dns_name.data, dns_name.size));
        }
    }
}

gcc_pure
std::list<std::string>
GetSubjectAltNames(X509 &cert)
{
    std::list<std::string> list;

    for (int i = -1;
         (i = X509_get_ext_by_NID(&cert, NID_subject_alt_name, i)) >= 0;) {
        auto ext = X509_get_ext(&cert, i);
        if (ext == nullptr)
            continue;

        OpenSSL::UniqueGeneralNames gn(reinterpret_cast<GENERAL_NAMES *>(X509V3_EXT_d2i(ext)));
        if (!gn)
            continue;

        FillNameList(list, gn);
    }

    return list;
}
{'fraction_non_alphanumeric': 0.14722363728986246, 'fraction_numerical': 0.016811003565970453, 'mean_word_length': 2.5839416058394162, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2054837', 'n_tokens_mistral': 741, 'n_tokens_neox': 700, 'n_words': 135}