test/ssl_test.c:288: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned32 by call to `SSL_CTX_free`.
Showing all 16 steps of the trace


test/ssl_test.c:229:22: Call
227.   #ifndef OPENSSL_NO_DTLS
228.       if (test_ctx->method == SSL_TEST_METHOD_DTLS) {
229.           server_ctx = SSL_CTX_new(DTLS_server_method());
                            ^
230.           if (test_ctx->extra.server.servername_callback !=
231.               SSL_TEST_SERVERNAME_CB_NONE) {

ssl/ssl_lib.c:2390:21: Call
  2388.           goto err;
  2389.   
  2390.       ret->sessions = lh_SSL_SESSION_new(ssl_session_hash, ssl_session_cmp);
                              ^
  2391.       if (ret->sessions == NULL)
  2392.           goto err;

ssl/ssl_locl.h:584:1: Call
    582.   };
    583.   
    584. > DEFINE_LHASH_OF(SSL_SESSION);
    585.   /* Needed in ssl_cert.c */
    586.   DEFINE_LHASH_OF(X509_NAME);

crypto/lhash/lhash.c:37:5: Assignment
      35.       ret->comp = ((c == NULL) ? (OPENSSL_LH_COMPFUNC)strcmp : c);
      36.       ret->hash = ((h == NULL) ? (OPENSSL_LH_HASHFUNC)OPENSSL_LH_strhash : h);
      37.       ret->num_nodes = MIN_NODES / 2;
                ^
      38.       ret->num_alloc_nodes = MIN_NODES;
      39.       ret->pmax = MIN_NODES / 2;

test/ssl_test.c:288:5: Call
286.   err:
287.       CONF_modules_unload(0);
288.       SSL_CTX_free(server_ctx);
           ^
289.       SSL_CTX_free(server2_ctx);
290.       SSL_CTX_free(client_ctx);

ssl/ssl_lib.c:2498:1: Parameter `a->sessions->num_nodes`
  2496.   }
  2497.   
  2498. > void SSL_CTX_free(SSL_CTX *a)
  2499.   {
  2500.       int i;

ssl/ssl_lib.c:2524:9: Call
  2522.        */
  2523.       if (a->sessions != NULL)
  2524.           SSL_CTX_flush_sessions(a, 0);
                  ^
  2525.   
  2526.       CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);

ssl/ssl_sess.c:968:1: Parameter `s->sessions->num_nodes`
    966.   IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM);
    967.   
    968. > void SSL_CTX_flush_sessions(SSL_CTX *s, long t)
    969.   {
    970.       unsigned long i;

ssl/ssl_sess.c:981:5: Call
    979.       i = lh_SSL_SESSION_get_down_load(s->sessions);
    980.       lh_SSL_SESSION_set_down_load(s->sessions, 0);
    981.       lh_SSL_SESSION_doall_TIMEOUT_PARAM(tp.cache, timeout_cb, &tp);
               ^
    982.       lh_SSL_SESSION_set_down_load(s->sessions, i);
    983.       CRYPTO_THREAD_unlock(s->lock);

ssl/ssl_sess.c:966:1: Parameter `lh->num_nodes`
      964.   }
      965.   
      966. > IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM);
      967.   
      968.   void SSL_CTX_flush_sessions(SSL_CTX *s, long t)

ssl/ssl_sess.c:966:1: Call
      964.   }
      965.   
      966. > IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM);
      967.   
      968.   void SSL_CTX_flush_sessions(SSL_CTX *s, long t)

crypto/lhash/lhash.c:182:1: Parameter `lh->num_nodes`
        180.   }
        181.   
        182. > void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg)
        183.   {
        184.       doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);

crypto/lhash/lhash.c:184:5: Call
        182.   void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg)
        183.   {
        184.       doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);
                   ^
        185.   }
        186.   

crypto/lhash/lhash.c:150:1: <LHS trace>
148.   }
149.   
150. > static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,
151.                             OPENSSL_LH_DOALL_FUNC func,
152.                             OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)

crypto/lhash/lhash.c:150:1: Parameter `lh->num_nodes`
          148.   }
          149.   
          150. > static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,
          151.                             OPENSSL_LH_DOALL_FUNC func,
          152.                             OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)

crypto/lhash/lhash.c:164:10: Binary operation: ([0, +oo] - 1):unsigned32 by call to `SSL_CTX_free` 
          162.        * memory leaks otherwise
          163.        */
          164.       for (i = lh->num_nodes - 1; i >= 0; i--) {
                          ^
          165.           a = lh->b[i];
          166.           while (a != NULL) {

static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,
                          OPENSSL_LH_DOALL_FUNC func,
                          OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)
{
    int i;
    OPENSSL_LH_NODE *a, *n;
    if (lh == NULL)
        return;
    for (i = lh->num_nodes - 1; i >= 0; i--) {
        a = lh->b[i];
        while (a != NULL) {
            n = a->next;
            if (use_arg)
                func_arg(a->data, arg);
            else
                func(a->data);
            a = n;
        }
    }
}
['static int execute_test(SSL_TEST_FIXTURE fixture)\n{\n    int ret = 0;\n    SSL_CTX *server_ctx = NULL, *server2_ctx = NULL, *client_ctx = NULL,\n        *resume_server_ctx = NULL, *resume_client_ctx = NULL;\n    SSL_TEST_CTX *test_ctx = NULL;\n    HANDSHAKE_RESULT *result = NULL;\n    test_ctx = SSL_TEST_CTX_create(conf, fixture.test_app);\n    if (test_ctx == NULL)\n        goto err;\n#ifndef OPENSSL_NO_DTLS\n    if (test_ctx->method == SSL_TEST_METHOD_DTLS) {\n        server_ctx = SSL_CTX_new(DTLS_server_method());\n        if (test_ctx->extra.server.servername_callback !=\n            SSL_TEST_SERVERNAME_CB_NONE) {\n            server2_ctx = SSL_CTX_new(DTLS_server_method());\n            OPENSSL_assert(server2_ctx != NULL);\n        }\n        client_ctx = SSL_CTX_new(DTLS_client_method());\n        if (test_ctx->handshake_mode == SSL_TEST_HANDSHAKE_RESUME) {\n            resume_server_ctx = SSL_CTX_new(DTLS_server_method());\n            resume_client_ctx = SSL_CTX_new(DTLS_client_method());\n            OPENSSL_assert(resume_server_ctx != NULL);\n            OPENSSL_assert(resume_client_ctx != NULL);\n        }\n    }\n#endif\n    if (test_ctx->method == SSL_TEST_METHOD_TLS) {\n        server_ctx = SSL_CTX_new(TLS_server_method());\n        if (test_ctx->extra.server.servername_callback !=\n            SSL_TEST_SERVERNAME_CB_NONE) {\n            server2_ctx = SSL_CTX_new(TLS_server_method());\n            OPENSSL_assert(server2_ctx != NULL);\n        }\n        client_ctx = SSL_CTX_new(TLS_client_method());\n        if (test_ctx->handshake_mode == SSL_TEST_HANDSHAKE_RESUME) {\n            resume_server_ctx = SSL_CTX_new(TLS_server_method());\n            resume_client_ctx = SSL_CTX_new(TLS_client_method());\n            OPENSSL_assert(resume_server_ctx != NULL);\n            OPENSSL_assert(resume_client_ctx != NULL);\n        }\n    }\n    OPENSSL_assert(server_ctx != NULL);\n    OPENSSL_assert(client_ctx != NULL);\n    OPENSSL_assert(CONF_modules_load(conf, fixture.test_app, 0) > 0);\n    if (!SSL_CTX_config(server_ctx, "server")\n        || !SSL_CTX_config(client_ctx, "client")) {\n        goto err;\n    }\n    if (server2_ctx != NULL && !SSL_CTX_config(server2_ctx, "server2"))\n        goto err;\n    if (resume_server_ctx != NULL\n        && !SSL_CTX_config(resume_server_ctx, "resume-server"))\n        goto err;\n    if (resume_client_ctx != NULL\n        && !SSL_CTX_config(resume_client_ctx, "resume-client"))\n        goto err;\n    result = do_handshake(server_ctx, server2_ctx, client_ctx,\n                          resume_server_ctx, resume_client_ctx, test_ctx);\n    ret = check_test(result, test_ctx);\nerr:\n    CONF_modules_unload(0);\n    SSL_CTX_free(server_ctx);\n    SSL_CTX_free(server2_ctx);\n    SSL_CTX_free(client_ctx);\n    SSL_CTX_free(resume_server_ctx);\n    SSL_CTX_free(resume_client_ctx);\n    SSL_TEST_CTX_free(test_ctx);\n    if (ret != 1)\n        ERR_print_errors_fp(stderr);\n    HANDSHAKE_RESULT_free(result);\n    return ret;\n}', 'SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth)\n{\n    SSL_CTX *ret = NULL;\n    if (meth == NULL) {\n        SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_NULL_SSL_METHOD_PASSED);\n        return (NULL);\n    }\n    if (!OPENSSL_init_ssl(OPENSSL_INIT_LOAD_SSL_STRINGS, NULL))\n        return NULL;\n    if (FIPS_mode() && (meth->version < TLS1_VERSION)) {\n        SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_AT_LEAST_TLS_1_0_NEEDED_IN_FIPS_MODE);\n        return NULL;\n    }\n    if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) {\n        SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);\n        goto err;\n    }\n    ret = OPENSSL_zalloc(sizeof(*ret));\n    if (ret == NULL)\n        goto err;\n    ret->method = meth;\n    ret->min_proto_version = 0;\n    ret->max_proto_version = 0;\n    ret->session_cache_mode = SSL_SESS_CACHE_SERVER;\n    ret->session_cache_size = SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;\n    ret->session_timeout = meth->get_timeout();\n    ret->references = 1;\n    ret->lock = CRYPTO_THREAD_lock_new();\n    if (ret->lock == NULL) {\n        SSLerr(SSL_F_SSL_CTX_NEW, ERR_R_MALLOC_FAILURE);\n        OPENSSL_free(ret);\n        return NULL;\n    }\n    ret->max_cert_list = SSL_MAX_CERT_LIST_DEFAULT;\n    ret->verify_mode = SSL_VERIFY_NONE;\n    if ((ret->cert = ssl_cert_new()) == NULL)\n        goto err;\n    ret->sessions = lh_SSL_SESSION_new(ssl_session_hash, ssl_session_cmp);\n    if (ret->sessions == NULL)\n        goto err;\n    ret->cert_store = X509_STORE_new();\n    if (ret->cert_store == NULL)\n        goto err;\n#ifndef OPENSSL_NO_CT\n    ret->ctlog_store = CTLOG_STORE_new();\n    if (ret->ctlog_store == NULL)\n        goto err;\n#endif\n    if (!ssl_create_cipher_list(ret->method,\n                           &ret->cipher_list, &ret->cipher_list_by_id,\n                           SSL_DEFAULT_CIPHER_LIST, ret->cert)\n       || sk_SSL_CIPHER_num(ret->cipher_list) <= 0) {\n        SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_LIBRARY_HAS_NO_CIPHERS);\n        goto err2;\n    }\n    ret->param = X509_VERIFY_PARAM_new();\n    if (ret->param == NULL)\n        goto err;\n    if ((ret->md5 = EVP_get_digestbyname("ssl3-md5")) == NULL) {\n        SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES);\n        goto err2;\n    }\n    if ((ret->sha1 = EVP_get_digestbyname("ssl3-sha1")) == NULL) {\n        SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES);\n        goto err2;\n    }\n    if ((ret->client_CA = sk_X509_NAME_new_null()) == NULL)\n        goto err;\n    if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_CTX, ret, &ret->ex_data))\n        goto err;\n    if (!(meth->ssl3_enc->enc_flags & SSL_ENC_FLAG_DTLS))\n        ret->comp_methods = SSL_COMP_get_compression_methods();\n    ret->max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH;\n    ret->split_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH;\n    if ((RAND_bytes(ret->tlsext_tick_key_name, sizeof(ret->tlsext_tick_key_name)) <= 0)\n        || (RAND_bytes(ret->tlsext_tick_hmac_key, sizeof(ret->tlsext_tick_hmac_key)) <= 0)\n        || (RAND_bytes(ret->tlsext_tick_aes_key, sizeof(ret->tlsext_tick_aes_key)) <= 0))\n        ret->options |= SSL_OP_NO_TICKET;\n#ifndef OPENSSL_NO_SRP\n    if (!SSL_CTX_SRP_CTX_init(ret))\n        goto err;\n#endif\n#ifndef OPENSSL_NO_ENGINE\n# ifdef OPENSSL_SSL_CLIENT_ENGINE_AUTO\n#  define eng_strx(x)     #x\n#  define eng_str(x)      eng_strx(x)\n    {\n        ENGINE *eng;\n        eng = ENGINE_by_id(eng_str(OPENSSL_SSL_CLIENT_ENGINE_AUTO));\n        if (!eng) {\n            ERR_clear_error();\n            ENGINE_load_builtin_engines();\n            eng = ENGINE_by_id(eng_str(OPENSSL_SSL_CLIENT_ENGINE_AUTO));\n        }\n        if (!eng || !SSL_CTX_set_client_cert_engine(ret, eng))\n            ERR_clear_error();\n    }\n# endif\n#endif\n    ret->options |= SSL_OP_LEGACY_SERVER_CONNECT;\n    ret->options |= SSL_OP_NO_COMPRESSION;\n    ret->tlsext_status_type = -1;\n    return ret;\n err:\n    SSLerr(SSL_F_SSL_CTX_NEW, ERR_R_MALLOC_FAILURE);\n err2:\n    SSL_CTX_free(ret);\n    return NULL;\n}', 'DEFINE_LHASH_OF(SSL_SESSION)', 'OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c)\n{\n    OPENSSL_LHASH *ret;\n    if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)\n        goto err0;\n    if ((ret->b = OPENSSL_zalloc(sizeof(*ret->b) * MIN_NODES)) == NULL)\n        goto err1;\n    ret->comp = ((c == NULL) ? (OPENSSL_LH_COMPFUNC)strcmp : c);\n    ret->hash = ((h == NULL) ? (OPENSSL_LH_HASHFUNC)OPENSSL_LH_strhash : h);\n    ret->num_nodes = MIN_NODES / 2;\n    ret->num_alloc_nodes = MIN_NODES;\n    ret->pmax = MIN_NODES / 2;\n    ret->up_load = UP_LOAD;\n    ret->down_load = DOWN_LOAD;\n    return (ret);\n err1:\n    OPENSSL_free(ret);\n err0:\n    return (NULL);\n}', 'void SSL_CTX_free(SSL_CTX *a)\n{\n    int i;\n    if (a == NULL)\n        return;\n    CRYPTO_atomic_add(&a->references, -1, &i, a->lock);\n    REF_PRINT_COUNT("SSL_CTX", a);\n    if (i > 0)\n        return;\n    REF_ASSERT_ISNT(i < 0);\n    X509_VERIFY_PARAM_free(a->param);\n    dane_ctx_final(&a->dane);\n    if (a->sessions != NULL)\n        SSL_CTX_flush_sessions(a, 0);\n    CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);\n    lh_SSL_SESSION_free(a->sessions);\n    X509_STORE_free(a->cert_store);\n#ifndef OPENSSL_NO_CT\n    CTLOG_STORE_free(a->ctlog_store);\n#endif\n    sk_SSL_CIPHER_free(a->cipher_list);\n    sk_SSL_CIPHER_free(a->cipher_list_by_id);\n    ssl_cert_free(a->cert);\n    sk_X509_NAME_pop_free(a->client_CA, X509_NAME_free);\n    sk_X509_pop_free(a->extra_certs, X509_free);\n    a->comp_methods = NULL;\n#ifndef OPENSSL_NO_SRTP\n    sk_SRTP_PROTECTION_PROFILE_free(a->srtp_profiles);\n#endif\n#ifndef OPENSSL_NO_SRP\n    SSL_CTX_SRP_CTX_free(a);\n#endif\n#ifndef OPENSSL_NO_ENGINE\n    ENGINE_finish(a->client_cert_engine);\n#endif\n#ifndef OPENSSL_NO_EC\n    OPENSSL_free(a->tlsext_ecpointformatlist);\n    OPENSSL_free(a->tlsext_ellipticcurvelist);\n#endif\n    OPENSSL_free(a->alpn_client_proto_list);\n    CRYPTO_THREAD_lock_free(a->lock);\n    OPENSSL_free(a);\n}', 'void SSL_CTX_flush_sessions(SSL_CTX *s, long t)\n{\n    unsigned long i;\n    TIMEOUT_PARAM tp;\n    tp.ctx = s;\n    tp.cache = s->sessions;\n    if (tp.cache == NULL)\n        return;\n    tp.time = t;\n    CRYPTO_THREAD_write_lock(s->lock);\n    i = lh_SSL_SESSION_get_down_load(s->sessions);\n    lh_SSL_SESSION_set_down_load(s->sessions, 0);\n    lh_SSL_SESSION_doall_TIMEOUT_PARAM(tp.cache, timeout_cb, &tp);\n    lh_SSL_SESSION_set_down_load(s->sessions, i);\n    CRYPTO_THREAD_unlock(s->lock);\n}', 'IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM)', 'void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg)\n{\n    doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);\n}', 'static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,\n                          OPENSSL_LH_DOALL_FUNC func,\n                          OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)\n{\n    int i;\n    OPENSSL_LH_NODE *a, *n;\n    if (lh == NULL)\n        return;\n    for (i = lh->num_nodes - 1; i >= 0; i--) {\n        a = lh->b[i];\n        while (a != NULL) {\n            n = a->next;\n            if (use_arg)\n                func_arg(a->data, arg);\n            else\n                func(a->data);\n            a = n;\n        }\n    }\n}']