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


test/asynciotest.c:294:10: Call
292.   
293.       /* BIOs get freed on error */
294.       if (!TEST_true(create_ssl_objects(serverctx, clientctx, &serverssl,
                ^
295.                                         &clientssl, s_to_c_fbio, c_to_s_fbio))
296.               || !TEST_true(create_ssl_connection(serverssl, clientssl,

test/ssltestlib.c:580:21: Call
  578.   
  579.       if (*sssl == NULL)
  580.           serverssl = SSL_new(serverctx);
                             ^
  581.       else
  582.           serverssl = *sssl;

ssl/ssl_lib.c:521:1: Parameter `ctx->sessions->num_nodes`
    519.   }
    520.   
    521. > SSL *SSL_new(SSL_CTX *ctx)
    522.   {
    523.       SSL *s;

test/asynciotest.c:351:5: Call
349.   
350.       /* Also frees the BIOs */
351.       SSL_free(clientssl);
           ^
352.       SSL_free(serverssl);
353.       clientssl = serverssl = NULL;

ssl/ssl_lib.c:963:1: Parameter `s->ctx->sessions->num_nodes`
  961.   }
  962.   
  963. > void SSL_free(SSL *s)
  964.   {
  965.       int i;

ssl/ssl_lib.c:1030:5: Call
  1028.       RECORD_LAYER_release(&s->rlayer);
  1029.   
  1030.       SSL_CTX_free(s->ctx);
              ^
  1031.   
  1032.       ASYNC_WAIT_CTX_free(s->waitctx);

ssl/ssl_lib.c:2780:1: Parameter `a->sessions->num_nodes`
    2778.   }
    2779.   
    2780. > void SSL_CTX_free(SSL_CTX *a)
    2781.   {
    2782.       int i;

ssl/ssl_lib.c:2806:9: Call
    2804.        */
    2805.       if (a->sessions != NULL)
    2806.           SSL_CTX_flush_sessions(a, 0);
                    ^
    2807.   
    2808.       CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, a, &a->ex_data);

ssl/ssl_sess.c:1021:1: Parameter `s->sessions->num_nodes`
      1019.   IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM);
      1020.   
      1021. > void SSL_CTX_flush_sessions(SSL_CTX *s, long t)
      1022.   {
      1023.       unsigned long i;

ssl/ssl_sess.c:1034:5: Call
      1032.       i = lh_SSL_SESSION_get_down_load(s->sessions);
      1033.       lh_SSL_SESSION_set_down_load(s->sessions, 0);
      1034.       lh_SSL_SESSION_doall_TIMEOUT_PARAM(tp.cache, timeout_cb, &tp);
                  ^
      1035.       lh_SSL_SESSION_set_down_load(s->sessions, i);
      1036.       CRYPTO_THREAD_unlock(s->lock);

ssl/ssl_sess.c:1019:1: Parameter `lh->num_nodes`
        1017.   }
        1018.   
        1019. > IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM);
        1020.   
        1021.   void SSL_CTX_flush_sessions(SSL_CTX *s, long t)

ssl/ssl_sess.c:1019:1: Call
        1017.   }
        1018.   
        1019. > IMPLEMENT_LHASH_DOALL_ARG(SSL_SESSION, TIMEOUT_PARAM);
        1020.   
        1021.   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_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 test_asyncio(int test)\n{\n    SSL_CTX *serverctx = NULL, *clientctx = NULL;\n    SSL *serverssl = NULL, *clientssl = NULL;\n    BIO *s_to_c_fbio = NULL, *c_to_s_fbio = NULL;\n    int testresult = 0, ret;\n    size_t i, j;\n    const char testdata[] = "Test data";\n    char buf[sizeof(testdata)];\n    if (!TEST_true(create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(),\n                             &serverctx, &clientctx, cert, privkey)))\n        goto end;\n    if (test == 1)\n        fragment = 1;\n    s_to_c_fbio = BIO_new(bio_f_async_filter());\n    c_to_s_fbio = BIO_new(bio_f_async_filter());\n    if (!TEST_ptr(s_to_c_fbio)\n            || !TEST_ptr(c_to_s_fbio)) {\n        BIO_free(s_to_c_fbio);\n        BIO_free(c_to_s_fbio);\n        goto end;\n    }\n    if (!TEST_true(create_ssl_objects(serverctx, clientctx, &serverssl,\n                                      &clientssl, s_to_c_fbio, c_to_s_fbio))\n            || !TEST_true(create_ssl_connection(serverssl, clientssl,\n                          SSL_ERROR_NONE)))\n        goto end;\n    for (j = 0; j < 2; j++) {\n        int len;\n        for (ret = -1, i = 0, len = 0; len != sizeof(testdata) && i < 2;\n            i++) {\n            ret = SSL_write(clientssl, testdata + len,\n                sizeof(testdata) - len);\n            if (ret > 0) {\n                len += ret;\n            } else {\n                int ssl_error = SSL_get_error(clientssl, ret);\n                if (!TEST_false(ssl_error == SSL_ERROR_SYSCALL ||\n                                ssl_error == SSL_ERROR_SSL))\n                    goto end;\n            }\n        }\n        if (!TEST_size_t_eq(len, sizeof(testdata)))\n            goto end;\n        for (ret = -1, i = 0, len = 0; len != sizeof(testdata) &&\n                i < MAX_ATTEMPTS; i++) {\n            ret = SSL_read(serverssl, buf + len, sizeof(buf) - len);\n            if (ret > 0) {\n                len += ret;\n            } else {\n                int ssl_error = SSL_get_error(serverssl, ret);\n                if (!TEST_false(ssl_error == SSL_ERROR_SYSCALL ||\n                                ssl_error == SSL_ERROR_SSL))\n                    goto end;\n            }\n        }\n        if (!TEST_mem_eq(testdata, sizeof(testdata), buf, len))\n            goto end;\n    }\n    SSL_free(clientssl);\n    SSL_free(serverssl);\n    clientssl = serverssl = NULL;\n    testresult = 1;\n end:\n    SSL_free(clientssl);\n    SSL_free(serverssl);\n    SSL_CTX_free(clientctx);\n    SSL_CTX_free(serverctx);\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, *clientssl;\n    BIO *s_to_c_bio = NULL, *c_to_s_bio = NULL;\n    if (*sssl == NULL)\n        serverssl = SSL_new(serverctx);\n    else\n        serverssl = *sssl;\n    if (*cssl == NULL)\n        clientssl = SSL_new(clientctx);\n    else\n        clientssl = *cssl;\n    if (serverssl == NULL || clientssl == NULL) {\n        printf("Failed to create SSL object\\n");\n        goto error;\n    }\n    if (SSL_is_dtls(clientssl)) {\n        s_to_c_bio = BIO_new(bio_s_mempacket_test());\n        c_to_s_bio = BIO_new(bio_s_mempacket_test());\n    } else {\n        s_to_c_bio = BIO_new(BIO_s_mem());\n        c_to_s_bio = BIO_new(BIO_s_mem());\n    }\n    if (s_to_c_bio == NULL || c_to_s_bio == NULL) {\n        printf("Failed to create mem BIOs\\n");\n        goto error;\n    }\n    if (s_to_c_fbio != NULL)\n        s_to_c_bio = BIO_push(s_to_c_fbio, s_to_c_bio);\n    if (c_to_s_fbio != NULL)\n        c_to_s_bio = BIO_push(c_to_s_fbio, c_to_s_bio);\n    if (s_to_c_bio == NULL || c_to_s_bio == NULL) {\n        printf("Failed to create chained BIOs\\n");\n        goto error;\n    }\n    BIO_set_mem_eof_return(s_to_c_bio, -1);\n    BIO_set_mem_eof_return(c_to_s_bio, -1);\n    BIO_up_ref(s_to_c_bio);\n    BIO_up_ref(c_to_s_bio);\n    SSL_set_bio(serverssl, c_to_s_bio, s_to_c_bio);\n    SSL_set_bio(clientssl, s_to_c_bio, c_to_s_bio);\n    s_to_c_bio = c_to_s_bio = NULL;\n    s_to_c_fbio = c_to_s_fbio = NULL;\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->lock = CRYPTO_THREAD_lock_new();\n    if (s->lock == NULL) {\n        SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n        OPENSSL_free(s);\n        return NULL;\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->references = 1;\n    s->max_early_data = ctx->max_early_data;\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->sid_ctx_length = ctx->sid_ctx_length;\n    OPENSSL_assert(s->sid_ctx_length <= sizeof s->sid_ctx);\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->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        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    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->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}', '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    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    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    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}']