<commit_before>#include "network-mgr.h"
#include <QNetworkAccessManager>
#include <QNetworkProxy>
#include <algorithm>
#include <QStringRef>
#include <QSslConfiguration>
#include <QSslSocket>
#include <QSslCipher>
namespace {
QNetworkProxy proxy_;
const char *const kWhitelistCiphers[] = {"ECDHE-RSA-AES256-GCM-SHA384"
                                         "ECDHE-RSA-AES128-GCM-SHA256"
                                         "DHE-RSA-AES256-GCM-SHA384"
                                         "DHE-RSA-AES128-GCM-SHA256"
                                         "ECDHE-RSA-AES256-SHA384"
                                         "ECDHE-RSA-AES128-SHA256"
                                         "ECDHE-RSA-AES256-SHA"
                                         "ECDHE-RSA-AES128-SHA"
                                         "DHE-RSA-AES256-SHA256"
                                         "DHE-RSA-AES128-SHA256"
                                         "DHE-RSA-AES256-SHA"
                                         "DHE-RSA-AES128-SHA"
                                         "ECDHE-RSA-DES-CBC3-SHA"
                                         "EDH-RSA-DES-CBC3-SHA"
                                         "AES256-GCM-SHA384"
                                         "AES128-GCM-SHA256"
                                         "AES256-SHA256"
                                         "AES128-SHA256"
                                         "AES256-SHA"
                                         "AES128-SHA"
                                         "DES-CBC3-SHA"};
// return false if it contains RC4, RSK, CBC, MD5, DES, DSS, EXPORT, NULL
bool isWeakCipher(const QString& cipher_name)
{
    int current_begin = 0;
    int current_end;
    QStringRef name;
    while((current_end = cipher_name.indexOf("-", current_begin)) != -1) {
        name = QStringRef(&cipher_name, current_begin, current_end - current_begin);
        if (name == "RC4")
            return true;
        else if (name == "PSK")
            return true;
        else if (name == "CBC")
            return true;
        else if (name == "MD5")
            return true;
        else if (name == "DES")
            return true;
        else if (name == "DSS")
            return true;
        else if (name == "EXP")
            return true;
        else if (name == "NULL")
            return true;

        current_begin = current_end + 1;
    }
    return false;
}
} // anonymous namespace

NetworkManager* NetworkManager::instance_ = NULL;

NetworkManager::NetworkManager() : should_retry_(true) {
    // remove unsafe cipher
    QSslConfiguration configuration = QSslConfiguration::defaultConfiguration();
    const QList<QSslCipher> ciphers = QSslSocket::supportedCiphers();

    QList<QSslCipher> new_ciphers;
    Q_FOREACH(const QSslCipher &cipher, ciphers)
    {
        bool whitelisted = false;
        for (unsigned i = 0; i < sizeof(kWhitelistCiphers); ++i) {
            if (cipher.name() == kWhitelistCiphers[i]) {
                whitelisted = true;
                break;
            }
        }
        if (!whitelisted) {
            // blacklist eNULL, no encryption
            if (cipher.encryptionMethod().isEmpty())
                continue;
            // blacklist aNULL, no authentication
            if (cipher.authenticationMethod().isEmpty())
                continue;
            // blacklist RC4, RSK, CBC, MD5, DES, DSS, EXPORT, NULL
            const QString cipher_name = cipher.name();
            if (isWeakCipher(cipher_name))
                continue;
        }<commit_msg>fix memory invalid access<commit_after>#include "network-mgr.h"
#include <QNetworkAccessManager>
#include <QNetworkProxy>
#include <algorithm>
#include <QStringRef>
#include <QSslConfiguration>
#include <QSslSocket>
#include <QSslCipher>
namespace {
QNetworkProxy proxy_;
template <class T, std::size_t N>
inline size_t ArrayLengthOf(T (&)[N]) {
  return N;
}
const char *const kWhitelistCiphers[] = {"ECDHE-RSA-AES256-GCM-SHA384"
                                         "ECDHE-RSA-AES128-GCM-SHA256"
                                         "DHE-RSA-AES256-GCM-SHA384"
                                         "DHE-RSA-AES128-GCM-SHA256"
                                         "ECDHE-RSA-AES256-SHA384"
                                         "ECDHE-RSA-AES128-SHA256"
                                         "ECDHE-RSA-AES256-SHA"
                                         "ECDHE-RSA-AES128-SHA"
                                         "DHE-RSA-AES256-SHA256"
                                         "DHE-RSA-AES128-SHA256"
                                         "DHE-RSA-AES256-SHA"
                                         "DHE-RSA-AES128-SHA"
                                         "ECDHE-RSA-DES-CBC3-SHA"
                                         "EDH-RSA-DES-CBC3-SHA"
                                         "AES256-GCM-SHA384"
                                         "AES128-GCM-SHA256"
                                         "AES256-SHA256"
                                         "AES128-SHA256"
                                         "AES256-SHA"
                                         "AES128-SHA"
                                         "DES-CBC3-SHA"};
// return false if it contains RC4, RSK, CBC, MD5, DES, DSS, EXPORT, NULL
bool isWeakCipher(const QString& cipher_name)
{
    int current_begin = 0;
    int current_end;
    QStringRef name;
    while((current_end = cipher_name.indexOf("-", current_begin)) != -1) {
        name = QStringRef(&cipher_name, current_begin, current_end - current_begin);
        if (name == "RC4")
            return true;
        else if (name == "PSK")
            return true;
        else if (name == "CBC")
            return true;
        else if (name == "MD5")
            return true;
        else if (name == "DES")
            return true;
        else if (name == "DSS")
            return true;
        else if (name == "EXP")
            return true;
        else if (name == "NULL")
            return true;

        current_begin = current_end + 1;
    }
    return false;
}
} // anonymous namespace

NetworkManager* NetworkManager::instance_ = NULL;

NetworkManager::NetworkManager() : should_retry_(true) {
    // remove unsafe cipher
    QSslConfiguration configuration = QSslConfiguration::defaultConfiguration();
    const QList<QSslCipher> ciphers = QSslSocket::supportedCiphers();

    QList<QSslCipher> new_ciphers;
    Q_FOREACH(const QSslCipher &cipher, ciphers)
    {
        bool whitelisted = false;
        for (unsigned i = 0; i < ArrayLengthOf(kWhitelistCiphers); ++i) {
            if (cipher.name() == kWhitelistCiphers[i]) {
                whitelisted = true;
                break;
            }
        }
        if (!whitelisted) {
            // blacklist eNULL, no encryption
            if (cipher.encryptionMethod().isEmpty())
                continue;
            // blacklist aNULL, no authentication
            if (cipher.authenticationMethod().isEmpty())
                continue;
            // blacklist RC4, RSK, CBC, MD5, DES, DSS, EXPORT, NULL
            const QString cipher_name = cipher.name();
            if (isWeakCipher(cipher_name))
                continue;
        }
{'fraction_non_alphanumeric': 0.1000137193030594, 'fraction_numerical': 0.02826176430237344, 'mean_word_length': 1.2604651162790699, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 80, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3906326', 'n_tokens_mistral': 2143, 'n_tokens_neox': 1863, 'n_words': 414}