test/sslapitest.c:1413: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned32 by call to `SSL_free`.
Showing all 21 steps of the trace


test/sslapitest.c:1378:10: Call
1376.       /* Force a connection failure */
1377.       SSL_CTX_set_max_proto_version(sctx, TLS1_1_VERSION);
1378.       if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl3,
                 ^
1379.                                         &clientssl3, NULL, NULL))
1380.               || !TEST_true(SSL_set_session(clientssl3, sess1))

test/ssltestlib.c:797:15: Call
  795.       if (*sssl != NULL)
  796.           serverssl = *sssl;
  797.       else if (!TEST_ptr(serverssl = SSL_new(serverctx)))
                       ^
  798.           goto error;
  799.       if (*cssl != NULL)

ssl/ssl_lib.c:673:1: Parameter `ctx->sessions->num_nodes`
    671.   }
    672.   
    673. > SSL *SSL_new(SSL_CTX *ctx)
    674.   {
    675.       SSL *s;

test/sslapitest.c:1380:17: Call
1378.       if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl3,
1379.                                         &clientssl3, NULL, NULL))
1380.               || !TEST_true(SSL_set_session(clientssl3, sess1))
                        ^
1381.               /* This should fail because of the mismatched protocol versions */
1382.               || !TEST_false(create_ssl_connection(serverssl3, clientssl3,

ssl/ssl_sess.c:829:1: Parameter `s->session_ctx->sessions->num_nodes`
  827.   }
  828.   
  829. > int SSL_set_session(SSL *s, SSL_SESSION *session)
  830.   {
  831.       ssl_clear_bad_session(s);

ssl/ssl_sess.c:831:5: Call
  829.   int SSL_set_session(SSL *s, SSL_SESSION *session)
  830.   {
  831.       ssl_clear_bad_session(s);
             ^
  832.       if (s->ctx->method != s->method) {
  833.           if (!SSL_set_ssl_method(s, s->ctx->method))

ssl/ssl_sess.c:1124:1: Parameter `s->session_ctx->sessions->num_nodes`
    1122.   }
    1123.   
    1124. > int ssl_clear_bad_session(SSL *s)
    1125.   {
    1126.       if ((s->session != NULL) &&

test/sslapitest.c:1413:5: Call
1411.                                          | SSL_SESS_CACHE_NO_INTERNAL_STORE);
1412.   
1413.       SSL_free(serverssl1);
            ^
1414.       SSL_free(clientssl1);
1415.       serverssl1 = clientssl1 = NULL;

ssl/ssl_lib.c:1138:1: Parameter `s->ctx->sessions->num_nodes`
  1136.   }
  1137.   
  1138. > void SSL_free(SSL *s)
  1139.   {
  1140.       int i;

ssl/ssl_lib.c:1213:5: Call
  1211.           s->method->ssl_free(s);
  1212.   
  1213.       SSL_CTX_free(s->ctx);
              ^
  1214.   
  1215.       ASYNC_WAIT_CTX_free(s->waitctx);

ssl/ssl_lib.c:3163:1: Parameter `a->sessions->num_nodes`
    3161.   }
    3162.   
    3163. > void SSL_CTX_free(SSL_CTX *a)
    3164.   {
    3165.       int i;

ssl/ssl_lib.c:3189:9: Call
    3187.        */
    3188.       if (a->sessions != NULL)
    3189.           SSL_CTX_flush_sessions(a, 0);
                    ^
    3190.   
    3191.       CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);

ssl/ssl_sess.c:1106:1: Parameter `s->sessions->num_nodes`
      1104.   IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM);
      1105.   
      1106. > void SSL_CTX_flush_sessions(SSL_CTX *s, long t)
      1107.   {
      1108.       unsigned long i;

ssl/ssl_sess.c:1119:5: Call
      1117.       i = lh_SSL_SESSION_get_down_load(s->sessions);
      1118.       lh_SSL_SESSION_set_down_load(s->sessions, 0);
      1119.       lh_SSL_SESSION_doall_TIMEOUT_PARAM(tp.cache, timeout_cb, &tp);
                  ^
      1120.       lh_SSL_SESSION_set_down_load(s->sessions, i);
      1121.       CRYPTO_THREAD_unlock(s->lock);

ssl/ssl_sess.c:1104:1: Parameter `lh->num_nodes`
        1102.   }
        1103.   
        1104. > IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM);
        1105.   
        1106.   void SSL_CTX_flush_sessions(SSL_CTX *s, long t)

ssl/ssl_sess.c:1104:1: Call
        1102.   }
        1103.   
        1104. > IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM);
        1105.   
        1106.   void SSL_CTX_flush_sessions(SSL_CTX *s, long t)

crypto/lhash/lhash.c:218:1: Parameter `lh->num_nodes`
          216.   }
          217.   
          218. > void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg)
          219.   {
          220.       doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);

crypto/lhash/lhash.c:220:5: Call
          218.   void OPENSSL_LH_doall_arg(OPENSSL_LHASH *lh, OPENSSL_LH_DOALL_FUNCARG func, void *arg)
          219.   {
          220.       doall_util_fn(lh, 1, (OPENSSL_LH_DOALL_FUNC)0, func, arg);
                     ^
          221.   }
          222.   

crypto/lhash/lhash.c:186:1: <LHS trace>
184.   }
185.   
186. > static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,
187.                             OPENSSL_LH_DOALL_FUNC func,
188.                             OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)

crypto/lhash/lhash.c:186:1: Parameter `lh->num_nodes`
            184.   }
            185.   
            186. > static void doall_util_fn(OPENSSL_LHASH *lh, int use_arg,
            187.                             OPENSSL_LH_DOALL_FUNC func,
            188.                             OPENSSL_LH_DOALL_FUNCARG func_arg, void *arg)

crypto/lhash/lhash.c:200:10: Binary operation: ([0, +oo] - 1):unsigned32 by call to `SSL_free` 
            198.        * memory leaks otherwise
            199.        */
            200.       for (i = lh->num_nodes - 1; i >= 0; i--) {
                            ^
            201.           a = lh->b[i];
            202.           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_session(int maxprot, int use_int_cache,\n                                int use_ext_cache)\n{\n    SSL_CTX *sctx = NULL, *cctx = NULL;\n    SSL *serverssl1 = NULL, *clientssl1 = NULL;\n    SSL *serverssl2 = NULL, *clientssl2 = NULL;\n# ifndef OPENSSL_NO_TLS1_1\n    SSL *serverssl3 = NULL, *clientssl3 = NULL;\n# endif\n    SSL_SESSION *sess1 = NULL, *sess2 = NULL;\n    int testresult = 0, numnewsesstick = 1;\n    new_called = remove_called = 0;\n    if (maxprot == TLS1_3_VERSION)\n        numnewsesstick = 2;\n    if (!TEST_true(create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(),\n                                       TLS1_VERSION, 0,\n                                       &sctx, &cctx, cert, privkey)))\n        return 0;\n    SSL_CTX_set_min_proto_version(cctx, maxprot);\n    SSL_CTX_set_max_proto_version(cctx, maxprot);\n    if (use_ext_cache) {\n        SSL_CTX_sess_set_new_cb(cctx, new_session_cb);\n        SSL_CTX_sess_set_remove_cb(cctx, remove_session_cb);\n    }\n    if (use_int_cache) {\n        SSL_CTX_set_session_cache_mode(cctx, SSL_SESS_CACHE_CLIENT);\n    } else {\n        SSL_CTX_set_session_cache_mode(cctx,\n                                       SSL_SESS_CACHE_CLIENT\n                                       | SSL_SESS_CACHE_NO_INTERNAL_STORE);\n    }\n    if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl1, &clientssl1,\n                                      NULL, NULL))\n            || !TEST_true(create_ssl_connection(serverssl1, clientssl1,\n                                                SSL_ERROR_NONE))\n            || !TEST_ptr(sess1 = SSL_get1_session(clientssl1)))\n        goto end;\n    if (use_int_cache && !TEST_false(SSL_CTX_add_session(cctx, sess1)))\n        goto end;\n    if (use_ext_cache\n            && (!TEST_int_eq(new_called, numnewsesstick)\n                || !TEST_int_eq(remove_called, 0)))\n        goto end;\n    new_called = remove_called = 0;\n    if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl2,\n                                      &clientssl2, NULL, NULL))\n            || !TEST_true(SSL_set_session(clientssl2, sess1))\n            || !TEST_true(create_ssl_connection(serverssl2, clientssl2,\n                                                SSL_ERROR_NONE))\n            || !TEST_true(SSL_session_reused(clientssl2)))\n        goto end;\n    if (maxprot == TLS1_3_VERSION) {\n        if (use_ext_cache\n                && (!TEST_int_eq(new_called, 1)\n                    || !TEST_int_eq(remove_called, 1)))\n            goto end;\n    } else {\n        if (use_ext_cache\n                && (!TEST_int_eq(new_called, 0)\n                    || !TEST_int_eq(remove_called, 0)))\n            goto end;\n    }\n    SSL_SESSION_free(sess1);\n    if (!TEST_ptr(sess1 = SSL_get1_session(clientssl2)))\n        goto end;\n    shutdown_ssl_connection(serverssl2, clientssl2);\n    serverssl2 = clientssl2 = NULL;\n    new_called = remove_called = 0;\n    if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl2,\n                                      &clientssl2, NULL, NULL))\n            || !TEST_true(create_ssl_connection(serverssl2, clientssl2,\n                                                SSL_ERROR_NONE)))\n        goto end;\n    if (!TEST_ptr(sess2 = SSL_get1_session(clientssl2)))\n        goto end;\n    if (use_ext_cache\n            && (!TEST_int_eq(new_called, numnewsesstick)\n                || !TEST_int_eq(remove_called, 0)))\n        goto end;\n    new_called = remove_called = 0;\n    if (!TEST_true(SSL_set_session(clientssl2, sess1)))\n        goto end;\n    if (use_ext_cache\n            && (!TEST_int_eq(new_called, 0) || !TEST_int_eq(remove_called, 1)))\n        goto end;\n    if (!TEST_ptr_eq(SSL_get_session(clientssl2), sess1))\n        goto end;\n    if (use_int_cache) {\n        if (!TEST_true(SSL_CTX_add_session(cctx, sess2))\n                || !TEST_true(SSL_CTX_remove_session(cctx, sess2)))\n            goto end;\n    }\n    new_called = remove_called = 0;\n    if (!TEST_false(SSL_CTX_remove_session(cctx, sess2)))\n        goto end;\n    if (use_ext_cache\n            && (!TEST_int_eq(new_called, 0) || !TEST_int_eq(remove_called, 1)))\n        goto end;\n# if !defined(OPENSSL_NO_TLS1_1)\n    new_called = remove_called = 0;\n    SSL_CTX_set_max_proto_version(sctx, TLS1_1_VERSION);\n    if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl3,\n                                      &clientssl3, NULL, NULL))\n            || !TEST_true(SSL_set_session(clientssl3, sess1))\n            || !TEST_false(create_ssl_connection(serverssl3, clientssl3,\n                                                 SSL_ERROR_NONE)))\n        goto end;\n    if (use_ext_cache\n            && (!TEST_int_eq(new_called, 0) || !TEST_int_eq(remove_called, 1)))\n        goto end;\n    if (use_int_cache && !TEST_true(SSL_CTX_add_session(cctx, sess2)))\n        goto end;\n# endif\n    if (use_ext_cache) {\n        SSL_CTX_sess_set_new_cb(cctx, NULL);\n        SSL_CTX_sess_set_remove_cb(cctx, NULL);\n        SSL_CTX_sess_set_new_cb(sctx, new_session_cb);\n        SSL_CTX_sess_set_remove_cb(sctx, remove_session_cb);\n        SSL_CTX_sess_set_get_cb(sctx, get_session_cb);\n        get_sess_val = NULL;\n    }\n    SSL_CTX_set_session_cache_mode(cctx, 0);\n    if (!use_int_cache)\n        SSL_CTX_set_session_cache_mode(sctx,\n                                       SSL_SESS_CACHE_SERVER\n                                       | SSL_SESS_CACHE_NO_INTERNAL_STORE);\n    SSL_free(serverssl1);\n    SSL_free(clientssl1);\n    serverssl1 = clientssl1 = NULL;\n    SSL_free(serverssl2);\n    SSL_free(clientssl2);\n    serverssl2 = clientssl2 = NULL;\n    SSL_SESSION_free(sess1);\n    sess1 = NULL;\n    SSL_SESSION_free(sess2);\n    sess2 = NULL;\n    SSL_CTX_set_max_proto_version(sctx, maxprot);\n    if (maxprot == TLS1_2_VERSION)\n        SSL_CTX_set_options(sctx, SSL_OP_NO_TICKET);\n    new_called = remove_called = get_called = 0;\n    if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl1, &clientssl1,\n                                      NULL, NULL))\n            || !TEST_true(create_ssl_connection(serverssl1, clientssl1,\n                                                SSL_ERROR_NONE))\n            || !TEST_ptr(sess1 = SSL_get1_session(clientssl1))\n            || !TEST_ptr(sess2 = SSL_get1_session(serverssl1)))\n        goto end;\n    if (use_int_cache) {\n        if (maxprot == TLS1_3_VERSION && !use_ext_cache) {\n            if (!TEST_false(SSL_CTX_remove_session(sctx, sess2)))\n                goto end;\n        } else {\n            if (!TEST_false(SSL_CTX_add_session(sctx, sess2)))\n                goto end;\n        }\n    }\n    if (use_ext_cache) {\n        SSL_SESSION *tmp = sess2;\n        if (!TEST_int_eq(new_called, numnewsesstick)\n                || !TEST_int_eq(remove_called, 0)\n                || !TEST_int_eq(get_called, 0))\n            goto end;\n        if (use_int_cache && maxprot != TLS1_3_VERSION) {\n            if (!TEST_ptr(tmp = SSL_SESSION_dup(sess2))\n                    || !TEST_true(SSL_CTX_remove_session(sctx, sess2)))\n                goto end;\n            SSL_SESSION_free(sess2);\n        }\n        sess2 = tmp;\n    }\n    new_called = remove_called = get_called = 0;\n    get_sess_val = sess2;\n    if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl2,\n                                      &clientssl2, NULL, NULL))\n            || !TEST_true(SSL_set_session(clientssl2, sess1))\n            || !TEST_true(create_ssl_connection(serverssl2, clientssl2,\n                                                SSL_ERROR_NONE))\n            || !TEST_true(SSL_session_reused(clientssl2)))\n        goto end;\n    if (use_ext_cache) {\n        if (!TEST_int_eq(remove_called, 0))\n            goto end;\n        if (maxprot == TLS1_3_VERSION) {\n            if (!TEST_int_eq(new_called, 1)\n                    || !TEST_int_eq(get_called, 0))\n                goto end;\n        } else {\n            if (!TEST_int_eq(new_called, 0)\n                    || !TEST_int_eq(get_called, 1))\n                goto end;\n        }\n    }\n    testresult = 1;\n end:\n    SSL_free(serverssl1);\n    SSL_free(clientssl1);\n    SSL_free(serverssl2);\n    SSL_free(clientssl2);\n# ifndef OPENSSL_NO_TLS1_1\n    SSL_free(serverssl3);\n    SSL_free(clientssl3);\n# endif\n    SSL_SESSION_free(sess1);\n    SSL_SESSION_free(sess2);\n    SSL_CTX_free(sctx);\n    SSL_CTX_free(cctx);\n    return testresult;\n}', 'int create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,\n                          SSL **cssl, BIO *s_to_c_fbio, BIO *c_to_s_fbio)\n{\n    SSL *serverssl = NULL, *clientssl = NULL;\n    BIO *s_to_c_bio = NULL, *c_to_s_bio = NULL;\n    if (*sssl != NULL)\n        serverssl = *sssl;\n    else if (!TEST_ptr(serverssl = SSL_new(serverctx)))\n        goto error;\n    if (*cssl != NULL)\n        clientssl = *cssl;\n    else if (!TEST_ptr(clientssl = SSL_new(clientctx)))\n        goto error;\n    if (SSL_is_dtls(clientssl)) {\n        if (!TEST_ptr(s_to_c_bio = BIO_new(bio_s_mempacket_test()))\n                || !TEST_ptr(c_to_s_bio = BIO_new(bio_s_mempacket_test())))\n            goto error;\n    } else {\n        if (!TEST_ptr(s_to_c_bio = BIO_new(BIO_s_mem()))\n                || !TEST_ptr(c_to_s_bio = BIO_new(BIO_s_mem())))\n            goto error;\n    }\n    if (s_to_c_fbio != NULL\n            && !TEST_ptr(s_to_c_bio = BIO_push(s_to_c_fbio, s_to_c_bio)))\n        goto error;\n    if (c_to_s_fbio != NULL\n            && !TEST_ptr(c_to_s_bio = BIO_push(c_to_s_fbio, c_to_s_bio)))\n        goto error;\n    BIO_set_mem_eof_return(s_to_c_bio, -1);\n    BIO_set_mem_eof_return(c_to_s_bio, -1);\n    SSL_set_bio(serverssl, c_to_s_bio, s_to_c_bio);\n    BIO_up_ref(s_to_c_bio);\n    BIO_up_ref(c_to_s_bio);\n    SSL_set_bio(clientssl, s_to_c_bio, c_to_s_bio);\n    *sssl = serverssl;\n    *cssl = clientssl;\n    return 1;\n error:\n    SSL_free(serverssl);\n    SSL_free(clientssl);\n    BIO_free(s_to_c_bio);\n    BIO_free(c_to_s_bio);\n    BIO_free(s_to_c_fbio);\n    BIO_free(c_to_s_fbio);\n    return 0;\n}', 'SSL *SSL_new(SSL_CTX *ctx)\n{\n    SSL *s;\n    if (ctx == NULL) {\n        SSLerr(SSL_F_SSL_NEW, SSL_R_NULL_SSL_CTX);\n        return NULL;\n    }\n    if (ctx->method == NULL) {\n        SSLerr(SSL_F_SSL_NEW, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n        return NULL;\n    }\n    s = OPENSSL_zalloc(sizeof(*s));\n    if (s == NULL)\n        goto err;\n    s->references = 1;\n    s->lock = CRYPTO_THREAD_lock_new();\n    if (s->lock == NULL) {\n        OPENSSL_free(s);\n        s = NULL;\n        goto err;\n    }\n    RECORD_LAYER_init(&s->rlayer, s);\n    s->options = ctx->options;\n    s->dane.flags = ctx->dane.flags;\n    s->min_proto_version = ctx->min_proto_version;\n    s->max_proto_version = ctx->max_proto_version;\n    s->mode = ctx->mode;\n    s->max_cert_list = ctx->max_cert_list;\n    s->max_early_data = ctx->max_early_data;\n    s->recv_max_early_data = ctx->recv_max_early_data;\n    s->num_tickets = ctx->num_tickets;\n    s->pha_enabled = ctx->pha_enabled;\n    s->tls13_ciphersuites = sk_SSL_CIPHER_dup(ctx->tls13_ciphersuites);\n    if (s->tls13_ciphersuites == NULL)\n        goto err;\n    s->cert = ssl_cert_dup(ctx->cert);\n    if (s->cert == NULL)\n        goto err;\n    RECORD_LAYER_set_read_ahead(&s->rlayer, ctx->read_ahead);\n    s->msg_callback = ctx->msg_callback;\n    s->msg_callback_arg = ctx->msg_callback_arg;\n    s->verify_mode = ctx->verify_mode;\n    s->not_resumable_session_cb = ctx->not_resumable_session_cb;\n    s->record_padding_cb = ctx->record_padding_cb;\n    s->record_padding_arg = ctx->record_padding_arg;\n    s->block_padding = ctx->block_padding;\n    s->sid_ctx_length = ctx->sid_ctx_length;\n    if (!ossl_assert(s->sid_ctx_length <= sizeof(s->sid_ctx)))\n        goto err;\n    memcpy(&s->sid_ctx, &ctx->sid_ctx, sizeof(s->sid_ctx));\n    s->verify_callback = ctx->default_verify_callback;\n    s->generate_session_id = ctx->generate_session_id;\n    s->param = X509_VERIFY_PARAM_new();\n    if (s->param == NULL)\n        goto err;\n    X509_VERIFY_PARAM_inherit(s->param, ctx->param);\n    s->quiet_shutdown = ctx->quiet_shutdown;\n    s->ext.max_fragment_len_mode = ctx->ext.max_fragment_len_mode;\n    s->max_send_fragment = ctx->max_send_fragment;\n    s->split_send_fragment = ctx->split_send_fragment;\n    s->max_pipelines = ctx->max_pipelines;\n    if (s->max_pipelines > 1)\n        RECORD_LAYER_set_read_ahead(&s->rlayer, 1);\n    if (ctx->default_read_buf_len > 0)\n        SSL_set_default_read_buffer_len(s, ctx->default_read_buf_len);\n    SSL_CTX_up_ref(ctx);\n    s->ctx = ctx;\n    s->ext.debug_cb = 0;\n    s->ext.debug_arg = NULL;\n    s->ext.ticket_expected = 0;\n    s->ext.status_type = ctx->ext.status_type;\n    s->ext.status_expected = 0;\n    s->ext.ocsp.ids = NULL;\n    s->ext.ocsp.exts = NULL;\n    s->ext.ocsp.resp = NULL;\n    s->ext.ocsp.resp_len = 0;\n    SSL_CTX_up_ref(ctx);\n    s->session_ctx = ctx;\n#ifndef OPENSSL_NO_EC\n    if (ctx->ext.ecpointformats) {\n        s->ext.ecpointformats =\n            OPENSSL_memdup(ctx->ext.ecpointformats,\n                           ctx->ext.ecpointformats_len);\n        if (!s->ext.ecpointformats)\n            goto err;\n        s->ext.ecpointformats_len =\n            ctx->ext.ecpointformats_len;\n    }\n    if (ctx->ext.supportedgroups) {\n        s->ext.supportedgroups =\n            OPENSSL_memdup(ctx->ext.supportedgroups,\n                           ctx->ext.supportedgroups_len\n                                * sizeof(*ctx->ext.supportedgroups));\n        if (!s->ext.supportedgroups)\n            goto err;\n        s->ext.supportedgroups_len = ctx->ext.supportedgroups_len;\n    }\n#endif\n#ifndef OPENSSL_NO_NEXTPROTONEG\n    s->ext.npn = NULL;\n#endif\n    if (s->ctx->ext.alpn) {\n        s->ext.alpn = OPENSSL_malloc(s->ctx->ext.alpn_len);\n        if (s->ext.alpn == NULL)\n            goto err;\n        memcpy(s->ext.alpn, s->ctx->ext.alpn, s->ctx->ext.alpn_len);\n        s->ext.alpn_len = s->ctx->ext.alpn_len;\n    }\n    s->verified_chain = NULL;\n    s->verify_result = X509_V_OK;\n    s->default_passwd_callback = ctx->default_passwd_callback;\n    s->default_passwd_callback_userdata = ctx->default_passwd_callback_userdata;\n    s->method = ctx->method;\n    s->key_update = SSL_KEY_UPDATE_NONE;\n    s->allow_early_data_cb = ctx->allow_early_data_cb;\n    s->allow_early_data_cb_data = ctx->allow_early_data_cb_data;\n    if (!s->method->ssl_new(s))\n        goto err;\n    s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;\n    if (!SSL_clear(s))\n        goto err;\n    if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data))\n        goto err;\n#ifndef OPENSSL_NO_PSK\n    s->psk_client_callback = ctx->psk_client_callback;\n    s->psk_server_callback = ctx->psk_server_callback;\n#endif\n    s->psk_find_session_cb = ctx->psk_find_session_cb;\n    s->psk_use_session_cb = ctx->psk_use_session_cb;\n    s->async_cb = ctx->async_cb;\n    s->async_cb_arg = ctx->async_cb_arg;\n    s->job = NULL;\n#ifndef OPENSSL_NO_CT\n    if (!SSL_set_ct_validation_callback(s, ctx->ct_validation_callback,\n                                        ctx->ct_validation_callback_arg))\n        goto err;\n#endif\n    return s;\n err:\n    SSL_free(s);\n    SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n    return NULL;\n}', 'int SSL_set_session(SSL *s, SSL_SESSION *session)\n{\n    ssl_clear_bad_session(s);\n    if (s->ctx->method != s->method) {\n        if (!SSL_set_ssl_method(s, s->ctx->method))\n            return 0;\n    }\n    if (session != NULL) {\n        SSL_SESSION_up_ref(session);\n        s->verify_result = session->verify_result;\n    }\n    SSL_SESSION_free(s->session);\n    s->session = session;\n    return 1;\n}', 'int ssl_clear_bad_session(SSL *s)\n{\n    if ((s->session != NULL) &&\n        !(s->shutdown & SSL_SENT_SHUTDOWN) &&\n        !(SSL_in_init(s) || SSL_in_before(s))) {\n        SSL_CTX_remove_session(s->session_ctx, s->session);\n        return 1;\n    } else\n        return 0;\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    RECORD_LAYER_release(&s->rlayer);\n    ssl_free_wbio_buffer(s);\n    BIO_free_all(s->wbio);\n    s->wbio = NULL;\n    BIO_free_all(s->rbio);\n    s->rbio = NULL;\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    sk_SSL_CIPHER_free(s->tls13_ciphersuites);\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_NAME_pop_free(s->client_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    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    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    sk_SSL_CIPHER_free(a->tls13_ciphersuites);\n    ssl_cert_free(a->cert);\n    sk_X509_NAME_pop_free(a->ca_names, X509_NAME_free);\n    sk_X509_NAME_pop_free(a->client_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    OPENSSL_secure_free(a->ext.secure);\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}']