test/handshake_helper.c:1624: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned32 by call to `peer_free_data`.
Showing all 17 steps of the trace


test/handshake_helper.c:1344:1: Parameter `client_ctx->sessions->num_nodes`
1342.    * parsing.)
1343.    */
1344. > static HANDSHAKE_RESULT *do_handshake_internal(
1345.       SSL_CTX *server_ctx, SSL_CTX *server2_ctx, SSL_CTX *client_ctx,
1346.       const SSL_TEST_CTX *test_ctx, const SSL_TEST_EXTRA_CONF *extra,

test/handshake_helper.c:1624:5: Call
1622.       ctx_data_free_data(&client_ctx_data);
1623.   
1624.       peer_free_data(&server);
            ^
1625.       peer_free_data(&client);
1626.       return ret;

test/handshake_helper.c:727:1: Parameter `peer->ssl->ctx->sessions->num_nodes`
  725.   }
  726.   
  727. > static void peer_free_data(PEER *peer)
  728.   {
  729.       SSL_free(peer->ssl);

test/handshake_helper.c:729:5: Call
  727.   static void peer_free_data(PEER *peer)
  728.   {
  729.       SSL_free(peer->ssl);
             ^
  730.       OPENSSL_free(peer->write_buf);
  731.       OPENSSL_free(peer->read_buf);

ssl/ssl_lib.c:1132:1: Parameter `s->ctx->sessions->num_nodes`
    1130.   }
    1131.   
    1132. > void SSL_free(SSL *s)
    1133.   {
    1134.       int i;

ssl/ssl_lib.c:1204:5: Call
    1202.       RECORD_LAYER_release(&s->rlayer);
    1203.   
    1204.       SSL_CTX_free(s->ctx);
                ^
    1205.   
    1206.       ASYNC_WAIT_CTX_free(s->waitctx);

ssl/ssl_lib.c:3017:1: Parameter `a->sessions->num_nodes`
      3015.   }
      3016.   
      3017. > void SSL_CTX_free(SSL_CTX *a)
      3018.   {
      3019.       int i;

ssl/ssl_lib.c:3043:9: Call
      3041.        */
      3042.       if (a->sessions != NULL)
      3043.           SSL_CTX_flush_sessions(a, 0);
                      ^
      3044.   
      3045.       CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);

ssl/ssl_sess.c:1102:1: Parameter `s->sessions->num_nodes`
        1100.   IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM);
        1101.   
        1102. > void SSL_CTX_flush_sessions(SSL_CTX *s, long t)
        1103.   {
        1104.       unsigned long i;

ssl/ssl_sess.c:1115:5: Call
        1113.       i = lh_SSL_SESSION_get_down_load(s->sessions);
        1114.       lh_SSL_SESSION_set_down_load(s->sessions, 0);
        1115.       lh_SSL_SESSION_doall_TIMEOUT_PARAM(tp.cache, timeout_cb, &tp);
                    ^
        1116.       lh_SSL_SESSION_set_down_load(s->sessions, i);
        1117.       CRYPTO_THREAD_unlock(s->lock);

ssl/ssl_sess.c:1100:1: Parameter `lh->num_nodes`
          1098.   }
          1099.   
          1100. > IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM);
          1101.   
          1102.   void SSL_CTX_flush_sessions(SSL_CTX *s, long t)

ssl/ssl_sess.c:1100:1: Call
          1098.   }
          1099.   
          1100. > IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM);
          1101.   
          1102.   void SSL_CTX_flush_sessions(SSL_CTX *s, long t)

crypto/lhash/lhash.c:198:1: Parameter `lh->num_nodes`
            196.   }
            197.   
            198. > void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg)
            199.   {
            200.       doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);

crypto/lhash/lhash.c:200:5: Call
            198.   void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg)
            199.   {
            200.       doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);
                       ^
            201.   }
            202.   

crypto/lhash/lhash.c:166:1: <LHS trace>
164.   }
165.   
166. > static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,
167.                             OPENSSL_LH_DOALL_FUNC func,
168.                             OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)

crypto/lhash/lhash.c:166:1: Parameter `lh->num_nodes`
              164.   }
              165.   
              166. > static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,
              167.                             OPENSSL_LH_DOALL_FUNC func,
              168.                             OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)

crypto/lhash/lhash.c:180:10: Binary operation: ([0, +oo] - 1):unsigned32 by call to `peer_free_data` 
              178.        * memory leaks otherwise
              179.        */
              180.       for (i = lh->num_nodes - 1; i >= 0; i--) {
                              ^
              181.           a = lh->b[i];
              182.           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 HANDSHAKE_RESULT *do_handshake_internal(\n    SSL_CTX *server_ctx, SSL_CTX *server2_ctx, SSL_CTX *client_ctx,\n    const SSL_TEST_CTX *test_ctx, const SSL_TEST_EXTRA_CONF *extra,\n    SSL_SESSION *session_in, SSL_SESSION **session_out)\n{\n    PEER server, client;\n    BIO *client_to_server = NULL, *server_to_client = NULL;\n    HANDSHAKE_EX_DATA server_ex_data, client_ex_data;\n    CTX_DATA client_ctx_data, server_ctx_data, server2_ctx_data;\n    HANDSHAKE_RESULT *ret = HANDSHAKE_RESULT_new();\n    int client_turn = 1, client_turn_count = 0;\n    connect_phase_t phase = HANDSHAKE;\n    handshake_status_t status = HANDSHAKE_RETRY;\n    const unsigned char* tick = NULL;\n    size_t tick_len = 0;\n    const unsigned char* sess_id = NULL;\n    unsigned int sess_id_len = 0;\n    SSL_SESSION* sess = NULL;\n    const unsigned char *proto = NULL;\n    unsigned int proto_len = 0;\n    EVP_PKEY *tmp_key;\n    const STACK_OF(X509_NAME) *names;\n    time_t start;\n    const char* cipher;\n    if (ret == NULL)\n        return NULL;\n    memset(&server_ctx_data, 0, sizeof(server_ctx_data));\n    memset(&server2_ctx_data, 0, sizeof(server2_ctx_data));\n    memset(&client_ctx_data, 0, sizeof(client_ctx_data));\n    memset(&server, 0, sizeof(server));\n    memset(&client, 0, sizeof(client));\n    memset(&server_ex_data, 0, sizeof(server_ex_data));\n    memset(&client_ex_data, 0, sizeof(client_ex_data));\n    if (!configure_handshake_ctx(server_ctx, server2_ctx, client_ctx,\n                                 test_ctx, extra, &server_ctx_data,\n                                 &server2_ctx_data, &client_ctx_data)) {\n        TEST_note("configure_handshake_ctx");\n        return NULL;\n    }\n    if (!create_peer(&server, server_ctx)) {\n        TEST_note("creating server context");\n        goto err;\n    }\n    if (!create_peer(&client, client_ctx)) {\n        TEST_note("creating client context");\n        goto err;\n    }\n    server.bytes_to_write = client.bytes_to_read = test_ctx->app_data_size;\n    client.bytes_to_write = server.bytes_to_read = test_ctx->app_data_size;\n    configure_handshake_ssl(server.ssl, client.ssl, extra);\n    if (session_in != NULL) {\n        if (!TEST_true(SSL_CTX_add_session(server_ctx, session_in))\n                || !TEST_true(SSL_set_session(client.ssl, session_in)))\n            goto err;\n    }\n    ret->result = SSL_TEST_INTERNAL_ERROR;\n    if (test_ctx->use_sctp) {\n#if !defined(OPENSSL_NO_SCTP) && !defined(OPENSSL_NO_SOCK)\n        int csock, ssock;\n        if (create_sctp_socks(&ssock, &csock)) {\n            client_to_server = BIO_new_dgram_sctp(csock, BIO_CLOSE);\n            server_to_client = BIO_new_dgram_sctp(ssock, BIO_CLOSE);\n        }\n#endif\n    } else {\n        client_to_server = BIO_new(BIO_s_mem());\n        server_to_client = BIO_new(BIO_s_mem());\n    }\n    if (!TEST_ptr(client_to_server)\n            || !TEST_ptr(server_to_client))\n        goto err;\n    BIO_set_nbio(client_to_server, 1);\n    BIO_set_nbio(server_to_client, 1);\n    SSL_set_connect_state(client.ssl);\n    SSL_set_accept_state(server.ssl);\n    if (test_ctx->use_sctp) {\n        SSL_set_bio(client.ssl, client_to_server, client_to_server);\n        SSL_set_bio(server.ssl, server_to_client, server_to_client);\n    } else {\n        SSL_set_bio(client.ssl, server_to_client, client_to_server);\n        if (!TEST_int_gt(BIO_up_ref(server_to_client), 0)\n                || !TEST_int_gt(BIO_up_ref(client_to_server), 0))\n            goto err;\n        SSL_set_bio(server.ssl, client_to_server, server_to_client);\n    }\n    ex_data_idx = SSL_get_ex_new_index(0, "ex data", NULL, NULL, NULL);\n    if (!TEST_int_ge(ex_data_idx, 0)\n            || !TEST_int_eq(SSL_set_ex_data(server.ssl, ex_data_idx, &server_ex_data), 1)\n            || !TEST_int_eq(SSL_set_ex_data(client.ssl, ex_data_idx, &client_ex_data), 1))\n        goto err;\n    SSL_set_info_callback(server.ssl, &info_cb);\n    SSL_set_info_callback(client.ssl, &info_cb);\n    client.status = PEER_RETRY;\n    server.status = PEER_WAITING;\n    start = time(NULL);\n    for(;;) {\n        if (client_turn) {\n            do_connect_step(test_ctx, &client, phase);\n            status = handshake_status(client.status, server.status,\n                                      1  );\n            if (server.status == PEER_WAITING)\n                server.status = PEER_RETRY;\n        } else {\n            do_connect_step(test_ctx, &server, phase);\n            status = handshake_status(server.status, client.status,\n                                      0  );\n        }\n        switch (status) {\n        case HANDSHAKE_SUCCESS:\n            client_turn_count = 0;\n            phase = next_phase(test_ctx, phase);\n            if (phase == CONNECTION_DONE) {\n                ret->result = SSL_TEST_SUCCESS;\n                goto err;\n            } else {\n                client.status = server.status = PEER_RETRY;\n                client_turn = 1;\n                break;\n            }\n        case CLIENT_ERROR:\n            ret->result = SSL_TEST_CLIENT_FAIL;\n            goto err;\n        case SERVER_ERROR:\n            ret->result = SSL_TEST_SERVER_FAIL;\n            goto err;\n        case INTERNAL_ERROR:\n            ret->result = SSL_TEST_INTERNAL_ERROR;\n            goto err;\n        case HANDSHAKE_RETRY:\n            if (test_ctx->use_sctp) {\n                if (time(NULL) - start > 3) {\n                    ret->result = SSL_TEST_INTERNAL_ERROR;\n                    goto err;\n                }\n                if ((client_turn && server.status == PEER_RETRY)\n                        || (!client_turn && client.status == PEER_RETRY))\n                    client_turn ^= 1;\n            } else {\n                if (client_turn_count++ >= 2000) {\n                    ret->result = SSL_TEST_INTERNAL_ERROR;\n                    goto err;\n                }\n                client_turn ^= 1;\n            }\n            break;\n        }\n    }\n err:\n    ret->server_alert_sent = server_ex_data.alert_sent;\n    ret->server_num_fatal_alerts_sent = server_ex_data.num_fatal_alerts_sent;\n    ret->server_alert_received = client_ex_data.alert_received;\n    ret->client_alert_sent = client_ex_data.alert_sent;\n    ret->client_num_fatal_alerts_sent = client_ex_data.num_fatal_alerts_sent;\n    ret->client_alert_received = server_ex_data.alert_received;\n    ret->server_protocol = SSL_version(server.ssl);\n    ret->client_protocol = SSL_version(client.ssl);\n    ret->servername = server_ex_data.servername;\n    if ((sess = SSL_get0_session(client.ssl)) != NULL) {\n        SSL_SESSION_get0_ticket(sess, &tick, &tick_len);\n        sess_id = SSL_SESSION_get_id(sess, &sess_id_len);\n    }\n    if (tick == NULL || tick_len == 0)\n        ret->session_ticket = SSL_TEST_SESSION_TICKET_NO;\n    else\n        ret->session_ticket = SSL_TEST_SESSION_TICKET_YES;\n    ret->compression = (SSL_get_current_compression(client.ssl) == NULL)\n                       ? SSL_TEST_COMPRESSION_NO\n                       : SSL_TEST_COMPRESSION_YES;\n    if (sess_id == NULL || sess_id_len == 0)\n        ret->session_id = SSL_TEST_SESSION_ID_NO;\n    else\n        ret->session_id = SSL_TEST_SESSION_ID_YES;\n    ret->session_ticket_do_not_call = server_ex_data.session_ticket_do_not_call;\n#ifndef OPENSSL_NO_NEXTPROTONEG\n    SSL_get0_next_proto_negotiated(client.ssl, &proto, &proto_len);\n    ret->client_npn_negotiated = dup_str(proto, proto_len);\n    SSL_get0_next_proto_negotiated(server.ssl, &proto, &proto_len);\n    ret->server_npn_negotiated = dup_str(proto, proto_len);\n#endif\n    SSL_get0_alpn_selected(client.ssl, &proto, &proto_len);\n    ret->client_alpn_negotiated = dup_str(proto, proto_len);\n    SSL_get0_alpn_selected(server.ssl, &proto, &proto_len);\n    ret->server_alpn_negotiated = dup_str(proto, proto_len);\n    ret->client_resumed = SSL_session_reused(client.ssl);\n    ret->server_resumed = SSL_session_reused(server.ssl);\n    cipher = SSL_CIPHER_get_name(SSL_get_current_cipher(client.ssl));\n    ret->cipher = dup_str((const unsigned char*)cipher, strlen(cipher));\n    if (session_out != NULL)\n        *session_out = SSL_get1_session(client.ssl);\n    if (SSL_get_server_tmp_key(client.ssl, &tmp_key)) {\n        ret->tmp_key_type = pkey_type(tmp_key);\n        EVP_PKEY_free(tmp_key);\n    }\n    SSL_get_peer_signature_nid(client.ssl, &ret->server_sign_hash);\n    SSL_get_peer_signature_nid(server.ssl, &ret->client_sign_hash);\n    SSL_get_peer_signature_type_nid(client.ssl, &ret->server_sign_type);\n    SSL_get_peer_signature_type_nid(server.ssl, &ret->client_sign_type);\n    names = SSL_get0_peer_CA_list(client.ssl);\n    if (names == NULL)\n        ret->client_ca_names = NULL;\n    else\n        ret->client_ca_names = SSL_dup_CA_list(names);\n    names = SSL_get0_peer_CA_list(server.ssl);\n    if (names == NULL)\n        ret->server_ca_names = NULL;\n    else\n        ret->server_ca_names = SSL_dup_CA_list(names);\n    ret->server_cert_type = peer_pkey_type(client.ssl);\n    ret->client_cert_type = peer_pkey_type(server.ssl);\n    ctx_data_free_data(&server_ctx_data);\n    ctx_data_free_data(&server2_ctx_data);\n    ctx_data_free_data(&client_ctx_data);\n    peer_free_data(&server);\n    peer_free_data(&client);\n    return ret;\n}', 'static void peer_free_data(PEER *peer)\n{\n    SSL_free(peer->ssl);\n    OPENSSL_free(peer->write_buf);\n    OPENSSL_free(peer->read_buf);\n}', 'void SSL_free(SSL *s)\n{\n    int i;\n    if (s == NULL)\n        return;\n    CRYPTO_DOWN_REF(&s->references, &i, s->lock);\n    REF_PRINT_COUNT("SSL", s);\n    if (i > 0)\n        return;\n    REF_ASSERT_ISNT(i < 0);\n    X509_VERIFY_PARAM_free(s->param);\n    dane_final(&s->dane);\n    CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n    ssl_free_wbio_buffer(s);\n    BIO_free_all(s->wbio);\n    BIO_free_all(s->rbio);\n    BUF_MEM_free(s->init_buf);\n    sk_SSL_CIPHER_free(s->cipher_list);\n    sk_SSL_CIPHER_free(s->cipher_list_by_id);\n    if (s->session != NULL) {\n        ssl_clear_bad_session(s);\n        SSL_SESSION_free(s->session);\n    }\n    SSL_SESSION_free(s->psksession);\n    OPENSSL_free(s->psksession_id);\n    clear_ciphers(s);\n    ssl_cert_free(s->cert);\n    OPENSSL_free(s->ext.hostname);\n    SSL_CTX_free(s->session_ctx);\n#ifndef OPENSSL_NO_EC\n    OPENSSL_free(s->ext.ecpointformats);\n    OPENSSL_free(s->ext.supportedgroups);\n#endif\n    sk_X509_EXTENSION_pop_free(s->ext.ocsp.exts, X509_EXTENSION_free);\n#ifndef OPENSSL_NO_OCSP\n    sk_OCSP_RESPID_pop_free(s->ext.ocsp.ids, OCSP_RESPID_free);\n#endif\n#ifndef OPENSSL_NO_CT\n    SCT_LIST_free(s->scts);\n    OPENSSL_free(s->ext.scts);\n#endif\n    OPENSSL_free(s->ext.ocsp.resp);\n    OPENSSL_free(s->ext.alpn);\n    OPENSSL_free(s->ext.tls13_cookie);\n    OPENSSL_free(s->clienthello);\n    OPENSSL_free(s->pha_context);\n    EVP_MD_CTX_free(s->pha_dgst);\n    sk_X509_NAME_pop_free(s->ca_names, X509_NAME_free);\n    sk_X509_pop_free(s->verified_chain, X509_free);\n    if (s->method != NULL)\n        s->method->ssl_free(s);\n    RECORD_LAYER_release(&s->rlayer);\n    SSL_CTX_free(s->ctx);\n    ASYNC_WAIT_CTX_free(s->waitctx);\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n    OPENSSL_free(s->ext.npn);\n#endif\n#ifndef OPENSSL_NO_SRTP\n    sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);\n#endif\n    RAND_DRBG_free(s->drbg);\n    CRYPTO_THREAD_lock_free(s->lock);\n    OPENSSL_free(s);\n}', 'void SSL_CTX_free(SSL_CTX *a)\n{\n    int i;\n    if (a == NULL)\n        return;\n    CRYPTO_DOWN_REF(&a->references, &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->ca_names, 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->ext.ecpointformats);\n    OPENSSL_free(a->ext.supportedgroups);\n#endif\n    OPENSSL_free(a->ext.alpn);\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}']