test/sslapitest.c:197: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned64 by call to `SSL_set_session`.
Showing all 17 steps of the trace


test/sslapitest.c:176:10: Call
174.       }
175.   
176.       if (!create_ssl_connection(sctx, cctx, &serverssl2, &clientssl2, NULL,
                ^
177.                                  NULL)) {
178.           printf("Unable to create second SSL connection\n");

test/ssltestlib.c:64:21: Call
  62.   
  63.       if (*sssl == NULL)
  64.           serverssl = SSL_new(serverctx);
                            ^
  65.       else
  66.           serverssl = *sssl;

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

test/sslapitest.c:197:10: Call
195.        * SSL_set_session() documentation.
196.        */
197.       if (!SSL_set_session(clientssl2, sess1)) {
                ^
198.           printf("Unexpected failure setting session\n");
199.           goto end;

ssl/ssl_sess.c:777:1: Parameter `s->initial_ctx->sessions->num_items`
  775.   }
  776.   
  777. > int SSL_set_session(SSL *s, SSL_SESSION *session)
  778.   {
  779.       ssl_clear_bad_session(s);

ssl/ssl_sess.c:779:5: Call
  777.   int SSL_set_session(SSL *s, SSL_SESSION *session)
  778.   {
  779.       ssl_clear_bad_session(s);
             ^
  780.       if (s->ctx->method != s->method) {
  781.           if (!SSL_set_ssl_method(s, s->ctx->method))

ssl/ssl_sess.c:986:1: Parameter `s->initial_ctx->sessions->num_items`
    984.   }
    985.   
    986. > int ssl_clear_bad_session(SSL *s)
    987.   {
    988.       if ((s->session != NULL) &&

ssl/ssl_sess.c:991:9: Call
    989.           !(s->shutdown & SSL_SENT_SHUTDOWN) &&
    990.           !(SSL_in_init(s) || SSL_in_before(s))) {
    991.           SSL_CTX_remove_session(s->session_ctx, s->session);
                   ^
    992.           return (1);
    993.       } else

ssl/ssl_sess.c:693:1: Parameter `ctx->sessions->num_items`
      691.   }
      692.   
      693. > int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
      694.   {
      695.       return remove_session_lock(ctx, c, 1);

ssl/ssl_sess.c:695:12: Call
      693.   int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
      694.   {
      695.       return remove_session_lock(ctx, c, 1);
                        ^
      696.   }
      697.   

ssl/ssl_sess.c:698:1: Parameter `ctx->sessions->num_items`
        696.   }
        697.   
        698. > static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
        699.   {
        700.       SSL_SESSION *r;

ssl/ssl_sess.c:708:17: Call
        706.           if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {
        707.               ret = 1;
        708.               r = lh_SSL_SESSION_delete(ctx->sessions, c);
                               ^
        709.               SSL_SESSION_list_remove(ctx, c);
        710.           }

ssl/ssl_locl.h:581:1: Parameter `lh->num_items`
          579.   };
          580.   
          581. > DEFINE_LHASH_OF(SSL_SESSION);
          582.   /* Needed in ssl_cert.c */
          583.   DEFINE_LHASH_OF(X509_NAME);

ssl/ssl_locl.h:581:1: Call
          579.   };
          580.   
          581. > DEFINE_LHASH_OF(SSL_SESSION);
          582.   /* Needed in ssl_cert.c */
          583.   DEFINE_LHASH_OF(X509_NAME);

crypto/lhash/lhash.c:103:1: <LHS trace>
101.   }
102.   
103. > void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)
104.   {
105.       unsigned long hash;

crypto/lhash/lhash.c:103:1: Parameter `lh->num_items`
            101.   }
            102.   
            103. > void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)
            104.   {
            105.       unsigned long hash;

crypto/lhash/lhash.c:123:5: Binary operation: ([0, +oo] - 1):unsigned64 by call to `SSL_set_session` 
            121.       }
            122.   
            123.       lh->num_items--;
                       ^
            124.       if ((lh->num_nodes > MIN_NODES) &&
            125.           (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))

void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)
{
    unsigned long hash;
    OPENSSL_LH_NODE *nn, **rn;
    void *ret;
    lh->error = 0;
    rn = getrn(lh, data, &hash);
    if (*rn == NULL) {
        lh->num_no_delete++;
        return (NULL);
    } else {
        nn = *rn;
        *rn = nn->next;
        ret = nn->data;
        OPENSSL_free(nn);
        lh->num_delete++;
    }
    lh->num_items--;
    if ((lh->num_nodes > MIN_NODES) &&
        (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))
        contract(lh);
    return (ret);
}
['static int execute_test_session(SSL_SESSION_TEST_FIXTURE fix)\n{\n    SSL_CTX *sctx = NULL, *cctx = NULL;\n    SSL *serverssl1 = NULL, *clientssl1 = NULL;\n    SSL *serverssl2 = NULL, *clientssl2 = NULL;\n    SSL *serverssl3 = NULL, *clientssl3 = NULL;\n    SSL_SESSION *sess1 = NULL, *sess2 = NULL;\n    int testresult = 0;\n    if (!create_ssl_ctx_pair(TLS_server_method(), TLS_client_method(), &sctx,\n                             &cctx, cert, privkey)) {\n        printf("Unable to create SSL_CTX pair\\n");\n        return 0;\n    }\n#ifndef OPENSSL_NO_TLS1_2\n    SSL_CTX_set_min_proto_version(cctx, TLS1_2_VERSION);\n#endif\n    if (fix.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 (fix.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 (!create_ssl_connection(sctx, cctx, &serverssl1, &clientssl1, NULL,\n                               NULL)) {\n        printf("Unable to create SSL connection\\n");\n        goto end;\n    }\n    sess1 = SSL_get1_session(clientssl1);\n    if (sess1 == NULL) {\n        printf("Unexpected NULL session\\n");\n        goto end;\n    }\n    if (fix.use_int_cache && SSL_CTX_add_session(cctx, sess1)) {\n        printf("Unexpected success adding session to cache\\n");\n        goto end;\n    }\n    if (fix.use_ext_cache && (new_called != 1 || remove_called != 0)) {\n        printf("Session not added to cache\\n");\n        goto end;\n    }\n    if (!create_ssl_connection(sctx, cctx, &serverssl2, &clientssl2, NULL,\n                               NULL)) {\n        printf("Unable to create second SSL connection\\n");\n        goto end;\n    }\n    sess2 = SSL_get1_session(clientssl2);\n    if (sess2 == NULL) {\n        printf("Unexpected NULL session from clientssl2\\n");\n        goto end;\n    }\n    if (fix.use_ext_cache && (new_called != 2 || remove_called != 0)) {\n        printf("Remove session callback unexpectedly called\\n");\n        goto end;\n    }\n    if (!SSL_set_session(clientssl2, sess1)) {\n        printf("Unexpected failure setting session\\n");\n        goto end;\n    }\n    if (fix.use_ext_cache && (new_called != 2 || remove_called != 1)) {\n        printf("Failed to call callback to remove session\\n");\n        goto end;\n    }\n    if (SSL_get_session(clientssl2) != sess1) {\n        printf("Unexpected session found\\n");\n        goto end;\n    }\n    if (fix.use_int_cache) {\n        if (!SSL_CTX_add_session(cctx, sess2)) {\n            printf("Unexpected failure adding session to cache\\n");\n            goto end;\n        }\n        if (!SSL_CTX_remove_session(cctx, sess2)) {\n            printf("Unexpected failure removing session from cache\\n");\n            goto end;\n        }\n        if (fix.use_ext_cache)\n            remove_called--;\n    }\n    if (SSL_CTX_remove_session(cctx, sess2)) {\n        printf("Unexpected success removing session from cache\\n");\n        goto end;\n    }\n    if (fix.use_ext_cache && (new_called != 2 || remove_called != 2)) {\n        printf("Failed to call callback to remove session #2\\n");\n        goto end;\n    }\n#ifndef OPENSSL_NO_TLS1_1\n    SSL_CTX_set_max_proto_version(sctx, TLS1_1_VERSION);\n    clientssl3 = SSL_new(cctx);\n    if (clientssl3 == NULL) {\n        printf("Malloc failure\\n");\n        goto end;\n    }\n    if (!SSL_set_session(clientssl3, sess1)) {\n        printf("Unable to set session for third connection\\n");\n        goto end;\n    }\n    if (create_ssl_connection(sctx, cctx, &serverssl3, &clientssl3, NULL,\n                               NULL)) {\n        printf("Unexpected success creating SSL connection\\n");\n        goto end;\n    }\n    if (fix.use_ext_cache && (new_called != 2 || remove_called != 3)) {\n        printf("Failed to call callback to remove session #2\\n");\n        goto end;\n    }\n    if (fix.use_int_cache && !SSL_CTX_add_session(cctx, sess2)) {\n        printf("Unexpected failure adding session to cache #2\\n");\n        goto end;\n    }\n#endif\n    testresult = 1;\n end:\n    SSL_free(serverssl1);\n    SSL_free(clientssl1);\n    SSL_free(serverssl2);\n    SSL_free(clientssl2);\n    SSL_free(serverssl3);\n    SSL_free(clientssl3);\n    SSL_SESSION_free(sess1);\n    SSL_SESSION_free(sess2);\n    if (new_called >= 1)\n        SSL_SESSION_free(sess1);\n    if (new_called >= 2)\n        SSL_SESSION_free(sess2);\n    SSL_CTX_free(sctx);\n    SSL_CTX_free(cctx);\n    return testresult;\n}', 'int create_ssl_connection(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,\n                          SSL **cssl, BIO *s_to_c_fbio, BIO *c_to_s_fbio)\n{\n    int retc = -1, rets = -1, err, abortctr = 0;\n    int clienterr = 0, servererr = 0;\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    s_to_c_bio = BIO_new(BIO_s_mem());\n    c_to_s_bio = BIO_new(BIO_s_mem());\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    do {\n        err = SSL_ERROR_WANT_WRITE;\n        while (!clienterr && retc <= 0 && err == SSL_ERROR_WANT_WRITE) {\n            retc = SSL_connect(clientssl);\n            if (retc <= 0)\n                err = SSL_get_error(clientssl, retc);\n        }\n        if (!clienterr && retc <= 0 && err != SSL_ERROR_WANT_READ) {\n            printf("SSL_connect() failed %d, %d\\n", retc, err);\n            clienterr = 1;\n        }\n        err = SSL_ERROR_WANT_WRITE;\n        while (!servererr && rets <= 0 && err == SSL_ERROR_WANT_WRITE) {\n            rets = SSL_accept(serverssl);\n            if (rets <= 0)\n                err = SSL_get_error(serverssl, rets);\n        }\n        if (!servererr && rets <= 0 && err != SSL_ERROR_WANT_READ) {\n            printf("SSL_accept() failed %d, %d\\n", retc, err);\n            servererr = 1;\n        }\n        if (clienterr && servererr)\n            goto error;\n        if (++abortctr == MAXLOOPS) {\n            printf("No progress made\\n");\n            goto error;\n        }\n    } while (retc <=0 || rets <= 0);\n    *sssl = serverssl;\n    *cssl = clientssl;\n    return 1;\n error:\n    if (*sssl == NULL) {\n        SSL_free(serverssl);\n        BIO_free(s_to_c_bio);\n        BIO_free(s_to_c_fbio);\n    }\n    if (*cssl == NULL) {\n        SSL_free(clientssl);\n        BIO_free(c_to_s_bio);\n        BIO_free(c_to_s_fbio);\n    }\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->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->tlsext_debug_cb = 0;\n    s->tlsext_debug_arg = NULL;\n    s->tlsext_ticket_expected = 0;\n    s->tlsext_status_type = ctx->tlsext_status_type;\n    s->tlsext_status_expected = 0;\n    s->tlsext_ocsp_ids = NULL;\n    s->tlsext_ocsp_exts = NULL;\n    s->tlsext_ocsp_resp = NULL;\n    s->tlsext_ocsp_resplen = -1;\n    SSL_CTX_up_ref(ctx);\n    s->initial_ctx = ctx;\n# ifndef OPENSSL_NO_EC\n    if (ctx->tlsext_ecpointformatlist) {\n        s->tlsext_ecpointformatlist =\n            OPENSSL_memdup(ctx->tlsext_ecpointformatlist,\n                           ctx->tlsext_ecpointformatlist_length);\n        if (!s->tlsext_ecpointformatlist)\n            goto err;\n        s->tlsext_ecpointformatlist_length =\n            ctx->tlsext_ecpointformatlist_length;\n    }\n    if (ctx->tlsext_ellipticcurvelist) {\n        s->tlsext_ellipticcurvelist =\n            OPENSSL_memdup(ctx->tlsext_ellipticcurvelist,\n                           ctx->tlsext_ellipticcurvelist_length);\n        if (!s->tlsext_ellipticcurvelist)\n            goto err;\n        s->tlsext_ellipticcurvelist_length =\n            ctx->tlsext_ellipticcurvelist_length;\n    }\n# endif\n# ifndef OPENSSL_NO_NEXTPROTONEG\n    s->next_proto_negotiated = NULL;\n# endif\n    if (s->ctx->alpn_client_proto_list) {\n        s->alpn_client_proto_list =\n            OPENSSL_malloc(s->ctx->alpn_client_proto_list_len);\n        if (s->alpn_client_proto_list == NULL)\n            goto err;\n        memcpy(s->alpn_client_proto_list, s->ctx->alpn_client_proto_list,\n               s->ctx->alpn_client_proto_list_len);\n        s->alpn_client_proto_list_len = s->ctx->alpn_client_proto_list_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    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}', '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}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n    return remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n{\n    SSL_SESSION *r;\n    int ret = 0;\n    if ((c != NULL) && (c->session_id_length != 0)) {\n        if (lck)\n            CRYPTO_THREAD_write_lock(ctx->lock);\n        if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {\n            ret = 1;\n            r = lh_SSL_SESSION_delete(ctx->sessions, c);\n            SSL_SESSION_list_remove(ctx, c);\n        }\n        c->not_resumable = 1;\n        if (lck)\n            CRYPTO_THREAD_unlock(ctx->lock);\n        if (ret)\n            SSL_SESSION_free(r);\n        if (ctx->remove_session_cb != NULL)\n            ctx->remove_session_cb(ctx, c);\n    } else\n        ret = 0;\n    return (ret);\n}', 'DEFINE_LHASH_OF(SSL_SESSION)', 'void *OPENSSL_LH_delete(OPENSSL_LHASH *lh, const void *data)\n{\n    unsigned long hash;\n    OPENSSL_LH_NODE *nn, **rn;\n    void *ret;\n    lh->error = 0;\n    rn = getrn(lh, data, &hash);\n    if (*rn == NULL) {\n        lh->num_no_delete++;\n        return (NULL);\n    } else {\n        nn = *rn;\n        *rn = nn->next;\n        ret = nn->data;\n        OPENSSL_free(nn);\n        lh->num_delete++;\n    }\n    lh->num_items--;\n    if ((lh->num_nodes > MIN_NODES) &&\n        (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))\n        contract(lh);\n    return (ret);\n}']