apps/s_client.c:1393: error: INTEGER_OVERFLOW_L1
  (0 - 1):unsigned64 by call to `SSL_new`.
Showing all 24 steps of the trace


apps/s_client.c:1385:9: Call
1383.           SSL_CTX_set_srp_cb_arg(ctx, &srp_arg);
1384.           SSL_CTX_set_srp_client_pwd_callback(ctx, ssl_give_srp_client_pwd_cb);
1385.           SSL_CTX_set_srp_strength(ctx, srp_arg.strength);
                ^
1386.           if (c_msg || c_debug || srp_arg.amp == 0)
1387.               SSL_CTX_set_srp_verify_param_callback(ctx,

ssl/tls_srp.c:514:12: Call
  512.   int SSL_CTX_set_srp_strength(SSL_CTX *ctx, int strength)
  513.   {
  514.       return tls1_ctx_ctrl(ctx, SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH, strength,
                    ^
  515.                            NULL);
  516.   }

ssl/s3_lib.c:3793:24: Call
    3791.                   return 0;
    3792.               }
    3793.               if ((new = DHparams_dup(dh)) == NULL) {
                                   ^
    3794.                   SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_DH_LIB);
    3795.                   return 0;

crypto/dh/dh_ameth.c:509:11: Call
      507.   {
      508.       DH *ret;
      509.       ret = DH_new();
                       ^
      510.       if (!ret)
      511.           return NULL;

crypto/dh/dh_lib.c:107:12: Call
        105.   DH *DH_new(void)
        106.   {
        107.       return DH_new_method(NULL);
                          ^
        108.   }
        109.   

crypto/dh/dh_lib.c:130:23: Call
          128.           ret->engine = engine;
          129.       } else
          130.           ret->engine = ENGINE_get_default_DH();
                                       ^
          131.       if (ret->engine) {
          132.           ret->meth = ENGINE_get_DH(ret->engine);

crypto/engine/tb_dh.c:110:12: Call
            108.   ENGINE *ENGINE_get_default_DH(void)
            109.   {
            110.       return engine_table_select(&dh_table, dummy_nid);
                              ^
            111.   }
            112.   

crypto/engine/eng_table.c:264:10: Call
              262.        * operations. But don't worry about a fprintf(stderr).
              263.        */
              264.       if (!int_table_check(table, 0))
                              ^
              265.           goto end;
              266.       tmplate.nid = nid;

crypto/engine/eng_table.c:122:15: Call
                120.       if (!create)
                121.           return 0;
                122.       if ((lh = lh_ENGINE_PILE_new()) == NULL)
                                     ^
                123.           return 0;
                124.       *t = (ENGINE_TABLE *)lh;

crypto/lhash/lhash.c:134:5: Assignment
                  132.       ret->up_load = UP_LOAD;
                  133.       ret->down_load = DOWN_LOAD;
                  134.       ret->num_items = 0;
                             ^
                  135.   
                  136.       ret->num_expands = 0;

apps/s_client.c:1393:11: Call
1391.   #endif
1392.   
1393.       con = SSL_new(ctx);
                  ^
1394.       if (sess_in) {
1395.           SSL_SESSION *sess;

ssl/ssl_lib.c:265:1: Parameter `ctx->sessions->num_items`
  263.   }
  264.   
  265. > SSL *SSL_new(SSL_CTX *ctx)
  266.   {
  267.       SSL *s;

ssl/ssl_lib.c:381:9: Call
  379.       s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;
  380.   
  381.       if(!SSL_clear(s))
                 ^
  382.           goto err;
  383.   

ssl/ssl_lib.c:190:1: Parameter `s->ctx->sessions->num_items`
    188.   };
    189.   
    190. > int SSL_clear(SSL *s)
    191.   {
    192.   

ssl/ssl_lib.c:198:9: Call
    196.       }
    197.   
    198.       if (ssl_clear_bad_session(s)) {
                   ^
    199.           SSL_SESSION_free(s->session);
    200.           s->session = NULL;

ssl/ssl_sess.c:1010:1: Parameter `s->ctx->sessions->num_items`
      1008.   }
      1009.   
      1010. > int ssl_clear_bad_session(SSL *s)
      1011.   {
      1012.       if ((s->session != NULL) &&

ssl/ssl_sess.c:1015:9: Call
      1013.           !(s->shutdown & SSL_SENT_SHUTDOWN) &&
      1014.           !(SSL_in_init(s) || SSL_in_before(s))) {
      1015.           SSL_CTX_remove_session(s->ctx, s->session);
                      ^
      1016.           return (1);
      1017.       } else

ssl/ssl_sess.c:675:1: Parameter `ctx->sessions->num_items`
        673.   }
        674.   
        675. > int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
        676.   {
        677.       return remove_session_lock(ctx, c, 1);

ssl/ssl_sess.c:677:12: Call
        675.   int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
        676.   {
        677.       return remove_session_lock(ctx, c, 1);
                          ^
        678.   }
        679.   

ssl/ssl_sess.c:680:1: Parameter `ctx->sessions->num_items`
          678.   }
          679.   
          680. > static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
          681.   {
          682.       SSL_SESSION *r;

ssl/ssl_sess.c:690:17: Call
          688.           if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {
          689.               ret = 1;
          690.               r = lh_SSL_SESSION_delete(ctx->sessions, c);
                                 ^
          691.               SSL_SESSION_list_remove(ctx, c);
          692.           }

crypto/lhash/lhash.c:211:1: <LHS trace>
209.   }
210.   
211. > void *lh_delete(_LHASH *lh, const void *data)
212.   {
213.       unsigned long hash;

crypto/lhash/lhash.c:211:1: Parameter `lh->num_items`
            209.   }
            210.   
            211. > void *lh_delete(_LHASH *lh, const void *data)
            212.   {
            213.       unsigned long hash;

crypto/lhash/lhash.c:231:5: Binary operation: (0 - 1):unsigned64 by call to `SSL_new` 
            229.       }
            230.   
            231.       lh->num_items--;
                       ^
            232.       if ((lh->num_nodes > MIN_NODES) &&
            233.           (lh->down_load >= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)))

void *lh_delete(_LHASH *lh, const void *data)
{
    unsigned long hash;
    LHASH_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);
}
['int MAIN(int argc, char **argv)\n{\n    int build_chain = 0;\n    SSL *con = NULL;\n#ifndef OPENSSL_NO_KRB5\n    KSSL_CTX *kctx;\n#endif\n    int s, k, width, state = 0;\n    char *cbuf = NULL, *sbuf = NULL, *mbuf = NULL;\n    int cbuf_len, cbuf_off;\n    int sbuf_len, sbuf_off;\n    fd_set readfds, writefds;\n    short port = PORT;\n    int full_log = 1;\n    char *host = SSL_HOST_NAME;\n    const char *unix_path = NULL;\n    char *xmpphost = NULL;\n    char *cert_file = NULL, *key_file = NULL, *chain_file = NULL;\n    int cert_format = FORMAT_PEM, key_format = FORMAT_PEM;\n    char *passarg = NULL, *pass = NULL;\n    X509 *cert = NULL;\n    EVP_PKEY *key = NULL;\n    STACK_OF(X509) *chain = NULL;\n    char *CApath = NULL, *CAfile = NULL;\n    char *chCApath = NULL, *chCAfile = NULL;\n    char *vfyCApath = NULL, *vfyCAfile = NULL;\n    int reconnect = 0, badop = 0, verify = SSL_VERIFY_NONE;\n    int crlf = 0;\n    int write_tty, read_tty, write_ssl, read_ssl, tty_on, ssl_pending;\n    SSL_CTX *ctx = NULL;\n    int ret = 1, in_init = 1, i, nbio_test = 0;\n    int starttls_proto = PROTO_OFF;\n    int prexit = 0;\n    X509_VERIFY_PARAM *vpm = NULL;\n    int badarg = 0;\n    const SSL_METHOD *meth = NULL;\n    int socket_type = SOCK_STREAM;\n    BIO *sbio;\n    char *inrand = NULL;\n    int mbuf_len = 0;\n    struct timeval timeout, *timeoutp;\n#ifndef OPENSSL_NO_ENGINE\n    char *engine_id = NULL;\n    char *ssl_client_engine_id = NULL;\n    ENGINE *ssl_client_engine = NULL;\n#endif\n    ENGINE *e = NULL;\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE)\n    struct timeval tv;\n#endif\n#ifndef OPENSSL_NO_TLSEXT\n    char *servername = NULL;\n    tlsextctx tlsextcbp = { NULL, 0 };\n# ifndef OPENSSL_NO_NEXTPROTONEG\n    const char *next_proto_neg_in = NULL;\n# endif\n    const char *alpn_in = NULL;\n# define MAX_SI_TYPES 100\n    unsigned short serverinfo_types[MAX_SI_TYPES];\n    int serverinfo_types_count = 0;\n#endif\n    char *sess_in = NULL;\n    char *sess_out = NULL;\n    struct sockaddr peer;\n    int peerlen = sizeof(peer);\n    int fallback_scsv = 0;\n    int enable_timeouts = 0;\n    long socket_mtu = 0;\n#ifndef OPENSSL_NO_JPAKE\n    static char *jpake_secret = NULL;\n# define no_jpake !jpake_secret\n#else\n# define no_jpake 1\n#endif\n#ifndef OPENSSL_NO_SRP\n    char *srppass = NULL;\n    int srp_lateuser = 0;\n    SRP_ARG srp_arg = { NULL, NULL, 0, 0, 0, 1024 };\n#endif\n    SSL_EXCERT *exc = NULL;\n    SSL_CONF_CTX *cctx = NULL;\n    STACK_OF(OPENSSL_STRING) *ssl_args = NULL;\n    char *crl_file = NULL;\n    int crl_format = FORMAT_PEM;\n    int crl_download = 0;\n    STACK_OF(X509_CRL) *crls = NULL;\n    int sdebug = 0;\n    meth = SSLv23_client_method();\n    apps_startup();\n    c_Pause = 0;\n    c_quiet = 0;\n    c_ign_eof = 0;\n    c_debug = 0;\n    c_msg = 0;\n    c_showcerts = 0;\n    if (bio_err == NULL)\n        bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);\n    if (!load_config(bio_err, NULL))\n        goto end;\n    cctx = SSL_CONF_CTX_new();\n    if (!cctx)\n        goto end;\n    SSL_CONF_CTX_set_flags(cctx, SSL_CONF_FLAG_CLIENT);\n    SSL_CONF_CTX_set_flags(cctx, SSL_CONF_FLAG_CMDLINE);\n    if (((cbuf = OPENSSL_malloc(BUFSIZZ)) == NULL) ||\n        ((sbuf = OPENSSL_malloc(BUFSIZZ)) == NULL) ||\n        ((mbuf = OPENSSL_malloc(BUFSIZZ)) == NULL)) {\n        BIO_printf(bio_err, "out of memory\\n");\n        goto end;\n    }\n    verify_depth = 0;\n    verify_error = X509_V_OK;\n#ifdef FIONBIO\n    c_nbio = 0;\n#endif\n    argc--;\n    argv++;\n    while (argc >= 1) {\n        if (strcmp(*argv, "-host") == 0) {\n            if (--argc < 1)\n                goto bad;\n            host = *(++argv);\n        } else if (strcmp(*argv, "-port") == 0) {\n            if (--argc < 1)\n                goto bad;\n            port = atoi(*(++argv));\n            if (port == 0)\n                goto bad;\n        } else if (strcmp(*argv, "-connect") == 0) {\n            if (--argc < 1)\n                goto bad;\n            if (!extract_host_port(*(++argv), &host, NULL, &port))\n                goto bad;\n        } else if (strcmp(*argv, "-unix") == 0) {\n            if (--argc < 1)\n                goto bad;\n            unix_path = *(++argv);\n        } else if (strcmp(*argv, "-xmpphost") == 0) {\n            if (--argc < 1)\n                goto bad;\n            xmpphost = *(++argv);\n        } else if (strcmp(*argv, "-verify") == 0) {\n            verify = SSL_VERIFY_PEER;\n            if (--argc < 1)\n                goto bad;\n            verify_depth = atoi(*(++argv));\n            if (!c_quiet)\n                BIO_printf(bio_err, "verify depth is %d\\n", verify_depth);\n        } else if (strcmp(*argv, "-cert") == 0) {\n            if (--argc < 1)\n                goto bad;\n            cert_file = *(++argv);\n        } else if (strcmp(*argv, "-CRL") == 0) {\n            if (--argc < 1)\n                goto bad;\n            crl_file = *(++argv);\n        } else if (strcmp(*argv, "-crl_download") == 0)\n            crl_download = 1;\n        else if (strcmp(*argv, "-sess_out") == 0) {\n            if (--argc < 1)\n                goto bad;\n            sess_out = *(++argv);\n        } else if (strcmp(*argv, "-sess_in") == 0) {\n            if (--argc < 1)\n                goto bad;\n            sess_in = *(++argv);\n        } else if (strcmp(*argv, "-certform") == 0) {\n            if (--argc < 1)\n                goto bad;\n            cert_format = str2fmt(*(++argv));\n        } else if (strcmp(*argv, "-CRLform") == 0) {\n            if (--argc < 1)\n                goto bad;\n            crl_format = str2fmt(*(++argv));\n        } else if (args_verify(&argv, &argc, &badarg, bio_err, &vpm)) {\n            if (badarg)\n                goto bad;\n            continue;\n        } else if (strcmp(*argv, "-verify_return_error") == 0)\n            verify_return_error = 1;\n        else if (strcmp(*argv, "-verify_quiet") == 0)\n            verify_quiet = 1;\n        else if (strcmp(*argv, "-brief") == 0) {\n            c_brief = 1;\n            verify_quiet = 1;\n            c_quiet = 1;\n        } else if (args_excert(&argv, &argc, &badarg, bio_err, &exc)) {\n            if (badarg)\n                goto bad;\n            continue;\n        } else if (args_ssl(&argv, &argc, cctx, &badarg, bio_err, &ssl_args)) {\n            if (badarg)\n                goto bad;\n            continue;\n        } else if (strcmp(*argv, "-prexit") == 0)\n            prexit = 1;\n        else if (strcmp(*argv, "-crlf") == 0)\n            crlf = 1;\n        else if (strcmp(*argv, "-quiet") == 0) {\n            c_quiet = 1;\n            c_ign_eof = 1;\n        } else if (strcmp(*argv, "-ign_eof") == 0)\n            c_ign_eof = 1;\n        else if (strcmp(*argv, "-no_ign_eof") == 0)\n            c_ign_eof = 0;\n        else if (strcmp(*argv, "-pause") == 0)\n            c_Pause = 1;\n        else if (strcmp(*argv, "-debug") == 0)\n            c_debug = 1;\n#ifndef OPENSSL_NO_TLSEXT\n        else if (strcmp(*argv, "-tlsextdebug") == 0)\n            c_tlsextdebug = 1;\n        else if (strcmp(*argv, "-status") == 0)\n            c_status_req = 1;\n#endif\n#ifdef WATT32\n        else if (strcmp(*argv, "-wdebug") == 0)\n            dbug_init();\n#endif\n        else if (strcmp(*argv, "-msg") == 0)\n            c_msg = 1;\n        else if (strcmp(*argv, "-msgfile") == 0) {\n            if (--argc < 1)\n                goto bad;\n            bio_c_msg = BIO_new_file(*(++argv), "w");\n        }\n#ifndef OPENSSL_NO_SSL_TRACE\n        else if (strcmp(*argv, "-trace") == 0)\n            c_msg = 2;\n#endif\n        else if (strcmp(*argv, "-security_debug") == 0) {\n            sdebug = 1;\n        } else if (strcmp(*argv, "-security_debug_verbose") == 0) {\n            sdebug = 2;\n        } else if (strcmp(*argv, "-showcerts") == 0)\n            c_showcerts = 1;\n        else if (strcmp(*argv, "-nbio_test") == 0)\n            nbio_test = 1;\n        else if (strcmp(*argv, "-state") == 0)\n            state = 1;\n#ifndef OPENSSL_NO_PSK\n        else if (strcmp(*argv, "-psk_identity") == 0) {\n            if (--argc < 1)\n                goto bad;\n            psk_identity = *(++argv);\n        } else if (strcmp(*argv, "-psk") == 0) {\n            size_t j;\n            if (--argc < 1)\n                goto bad;\n            psk_key = *(++argv);\n            for (j = 0; j < strlen(psk_key); j++) {\n                if (isxdigit((unsigned char)psk_key[j]))\n                    continue;\n                BIO_printf(bio_err, "Not a hex number \'%s\'\\n", *argv);\n                goto bad;\n            }\n        }\n#endif\n#ifndef OPENSSL_NO_SRP\n        else if (strcmp(*argv, "-srpuser") == 0) {\n            if (--argc < 1)\n                goto bad;\n            srp_arg.srplogin = *(++argv);\n            meth = TLSv1_client_method();\n        } else if (strcmp(*argv, "-srppass") == 0) {\n            if (--argc < 1)\n                goto bad;\n            srppass = *(++argv);\n            meth = TLSv1_client_method();\n        } else if (strcmp(*argv, "-srp_strength") == 0) {\n            if (--argc < 1)\n                goto bad;\n            srp_arg.strength = atoi(*(++argv));\n            BIO_printf(bio_err, "SRP minimal length for N is %d\\n",\n                       srp_arg.strength);\n            meth = TLSv1_client_method();\n        } else if (strcmp(*argv, "-srp_lateuser") == 0) {\n            srp_lateuser = 1;\n            meth = TLSv1_client_method();\n        } else if (strcmp(*argv, "-srp_moregroups") == 0) {\n            srp_arg.amp = 1;\n            meth = TLSv1_client_method();\n        }\n#endif\n#ifndef OPENSSL_NO_SSL3_METHOD\n        else if (strcmp(*argv, "-ssl3") == 0)\n            meth = SSLv3_client_method();\n#endif\n        else if (strcmp(*argv, "-tls1_2") == 0)\n            meth = TLSv1_2_client_method();\n        else if (strcmp(*argv, "-tls1_1") == 0)\n            meth = TLSv1_1_client_method();\n        else if (strcmp(*argv, "-tls1") == 0)\n            meth = TLSv1_client_method();\n#ifndef OPENSSL_NO_DTLS1\n        else if (strcmp(*argv, "-dtls") == 0) {\n            meth = DTLS_client_method();\n            socket_type = SOCK_DGRAM;\n        } else if (strcmp(*argv, "-dtls1") == 0) {\n            meth = DTLSv1_client_method();\n            socket_type = SOCK_DGRAM;\n        } else if (strcmp(*argv, "-dtls1_2") == 0) {\n            meth = DTLSv1_2_client_method();\n            socket_type = SOCK_DGRAM;\n        } else if (strcmp(*argv, "-timeout") == 0)\n            enable_timeouts = 1;\n        else if (strcmp(*argv, "-mtu") == 0) {\n            if (--argc < 1)\n                goto bad;\n            socket_mtu = atol(*(++argv));\n        }\n#endif\n        else if (strcmp(*argv, "-fallback_scsv") == 0) {\n            fallback_scsv = 1;\n        } else if (strcmp(*argv, "-keyform") == 0) {\n            if (--argc < 1)\n                goto bad;\n            key_format = str2fmt(*(++argv));\n        } else if (strcmp(*argv, "-pass") == 0) {\n            if (--argc < 1)\n                goto bad;\n            passarg = *(++argv);\n        } else if (strcmp(*argv, "-cert_chain") == 0) {\n            if (--argc < 1)\n                goto bad;\n            chain_file = *(++argv);\n        } else if (strcmp(*argv, "-key") == 0) {\n            if (--argc < 1)\n                goto bad;\n            key_file = *(++argv);\n        } else if (strcmp(*argv, "-reconnect") == 0) {\n            reconnect = 5;\n        } else if (strcmp(*argv, "-CApath") == 0) {\n            if (--argc < 1)\n                goto bad;\n            CApath = *(++argv);\n        } else if (strcmp(*argv, "-chainCApath") == 0) {\n            if (--argc < 1)\n                goto bad;\n            chCApath = *(++argv);\n        } else if (strcmp(*argv, "-verifyCApath") == 0) {\n            if (--argc < 1)\n                goto bad;\n            vfyCApath = *(++argv);\n        } else if (strcmp(*argv, "-build_chain") == 0)\n            build_chain = 1;\n        else if (strcmp(*argv, "-CAfile") == 0) {\n            if (--argc < 1)\n                goto bad;\n            CAfile = *(++argv);\n        } else if (strcmp(*argv, "-chainCAfile") == 0) {\n            if (--argc < 1)\n                goto bad;\n            chCAfile = *(++argv);\n        } else if (strcmp(*argv, "-verifyCAfile") == 0) {\n            if (--argc < 1)\n                goto bad;\n            vfyCAfile = *(++argv);\n        }\n#ifndef OPENSSL_NO_TLSEXT\n# ifndef OPENSSL_NO_NEXTPROTONEG\n        else if (strcmp(*argv, "-nextprotoneg") == 0) {\n            if (--argc < 1)\n                goto bad;\n            next_proto_neg_in = *(++argv);\n        }\n# endif\n        else if (strcmp(*argv, "-alpn") == 0) {\n            if (--argc < 1)\n                goto bad;\n            alpn_in = *(++argv);\n        } else if (strcmp(*argv, "-serverinfo") == 0) {\n            char *c;\n            int start = 0;\n            int len;\n            if (--argc < 1)\n                goto bad;\n            c = *(++argv);\n            serverinfo_types_count = 0;\n            len = strlen(c);\n            for (i = 0; i <= len; ++i) {\n                if (i == len || c[i] == \',\') {\n                    serverinfo_types[serverinfo_types_count]\n                        = atoi(c + start);\n                    serverinfo_types_count++;\n                    start = i + 1;\n                }\n                if (serverinfo_types_count == MAX_SI_TYPES)\n                    break;\n            }\n        }\n#endif\n#ifdef FIONBIO\n        else if (strcmp(*argv, "-nbio") == 0) {\n            c_nbio = 1;\n        }\n#endif\n        else if (strcmp(*argv, "-starttls") == 0) {\n            if (--argc < 1)\n                goto bad;\n            ++argv;\n            if (strcmp(*argv, "smtp") == 0)\n                starttls_proto = PROTO_SMTP;\n            else if (strcmp(*argv, "pop3") == 0)\n                starttls_proto = PROTO_POP3;\n            else if (strcmp(*argv, "imap") == 0)\n                starttls_proto = PROTO_IMAP;\n            else if (strcmp(*argv, "ftp") == 0)\n                starttls_proto = PROTO_FTP;\n            else if (strcmp(*argv, "xmpp") == 0)\n                starttls_proto = PROTO_XMPP;\n            else\n                goto bad;\n        }\n#ifndef OPENSSL_NO_ENGINE\n        else if (strcmp(*argv, "-engine") == 0) {\n            if (--argc < 1)\n                goto bad;\n            engine_id = *(++argv);\n        } else if (strcmp(*argv, "-ssl_client_engine") == 0) {\n            if (--argc < 1)\n                goto bad;\n            ssl_client_engine_id = *(++argv);\n        }\n#endif\n        else if (strcmp(*argv, "-rand") == 0) {\n            if (--argc < 1)\n                goto bad;\n            inrand = *(++argv);\n        }\n#ifndef OPENSSL_NO_TLSEXT\n        else if (strcmp(*argv, "-servername") == 0) {\n            if (--argc < 1)\n                goto bad;\n            servername = *(++argv);\n        }\n#endif\n#ifndef OPENSSL_NO_JPAKE\n        else if (strcmp(*argv, "-jpake") == 0) {\n            if (--argc < 1)\n                goto bad;\n            jpake_secret = *++argv;\n        }\n#endif\n#ifndef OPENSSL_NO_SRTP\n        else if (strcmp(*argv, "-use_srtp") == 0) {\n            if (--argc < 1)\n                goto bad;\n            srtp_profiles = *(++argv);\n        }\n#endif\n        else if (strcmp(*argv, "-keymatexport") == 0) {\n            if (--argc < 1)\n                goto bad;\n            keymatexportlabel = *(++argv);\n        } else if (strcmp(*argv, "-keymatexportlen") == 0) {\n            if (--argc < 1)\n                goto bad;\n            keymatexportlen = atoi(*(++argv));\n            if (keymatexportlen == 0)\n                goto bad;\n        } else {\n            BIO_printf(bio_err, "unknown option %s\\n", *argv);\n            badop = 1;\n            break;\n        }\n        argc--;\n        argv++;\n    }\n    if (badop) {\n bad:\n        sc_usage();\n        goto end;\n    }\n    if (unix_path && (socket_type != SOCK_STREAM)) {\n        BIO_printf(bio_err,\n                   "Can\'t use unix sockets and datagrams together\\n");\n        goto end;\n    }\n#if !defined(OPENSSL_NO_JPAKE) && !defined(OPENSSL_NO_PSK)\n    if (jpake_secret) {\n        if (psk_key) {\n            BIO_printf(bio_err, "Can\'t use JPAKE and PSK together\\n");\n            goto end;\n        }\n        psk_identity = "JPAKE";\n    }\n#endif\n    OpenSSL_add_ssl_algorithms();\n    SSL_load_error_strings();\n#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)\n    next_proto.status = -1;\n    if (next_proto_neg_in) {\n        next_proto.data =\n            next_protos_parse(&next_proto.len, next_proto_neg_in);\n        if (next_proto.data == NULL) {\n            BIO_printf(bio_err, "Error parsing -nextprotoneg argument\\n");\n            goto end;\n        }\n    } else\n        next_proto.data = NULL;\n#endif\n#ifndef OPENSSL_NO_ENGINE\n    e = setup_engine(bio_err, engine_id, 1);\n    if (ssl_client_engine_id) {\n        ssl_client_engine = ENGINE_by_id(ssl_client_engine_id);\n        if (!ssl_client_engine) {\n            BIO_printf(bio_err, "Error getting client auth engine\\n");\n            goto end;\n        }\n    }\n#endif\n    if (!app_passwd(bio_err, passarg, NULL, &pass, NULL)) {\n        BIO_printf(bio_err, "Error getting password\\n");\n        goto end;\n    }\n    if (key_file == NULL)\n        key_file = cert_file;\n    if (key_file) {\n        key = load_key(bio_err, key_file, key_format, 0, pass, e,\n                       "client certificate private key file");\n        if (!key) {\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n    }\n    if (cert_file) {\n        cert = load_cert(bio_err, cert_file, cert_format,\n                         NULL, e, "client certificate file");\n        if (!cert) {\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n    }\n    if (chain_file) {\n        chain = load_certs(bio_err, chain_file, FORMAT_PEM,\n                           NULL, e, "client certificate chain");\n        if (!chain)\n            goto end;\n    }\n    if (crl_file) {\n        X509_CRL *crl;\n        crl = load_crl(crl_file, crl_format);\n        if (!crl) {\n            BIO_puts(bio_err, "Error loading CRL\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        crls = sk_X509_CRL_new_null();\n        if (!crls || !sk_X509_CRL_push(crls, crl)) {\n            BIO_puts(bio_err, "Error adding CRL\\n");\n            ERR_print_errors(bio_err);\n            X509_CRL_free(crl);\n            goto end;\n        }\n    }\n    if (!load_excert(&exc, bio_err))\n        goto end;\n    if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL\n        && !RAND_status()) {\n        BIO_printf(bio_err,\n                   "warning, not much extra random data, consider using the -rand option\\n");\n    }\n    if (inrand != NULL)\n        BIO_printf(bio_err, "%ld semi-random bytes loaded\\n",\n                   app_RAND_load_files(inrand));\n    if (bio_c_out == NULL) {\n        if (c_quiet && !c_debug) {\n            bio_c_out = BIO_new(BIO_s_null());\n            if (c_msg && !bio_c_msg)\n                bio_c_msg = BIO_new_fp(stdout, BIO_NOCLOSE);\n        } else {\n            if (bio_c_out == NULL)\n                bio_c_out = BIO_new_fp(stdout, BIO_NOCLOSE);\n        }\n    }\n#ifndef OPENSSL_NO_SRP\n    if (!app_passwd(bio_err, srppass, NULL, &srp_arg.srppassin, NULL)) {\n        BIO_printf(bio_err, "Error getting password\\n");\n        goto end;\n    }\n#endif\n    ctx = SSL_CTX_new(meth);\n    if (ctx == NULL) {\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    if (sdebug)\n        ssl_ctx_security_debug(ctx, bio_err, sdebug);\n    if (vpm && !SSL_CTX_set1_param(ctx, vpm)) {\n        BIO_printf(bio_err, "Error setting verify params\\n");\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    if (!args_ssl_call(ctx, bio_err, cctx, ssl_args, 1, no_jpake)) {\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    if (!ssl_load_stores(ctx, vfyCApath, vfyCAfile, chCApath, chCAfile,\n                         crls, crl_download)) {\n        BIO_printf(bio_err, "Error loading store locations\\n");\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n#ifndef OPENSSL_NO_ENGINE\n    if (ssl_client_engine) {\n        if (!SSL_CTX_set_client_cert_engine(ctx, ssl_client_engine)) {\n            BIO_puts(bio_err, "Error setting client auth engine\\n");\n            ERR_print_errors(bio_err);\n            ENGINE_free(ssl_client_engine);\n            goto end;\n        }\n        ENGINE_free(ssl_client_engine);\n    }\n#endif\n#ifndef OPENSSL_NO_PSK\n# ifdef OPENSSL_NO_JPAKE\n    if (psk_key != NULL)\n# else\n    if (psk_key != NULL || jpake_secret)\n# endif\n    {\n        if (c_debug)\n            BIO_printf(bio_c_out,\n                       "PSK key given or JPAKE in use, setting client callback\\n");\n        SSL_CTX_set_psk_client_callback(ctx, psk_client_cb);\n    }\n#endif\n#ifndef OPENSSL_NO_SRTP\n    if (srtp_profiles != NULL) {\n        if(SSL_CTX_set_tlsext_use_srtp(ctx, srtp_profiles)) {\n            BIO_printf(bio_err, "Error setting SRTP profile\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n    }\n#endif\n    if (exc)\n        ssl_ctx_set_excert(ctx, exc);\n#if !defined(OPENSSL_NO_TLSEXT)\n# if !defined(OPENSSL_NO_NEXTPROTONEG)\n    if (next_proto.data)\n        SSL_CTX_set_next_proto_select_cb(ctx, next_proto_cb, &next_proto);\n# endif\n    if (alpn_in) {\n        unsigned short alpn_len;\n        unsigned char *alpn = next_protos_parse(&alpn_len, alpn_in);\n        if (alpn == NULL) {\n            BIO_printf(bio_err, "Error parsing -alpn argument\\n");\n            goto end;\n        }\n        if(SSL_CTX_set_alpn_protos(ctx, alpn, alpn_len)) {\n            BIO_printf(bio_err, "Error setting ALPN\\n");\n            goto end;\n        }\n        OPENSSL_free(alpn);\n    }\n#endif\n#ifndef OPENSSL_NO_TLSEXT\n    for (i = 0; i < serverinfo_types_count; i++) {\n        if(!SSL_CTX_add_client_custom_ext(ctx,\n                                      serverinfo_types[i],\n                                      NULL, NULL, NULL,\n                                      serverinfo_cli_parse_cb, NULL)) {\n            BIO_printf(bio_err, "Warning: Unable to add custom extension %u. "\n                       "Skipping\\n", serverinfo_types[i]);\n        }\n    }\n#endif\n    if (state)\n        SSL_CTX_set_info_callback(ctx, apps_ssl_info_callback);\n    SSL_CTX_set_verify(ctx, verify, verify_callback);\n    if ((!SSL_CTX_load_verify_locations(ctx, CAfile, CApath)) ||\n        (!SSL_CTX_set_default_verify_paths(ctx))) {\n        ERR_print_errors(bio_err);\n    }\n    ssl_ctx_add_crls(ctx, crls, crl_download);\n    if (!set_cert_key_stuff(ctx, cert, key, chain, build_chain))\n        goto end;\n#ifndef OPENSSL_NO_TLSEXT\n    if (servername != NULL) {\n        tlsextcbp.biodebug = bio_err;\n        SSL_CTX_set_tlsext_servername_callback(ctx, ssl_servername_cb);\n        SSL_CTX_set_tlsext_servername_arg(ctx, &tlsextcbp);\n    }\n# ifndef OPENSSL_NO_SRP\n    if (srp_arg.srplogin) {\n        if (!srp_lateuser && !SSL_CTX_set_srp_username(ctx, srp_arg.srplogin)) {\n            BIO_printf(bio_err, "Unable to set SRP username\\n");\n            goto end;\n        }\n        srp_arg.msg = c_msg;\n        srp_arg.debug = c_debug;\n        SSL_CTX_set_srp_cb_arg(ctx, &srp_arg);\n        SSL_CTX_set_srp_client_pwd_callback(ctx, ssl_give_srp_client_pwd_cb);\n        SSL_CTX_set_srp_strength(ctx, srp_arg.strength);\n        if (c_msg || c_debug || srp_arg.amp == 0)\n            SSL_CTX_set_srp_verify_param_callback(ctx,\n                                                  ssl_srp_verify_param_cb);\n    }\n# endif\n#endif\n    con = SSL_new(ctx);\n    if (sess_in) {\n        SSL_SESSION *sess;\n        BIO *stmp = BIO_new_file(sess_in, "r");\n        if (!stmp) {\n            BIO_printf(bio_err, "Can\'t open session file %s\\n", sess_in);\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        sess = PEM_read_bio_SSL_SESSION(stmp, NULL, 0, NULL);\n        BIO_free(stmp);\n        if (!sess) {\n            BIO_printf(bio_err, "Can\'t open session file %s\\n", sess_in);\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        if(!SSL_set_session(con, sess)) {\n            BIO_printf(bio_err, "Can\'t set session\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        SSL_SESSION_free(sess);\n    }\n    if (fallback_scsv)\n        SSL_set_mode(con, SSL_MODE_SEND_FALLBACK_SCSV);\n#ifndef OPENSSL_NO_TLSEXT\n    if (servername != NULL) {\n        if (!SSL_set_tlsext_host_name(con, servername)) {\n            BIO_printf(bio_err, "Unable to set TLS servername extension.\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n    }\n#endif\n#ifndef OPENSSL_NO_KRB5\n    if (con && (kctx = kssl_ctx_new()) != NULL) {\n        SSL_set0_kssl_ctx(con, kctx);\n        kssl_ctx_setstring(kctx, KSSL_SERVER, host);\n    }\n#endif\n re_start:\n#ifdef NO_SYS_UN_H\n    if (init_client(&s, host, port, socket_type) == 0)\n#else\n    if ((!unix_path && (init_client(&s, host, port, socket_type) == 0)) ||\n        (unix_path && (init_client_unix(&s, unix_path) == 0)))\n#endif\n    {\n        BIO_printf(bio_err, "connect:errno=%d\\n", get_last_socket_error());\n        SHUTDOWN(s);\n        goto end;\n    }\n    BIO_printf(bio_c_out, "CONNECTED(%08X)\\n", s);\n#ifdef FIONBIO\n    if (c_nbio) {\n        unsigned long l = 1;\n        BIO_printf(bio_c_out, "turning on non blocking io\\n");\n        if (BIO_socket_ioctl(s, FIONBIO, &l) < 0) {\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n    }\n#endif\n    if (c_Pause & 0x01)\n        SSL_set_debug(con, 1);\n    if (socket_type == SOCK_DGRAM) {\n        sbio = BIO_new_dgram(s, BIO_NOCLOSE);\n        if (getsockname(s, &peer, (void *)&peerlen) < 0) {\n            BIO_printf(bio_err, "getsockname:errno=%d\\n",\n                       get_last_socket_error());\n            SHUTDOWN(s);\n            goto end;\n        }\n        (void)BIO_ctrl_set_connected(sbio, 1, &peer);\n        if (enable_timeouts) {\n            timeout.tv_sec = 0;\n            timeout.tv_usec = DGRAM_RCV_TIMEOUT;\n            BIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_RECV_TIMEOUT, 0, &timeout);\n            timeout.tv_sec = 0;\n            timeout.tv_usec = DGRAM_SND_TIMEOUT;\n            BIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_SEND_TIMEOUT, 0, &timeout);\n        }\n        if (socket_mtu) {\n            if (socket_mtu < DTLS_get_link_min_mtu(con)) {\n                BIO_printf(bio_err, "MTU too small. Must be at least %ld\\n",\n                           DTLS_get_link_min_mtu(con));\n                BIO_free(sbio);\n                goto shut;\n            }\n            SSL_set_options(con, SSL_OP_NO_QUERY_MTU);\n            if (!DTLS_set_link_mtu(con, socket_mtu)) {\n                BIO_printf(bio_err, "Failed to set MTU\\n");\n                BIO_free(sbio);\n                goto shut;\n            }\n        } else\n            BIO_ctrl(sbio, BIO_CTRL_DGRAM_MTU_DISCOVER, 0, NULL);\n    } else\n        sbio = BIO_new_socket(s, BIO_NOCLOSE);\n    if (nbio_test) {\n        BIO *test;\n        test = BIO_new(BIO_f_nbio_test());\n        sbio = BIO_push(test, sbio);\n    }\n    if (c_debug) {\n        SSL_set_debug(con, 1);\n        BIO_set_callback(sbio, bio_dump_callback);\n        BIO_set_callback_arg(sbio, (char *)bio_c_out);\n    }\n    if (c_msg) {\n#ifndef OPENSSL_NO_SSL_TRACE\n        if (c_msg == 2)\n            SSL_set_msg_callback(con, SSL_trace);\n        else\n#endif\n            SSL_set_msg_callback(con, msg_cb);\n        SSL_set_msg_callback_arg(con, bio_c_msg ? bio_c_msg : bio_c_out);\n    }\n#ifndef OPENSSL_NO_TLSEXT\n    if (c_tlsextdebug) {\n        SSL_set_tlsext_debug_callback(con, tlsext_cb);\n        SSL_set_tlsext_debug_arg(con, bio_c_out);\n    }\n    if (c_status_req) {\n        SSL_set_tlsext_status_type(con, TLSEXT_STATUSTYPE_ocsp);\n        SSL_CTX_set_tlsext_status_cb(ctx, ocsp_resp_cb);\n        SSL_CTX_set_tlsext_status_arg(ctx, bio_c_out);\n    }\n#endif\n#ifndef OPENSSL_NO_JPAKE\n    if (jpake_secret)\n        jpake_client_auth(bio_c_out, sbio, jpake_secret);\n#endif\n    SSL_set_bio(con, sbio, sbio);\n    SSL_set_connect_state(con);\n    width = SSL_get_fd(con) + 1;\n    read_tty = 1;\n    write_tty = 0;\n    tty_on = 0;\n    read_ssl = 1;\n    write_ssl = 1;\n    cbuf_len = 0;\n    cbuf_off = 0;\n    sbuf_len = 0;\n    sbuf_off = 0;\n    if (starttls_proto == PROTO_SMTP) {\n        int foundit = 0;\n        BIO *fbio = BIO_new(BIO_f_buffer());\n        BIO_push(fbio, sbio);\n        do {\n            mbuf_len = BIO_gets(fbio, mbuf, BUFSIZZ);\n        }\n        while (mbuf_len > 3 && mbuf[3] == \'-\');\n        BIO_printf(fbio, "EHLO openssl.client.net\\r\\n");\n        (void)BIO_flush(fbio);\n        do {\n            mbuf_len = BIO_gets(fbio, mbuf, BUFSIZZ);\n            if (strstr(mbuf, "STARTTLS"))\n                foundit = 1;\n        }\n        while (mbuf_len > 3 && mbuf[3] == \'-\');\n        (void)BIO_flush(fbio);\n        BIO_pop(fbio);\n        BIO_free(fbio);\n        if (!foundit)\n            BIO_printf(bio_err,\n                       "didn\'t found starttls in server response,"\n                       " try anyway...\\n");\n        BIO_printf(sbio, "STARTTLS\\r\\n");\n        BIO_read(sbio, sbuf, BUFSIZZ);\n    } else if (starttls_proto == PROTO_POP3) {\n        BIO_read(sbio, mbuf, BUFSIZZ);\n        BIO_printf(sbio, "STLS\\r\\n");\n        BIO_read(sbio, sbuf, BUFSIZZ);\n    } else if (starttls_proto == PROTO_IMAP) {\n        int foundit = 0;\n        BIO *fbio = BIO_new(BIO_f_buffer());\n        BIO_push(fbio, sbio);\n        BIO_gets(fbio, mbuf, BUFSIZZ);\n        BIO_printf(fbio, ". CAPABILITY\\r\\n");\n        (void)BIO_flush(fbio);\n        do {\n            mbuf_len = BIO_gets(fbio, mbuf, BUFSIZZ);\n            if (strstr(mbuf, "STARTTLS"))\n                foundit = 1;\n        }\n        while (mbuf_len > 3 && mbuf[0] != \'.\');\n        (void)BIO_flush(fbio);\n        BIO_pop(fbio);\n        BIO_free(fbio);\n        if (!foundit)\n            BIO_printf(bio_err,\n                       "didn\'t found STARTTLS in server response,"\n                       " try anyway...\\n");\n        BIO_printf(sbio, ". STARTTLS\\r\\n");\n        BIO_read(sbio, sbuf, BUFSIZZ);\n    } else if (starttls_proto == PROTO_FTP) {\n        BIO *fbio = BIO_new(BIO_f_buffer());\n        BIO_push(fbio, sbio);\n        do {\n            mbuf_len = BIO_gets(fbio, mbuf, BUFSIZZ);\n        }\n        while (mbuf_len > 3 && mbuf[3] == \'-\');\n        (void)BIO_flush(fbio);\n        BIO_pop(fbio);\n        BIO_free(fbio);\n        BIO_printf(sbio, "AUTH TLS\\r\\n");\n        BIO_read(sbio, sbuf, BUFSIZZ);\n    }\n    if (starttls_proto == PROTO_XMPP) {\n        int seen = 0;\n        BIO_printf(sbio, "<stream:stream "\n                   "xmlns:stream=\'http://etherx.jabber.org/streams\' "\n                   "xmlns=\'jabber:client\' to=\'%s\' version=\'1.0\'>", xmpphost ?\n                   xmpphost : host);\n        seen = BIO_read(sbio, mbuf, BUFSIZZ);\n        mbuf[seen] = 0;\n        while (!strstr\n               (mbuf, "<starttls xmlns=\'urn:ietf:params:xml:ns:xmpp-tls\'")\n               && !strstr(mbuf,\n                          "<starttls xmlns=\\"urn:ietf:params:xml:ns:xmpp-tls\\""))\n        {\n            seen = BIO_read(sbio, mbuf, BUFSIZZ);\n            if (seen <= 0)\n                goto shut;\n            mbuf[seen] = 0;\n        }\n        BIO_printf(sbio,\n                   "<starttls xmlns=\'urn:ietf:params:xml:ns:xmpp-tls\'/>");\n        seen = BIO_read(sbio, sbuf, BUFSIZZ);\n        sbuf[seen] = 0;\n        if (!strstr(sbuf, "<proceed"))\n            goto shut;\n        mbuf[0] = 0;\n    }\n    for (;;) {\n        FD_ZERO(&readfds);\n        FD_ZERO(&writefds);\n        if ((SSL_version(con) == DTLS1_VERSION) &&\n            DTLSv1_get_timeout(con, &timeout))\n            timeoutp = &timeout;\n        else\n            timeoutp = NULL;\n        if (SSL_in_init(con) && !SSL_total_renegotiations(con)) {\n            in_init = 1;\n            tty_on = 0;\n        } else {\n            tty_on = 1;\n            if (in_init) {\n                in_init = 0;\n                if (sess_out) {\n                    BIO *stmp = BIO_new_file(sess_out, "w");\n                    if (stmp) {\n                        PEM_write_bio_SSL_SESSION(stmp, SSL_get_session(con));\n                        BIO_free(stmp);\n                    } else\n                        BIO_printf(bio_err, "Error writing session file %s\\n",\n                                   sess_out);\n                }\n                if (c_brief) {\n                    BIO_puts(bio_err, "CONNECTION ESTABLISHED\\n");\n                    print_ssl_summary(bio_err, con);\n                }\n                print_stuff(bio_c_out, con, full_log);\n                if (full_log > 0)\n                    full_log--;\n                if (starttls_proto) {\n                    BIO_printf(bio_err, "%s", mbuf);\n                    starttls_proto = PROTO_OFF;\n                }\n                if (reconnect) {\n                    reconnect--;\n                    BIO_printf(bio_c_out,\n                               "drop connection and then reconnect\\n");\n                    SSL_shutdown(con);\n                    SSL_set_connect_state(con);\n                    SHUTDOWN(SSL_get_fd(con));\n                    goto re_start;\n                }\n            }\n        }\n        ssl_pending = read_ssl && SSL_pending(con);\n        if (!ssl_pending) {\n#if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_NETWARE)\n            if (tty_on) {\n                if (read_tty)\n                    openssl_fdset(fileno(stdin), &readfds);\n                if (write_tty)\n                    openssl_fdset(fileno(stdout), &writefds);\n            }\n            if (read_ssl)\n                openssl_fdset(SSL_get_fd(con), &readfds);\n            if (write_ssl)\n                openssl_fdset(SSL_get_fd(con), &writefds);\n#else\n            if (!tty_on || !write_tty) {\n                if (read_ssl)\n                    openssl_fdset(SSL_get_fd(con), &readfds);\n                if (write_ssl)\n                    openssl_fdset(SSL_get_fd(con), &writefds);\n            }\n#endif\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)\n            i = 0;\n            if (!write_tty) {\n                if (read_tty) {\n                    tv.tv_sec = 1;\n                    tv.tv_usec = 0;\n                    i = select(width, (void *)&readfds, (void *)&writefds,\n                               NULL, &tv);\n# if defined(OPENSSL_SYS_WINCE) || defined(OPENSSL_SYS_MSDOS)\n                    if (!i && (!_kbhit() || !read_tty))\n                        continue;\n# else\n                    if (!i && (!((_kbhit())\n                                 || (WAIT_OBJECT_0 ==\n                                     WaitForSingleObject(GetStdHandle\n                                                         (STD_INPUT_HANDLE),\n                                                         0)))\n                               || !read_tty))\n                        continue;\n# endif\n                } else\n                    i = select(width, (void *)&readfds, (void *)&writefds,\n                               NULL, timeoutp);\n            }\n#elif defined(OPENSSL_SYS_NETWARE)\n            if (!write_tty) {\n                if (read_tty) {\n                    tv.tv_sec = 1;\n                    tv.tv_usec = 0;\n                    i = select(width, (void *)&readfds, (void *)&writefds,\n                               NULL, &tv);\n                } else\n                    i = select(width, (void *)&readfds, (void *)&writefds,\n                               NULL, timeoutp);\n            }\n#else\n            i = select(width, (void *)&readfds, (void *)&writefds,\n                       NULL, timeoutp);\n#endif\n            if (i < 0) {\n                BIO_printf(bio_err, "bad select %d\\n",\n                           get_last_socket_error());\n                goto shut;\n            }\n        }\n        if ((SSL_version(con) == DTLS1_VERSION)\n            && DTLSv1_handle_timeout(con) > 0) {\n            BIO_printf(bio_err, "TIMEOUT occurred\\n");\n        }\n        if (!ssl_pending && FD_ISSET(SSL_get_fd(con), &writefds)) {\n            k = SSL_write(con, &(cbuf[cbuf_off]), (unsigned int)cbuf_len);\n            switch (SSL_get_error(con, k)) {\n            case SSL_ERROR_NONE:\n                cbuf_off += k;\n                cbuf_len -= k;\n                if (k <= 0)\n                    goto end;\n                if (cbuf_len <= 0) {\n                    read_tty = 1;\n                    write_ssl = 0;\n                } else {\n                    read_tty = 0;\n                    write_ssl = 1;\n                }\n                break;\n            case SSL_ERROR_WANT_WRITE:\n                BIO_printf(bio_c_out, "write W BLOCK\\n");\n                write_ssl = 1;\n                read_tty = 0;\n                break;\n            case SSL_ERROR_WANT_READ:\n                BIO_printf(bio_c_out, "write R BLOCK\\n");\n                write_tty = 0;\n                read_ssl = 1;\n                write_ssl = 0;\n                break;\n            case SSL_ERROR_WANT_X509_LOOKUP:\n                BIO_printf(bio_c_out, "write X BLOCK\\n");\n                break;\n            case SSL_ERROR_ZERO_RETURN:\n                if (cbuf_len != 0) {\n                    BIO_printf(bio_c_out, "shutdown\\n");\n                    ret = 0;\n                    goto shut;\n                } else {\n                    read_tty = 1;\n                    write_ssl = 0;\n                    break;\n                }\n            case SSL_ERROR_SYSCALL:\n                if ((k != 0) || (cbuf_len != 0)) {\n                    BIO_printf(bio_err, "write:errno=%d\\n",\n                               get_last_socket_error());\n                    goto shut;\n                } else {\n                    read_tty = 1;\n                    write_ssl = 0;\n                }\n                break;\n            case SSL_ERROR_SSL:\n                ERR_print_errors(bio_err);\n                goto shut;\n            }\n        }\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE)\n        else if (!ssl_pending && write_tty)\n#else\n        else if (!ssl_pending && FD_ISSET(fileno(stdout), &writefds))\n#endif\n        {\n#ifdef CHARSET_EBCDIC\n            ascii2ebcdic(&(sbuf[sbuf_off]), &(sbuf[sbuf_off]), sbuf_len);\n#endif\n            i = raw_write_stdout(&(sbuf[sbuf_off]), sbuf_len);\n            if (i <= 0) {\n                BIO_printf(bio_c_out, "DONE\\n");\n                ret = 0;\n                goto shut;\n            }\n            sbuf_len -= i;;\n            sbuf_off += i;\n            if (sbuf_len <= 0) {\n                read_ssl = 1;\n                write_tty = 0;\n            }\n        } else if (ssl_pending || FD_ISSET(SSL_get_fd(con), &readfds)) {\n#ifdef RENEG\n            {\n                static int iiii;\n                if (++iiii == 52) {\n                    SSL_renegotiate(con);\n                    iiii = 0;\n                }\n            }\n#endif\n            k = SSL_read(con, sbuf, 1024   );\n            switch (SSL_get_error(con, k)) {\n            case SSL_ERROR_NONE:\n                if (k <= 0)\n                    goto end;\n                sbuf_off = 0;\n                sbuf_len = k;\n                read_ssl = 0;\n                write_tty = 1;\n                break;\n            case SSL_ERROR_WANT_WRITE:\n                BIO_printf(bio_c_out, "read W BLOCK\\n");\n                write_ssl = 1;\n                read_tty = 0;\n                break;\n            case SSL_ERROR_WANT_READ:\n                BIO_printf(bio_c_out, "read R BLOCK\\n");\n                write_tty = 0;\n                read_ssl = 1;\n                if ((read_tty == 0) && (write_ssl == 0))\n                    write_ssl = 1;\n                break;\n            case SSL_ERROR_WANT_X509_LOOKUP:\n                BIO_printf(bio_c_out, "read X BLOCK\\n");\n                break;\n            case SSL_ERROR_SYSCALL:\n                ret = get_last_socket_error();\n                if (c_brief)\n                    BIO_puts(bio_err, "CONNECTION CLOSED BY SERVER\\n");\n                else\n                    BIO_printf(bio_err, "read:errno=%d\\n", ret);\n                goto shut;\n            case SSL_ERROR_ZERO_RETURN:\n                BIO_printf(bio_c_out, "closed\\n");\n                ret = 0;\n                goto shut;\n            case SSL_ERROR_SSL:\n                ERR_print_errors(bio_err);\n                goto shut;\n            }\n        }\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)\n# if defined(OPENSSL_SYS_WINCE) || defined(OPENSSL_SYS_MSDOS)\n        else if (_kbhit())\n# else\n        else if ((_kbhit())\n                 || (WAIT_OBJECT_0 ==\n                     WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 0)))\n# endif\n#elif defined (OPENSSL_SYS_NETWARE)\n        else if (_kbhit())\n#else\n        else if (FD_ISSET(fileno(stdin), &readfds))\n#endif\n        {\n            if (crlf) {\n                int j, lf_num;\n                i = raw_read_stdin(cbuf, BUFSIZZ / 2);\n                lf_num = 0;\n                for (j = 0; j < i; j++)\n                    if (cbuf[j] == \'\\n\')\n                        lf_num++;\n                for (j = i - 1; j >= 0; j--) {\n                    cbuf[j + lf_num] = cbuf[j];\n                    if (cbuf[j] == \'\\n\') {\n                        lf_num--;\n                        i++;\n                        cbuf[j + lf_num] = \'\\r\';\n                    }\n                }\n                assert(lf_num == 0);\n            } else\n                i = raw_read_stdin(cbuf, BUFSIZZ);\n            if ((!c_ign_eof) && ((i <= 0) || (cbuf[0] == \'Q\'))) {\n                BIO_printf(bio_err, "DONE\\n");\n                ret = 0;\n                goto shut;\n            }\n            if ((!c_ign_eof) && (cbuf[0] == \'R\')) {\n                BIO_printf(bio_err, "RENEGOTIATING\\n");\n                SSL_renegotiate(con);\n                cbuf_len = 0;\n            }\n#ifndef OPENSSL_NO_HEARTBEATS\n            else if ((!c_ign_eof) && (cbuf[0] == \'B\')) {\n                BIO_printf(bio_err, "HEARTBEATING\\n");\n                SSL_heartbeat(con);\n                cbuf_len = 0;\n            }\n#endif\n            else {\n                cbuf_len = i;\n                cbuf_off = 0;\n#ifdef CHARSET_EBCDIC\n                ebcdic2ascii(cbuf, cbuf, i);\n#endif\n            }\n            write_ssl = 1;\n            read_tty = 0;\n        }\n    }\n    ret = 0;\n shut:\n    if (in_init)\n        print_stuff(bio_c_out, con, full_log);\n    SSL_shutdown(con);\n    SHUTDOWN(SSL_get_fd(con));\n end:\n    if (con != NULL) {\n        if (prexit != 0)\n            print_stuff(bio_c_out, con, 1);\n        SSL_free(con);\n    }\n#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)\n    if (next_proto.data)\n        OPENSSL_free(next_proto.data);\n#endif\n    if (ctx != NULL)\n        SSL_CTX_free(ctx);\n    if (cert)\n        X509_free(cert);\n    if (crls)\n        sk_X509_CRL_pop_free(crls, X509_CRL_free);\n    if (key)\n        EVP_PKEY_free(key);\n    if (chain)\n        sk_X509_pop_free(chain, X509_free);\n    if (pass)\n        OPENSSL_free(pass);\n    if (vpm)\n        X509_VERIFY_PARAM_free(vpm);\n    ssl_excert_free(exc);\n    if (ssl_args)\n        sk_OPENSSL_STRING_free(ssl_args);\n    if (cctx)\n        SSL_CONF_CTX_free(cctx);\n#ifndef OPENSSL_NO_JPAKE\n    if (jpake_secret && psk_key)\n        OPENSSL_free(psk_key);\n#endif\n    if (cbuf != NULL) {\n        OPENSSL_cleanse(cbuf, BUFSIZZ);\n        OPENSSL_free(cbuf);\n    }\n    if (sbuf != NULL) {\n        OPENSSL_cleanse(sbuf, BUFSIZZ);\n        OPENSSL_free(sbuf);\n    }\n    if (mbuf != NULL) {\n        OPENSSL_cleanse(mbuf, BUFSIZZ);\n        OPENSSL_free(mbuf);\n    }\n    if (bio_c_out != NULL) {\n        BIO_free(bio_c_out);\n        bio_c_out = NULL;\n    }\n    if (bio_c_msg != NULL) {\n        BIO_free(bio_c_msg);\n        bio_c_msg = NULL;\n    }\n    apps_shutdown();\n    OPENSSL_EXIT(ret);\n}', 'int SSL_CTX_set_srp_strength(SSL_CTX *ctx, int strength)\n{\n    return tls1_ctx_ctrl(ctx, SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH, strength,\n                         NULL);\n}', 'long ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg)\n{\n    CERT *cert;\n    cert = ctx->cert;\n    switch (cmd) {\n#ifndef OPENSSL_NO_RSA\n    case SSL_CTRL_NEED_TMP_RSA:\n        if ((cert->rsa_tmp == NULL) &&\n            ((cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) ||\n             (EVP_PKEY_size(cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) >\n              (512 / 8)))\n            )\n            return (1);\n        else\n            return (0);\n    case SSL_CTRL_SET_TMP_RSA:\n        {\n            RSA *rsa;\n            int i;\n            rsa = (RSA *)parg;\n            i = 1;\n            if (rsa == NULL)\n                i = 0;\n            else {\n                if ((rsa = RSAPrivateKey_dup(rsa)) == NULL)\n                    i = 0;\n            }\n            if (!i) {\n                SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_RSA_LIB);\n                return (0);\n            } else {\n                if (cert->rsa_tmp != NULL)\n                    RSA_free(cert->rsa_tmp);\n                cert->rsa_tmp = rsa;\n                return (1);\n            }\n        }\n    case SSL_CTRL_SET_TMP_RSA_CB:\n        {\n            SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n            return (0);\n        }\n#endif\n#ifndef OPENSSL_NO_DH\n    case SSL_CTRL_SET_TMP_DH:\n        {\n            DH *new = NULL, *dh;\n            dh = (DH *)parg;\n            if (!ssl_ctx_security(ctx, SSL_SECOP_TMP_DH,\n                                  DH_security_bits(dh), 0, dh)) {\n                SSLerr(SSL_F_SSL3_CTX_CTRL, SSL_R_DH_KEY_TOO_SMALL);\n                return 0;\n            }\n            if ((new = DHparams_dup(dh)) == NULL) {\n                SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_DH_LIB);\n                return 0;\n            }\n            if (!(ctx->options & SSL_OP_SINGLE_DH_USE)) {\n                if (!DH_generate_key(new)) {\n                    SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_DH_LIB);\n                    DH_free(new);\n                    return 0;\n                }\n            }\n            if (cert->dh_tmp != NULL)\n                DH_free(cert->dh_tmp);\n            cert->dh_tmp = new;\n            return 1;\n        }\n    case SSL_CTRL_SET_TMP_DH_CB:\n        {\n            SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n            return (0);\n        }\n    case SSL_CTRL_SET_DH_AUTO:\n        ctx->cert->dh_tmp_auto = larg;\n        return 1;\n#endif\n#ifndef OPENSSL_NO_EC\n    case SSL_CTRL_SET_TMP_ECDH:\n        {\n            EC_KEY *ecdh = NULL;\n            if (parg == NULL) {\n                SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_ECDH_LIB);\n                return 0;\n            }\n            ecdh = EC_KEY_dup((EC_KEY *)parg);\n            if (ecdh == NULL) {\n                SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_EC_LIB);\n                return 0;\n            }\n            if (!(ctx->options & SSL_OP_SINGLE_ECDH_USE)) {\n                if (!EC_KEY_generate_key(ecdh)) {\n                    EC_KEY_free(ecdh);\n                    SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_ECDH_LIB);\n                    return 0;\n                }\n            }\n            if (cert->ecdh_tmp != NULL) {\n                EC_KEY_free(cert->ecdh_tmp);\n            }\n            cert->ecdh_tmp = ecdh;\n            return 1;\n        }\n    case SSL_CTRL_SET_TMP_ECDH_CB:\n        {\n            SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n            return (0);\n        }\n#endif\n#ifndef OPENSSL_NO_TLSEXT\n    case SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG:\n        ctx->tlsext_servername_arg = parg;\n        break;\n    case SSL_CTRL_SET_TLSEXT_TICKET_KEYS:\n    case SSL_CTRL_GET_TLSEXT_TICKET_KEYS:\n        {\n            unsigned char *keys = parg;\n            if (!keys)\n                return 48;\n            if (larg != 48) {\n                SSLerr(SSL_F_SSL3_CTX_CTRL, SSL_R_INVALID_TICKET_KEYS_LENGTH);\n                return 0;\n            }\n            if (cmd == SSL_CTRL_SET_TLSEXT_TICKET_KEYS) {\n                memcpy(ctx->tlsext_tick_key_name, keys, 16);\n                memcpy(ctx->tlsext_tick_hmac_key, keys + 16, 16);\n                memcpy(ctx->tlsext_tick_aes_key, keys + 32, 16);\n            } else {\n                memcpy(keys, ctx->tlsext_tick_key_name, 16);\n                memcpy(keys + 16, ctx->tlsext_tick_hmac_key, 16);\n                memcpy(keys + 32, ctx->tlsext_tick_aes_key, 16);\n            }\n            return 1;\n        }\n    case SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG:\n        ctx->tlsext_status_arg = parg;\n        return 1;\n# ifndef OPENSSL_NO_SRP\n    case SSL_CTRL_SET_TLS_EXT_SRP_USERNAME:\n        ctx->srp_ctx.srp_Mask |= SSL_kSRP;\n        if (ctx->srp_ctx.login != NULL)\n            OPENSSL_free(ctx->srp_ctx.login);\n        ctx->srp_ctx.login = NULL;\n        if (parg == NULL)\n            break;\n        if (strlen((const char *)parg) > 255\n            || strlen((const char *)parg) < 1) {\n            SSLerr(SSL_F_SSL3_CTX_CTRL, SSL_R_INVALID_SRP_USERNAME);\n            return 0;\n        }\n        if ((ctx->srp_ctx.login = BUF_strdup((char *)parg)) == NULL) {\n            SSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_INTERNAL_ERROR);\n            return 0;\n        }\n        break;\n    case SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD:\n        ctx->srp_ctx.SRP_give_srp_client_pwd_callback =\n            srp_password_from_info_cb;\n        ctx->srp_ctx.info = parg;\n        break;\n    case SSL_CTRL_SET_SRP_ARG:\n        ctx->srp_ctx.srp_Mask |= SSL_kSRP;\n        ctx->srp_ctx.SRP_cb_arg = parg;\n        break;\n    case SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH:\n        ctx->srp_ctx.strength = larg;\n        break;\n# endif\n# ifndef OPENSSL_NO_EC\n    case SSL_CTRL_SET_CURVES:\n        return tls1_set_curves(&ctx->tlsext_ellipticcurvelist,\n                               &ctx->tlsext_ellipticcurvelist_length,\n                               parg, larg);\n    case SSL_CTRL_SET_CURVES_LIST:\n        return tls1_set_curves_list(&ctx->tlsext_ellipticcurvelist,\n                                    &ctx->tlsext_ellipticcurvelist_length,\n                                    parg);\n#  ifndef OPENSSL_NO_EC\n    case SSL_CTRL_SET_ECDH_AUTO:\n        ctx->cert->ecdh_tmp_auto = larg;\n        return 1;\n#  endif\n# endif\n    case SSL_CTRL_SET_SIGALGS:\n        return tls1_set_sigalgs(ctx->cert, parg, larg, 0);\n    case SSL_CTRL_SET_SIGALGS_LIST:\n        return tls1_set_sigalgs_list(ctx->cert, parg, 0);\n    case SSL_CTRL_SET_CLIENT_SIGALGS:\n        return tls1_set_sigalgs(ctx->cert, parg, larg, 1);\n    case SSL_CTRL_SET_CLIENT_SIGALGS_LIST:\n        return tls1_set_sigalgs_list(ctx->cert, parg, 1);\n    case SSL_CTRL_SET_CLIENT_CERT_TYPES:\n        return ssl3_set_req_cert_type(ctx->cert, parg, larg);\n    case SSL_CTRL_BUILD_CERT_CHAIN:\n        return ssl_build_cert_chain(NULL, ctx, larg);\n    case SSL_CTRL_SET_VERIFY_CERT_STORE:\n        return ssl_cert_set_cert_store(ctx->cert, parg, 0, larg);\n    case SSL_CTRL_SET_CHAIN_CERT_STORE:\n        return ssl_cert_set_cert_store(ctx->cert, parg, 1, larg);\n#endif\n    case SSL_CTRL_EXTRA_CHAIN_CERT:\n        if (ctx->extra_certs == NULL) {\n            if ((ctx->extra_certs = sk_X509_new_null()) == NULL)\n                return (0);\n        }\n        sk_X509_push(ctx->extra_certs, (X509 *)parg);\n        break;\n    case SSL_CTRL_GET_EXTRA_CHAIN_CERTS:\n        if (ctx->extra_certs == NULL && larg == 0)\n            *(STACK_OF(X509) **)parg = ctx->cert->key->chain;\n        else\n            *(STACK_OF(X509) **)parg = ctx->extra_certs;\n        break;\n    case SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS:\n        if (ctx->extra_certs) {\n            sk_X509_pop_free(ctx->extra_certs, X509_free);\n            ctx->extra_certs = NULL;\n        }\n        break;\n    case SSL_CTRL_CHAIN:\n        if (larg)\n            return ssl_cert_set1_chain(NULL, ctx, (STACK_OF(X509) *)parg);\n        else\n            return ssl_cert_set0_chain(NULL, ctx, (STACK_OF(X509) *)parg);\n    case SSL_CTRL_CHAIN_CERT:\n        if (larg)\n            return ssl_cert_add1_chain_cert(NULL, ctx, (X509 *)parg);\n        else\n            return ssl_cert_add0_chain_cert(NULL, ctx, (X509 *)parg);\n    case SSL_CTRL_GET_CHAIN_CERTS:\n        *(STACK_OF(X509) **)parg = ctx->cert->key->chain;\n        break;\n    case SSL_CTRL_SELECT_CURRENT_CERT:\n        return ssl_cert_select_current(ctx->cert, (X509 *)parg);\n    case SSL_CTRL_SET_CURRENT_CERT:\n        return ssl_cert_set_current(ctx->cert, larg);\n    default:\n        return (0);\n    }\n    return (1);\n}', 'DH *DHparams_dup(DH *dh)\n{\n    DH *ret;\n    ret = DH_new();\n    if (!ret)\n        return NULL;\n    if (!int_dh_param_copy(ret, dh, -1)) {\n        DH_free(ret);\n        return NULL;\n    }\n    return ret;\n}', 'DH *DH_new(void)\n{\n    return DH_new_method(NULL);\n}', 'DH *DH_new_method(ENGINE *engine)\n{\n    DH *ret;\n    ret = (DH *)OPENSSL_malloc(sizeof(DH));\n    if (ret == NULL) {\n        DHerr(DH_F_DH_NEW_METHOD, ERR_R_MALLOC_FAILURE);\n        return (NULL);\n    }\n    ret->meth = DH_get_default_method();\n#ifndef OPENSSL_NO_ENGINE\n    if (engine) {\n        if (!ENGINE_init(engine)) {\n            DHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB);\n            OPENSSL_free(ret);\n            return NULL;\n        }\n        ret->engine = engine;\n    } else\n        ret->engine = ENGINE_get_default_DH();\n    if (ret->engine) {\n        ret->meth = ENGINE_get_DH(ret->engine);\n        if (!ret->meth) {\n            DHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB);\n            ENGINE_finish(ret->engine);\n            OPENSSL_free(ret);\n            return NULL;\n        }\n    }\n#endif\n    ret->pad = 0;\n    ret->version = 0;\n    ret->p = NULL;\n    ret->g = NULL;\n    ret->length = 0;\n    ret->pub_key = NULL;\n    ret->priv_key = NULL;\n    ret->q = NULL;\n    ret->j = NULL;\n    ret->seed = NULL;\n    ret->seedlen = 0;\n    ret->counter = NULL;\n    ret->method_mont_p = NULL;\n    ret->references = 1;\n    ret->flags = ret->meth->flags;\n    CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data);\n    if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {\n#ifndef OPENSSL_NO_ENGINE\n        if (ret->engine)\n            ENGINE_finish(ret->engine);\n#endif\n        CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data);\n        OPENSSL_free(ret);\n        ret = NULL;\n    }\n    return (ret);\n}', 'ENGINE *ENGINE_get_default_DH(void)\n{\n    return engine_table_select(&dh_table, dummy_nid);\n}', 'ENGINE *engine_table_select(ENGINE_TABLE **table, int nid)\n#else\nENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f,\n                                int l)\n#endif\n{\n    ENGINE *ret = NULL;\n    ENGINE_PILE tmplate, *fnd = NULL;\n    int initres, loop = 0;\n    if (!(*table)) {\n#ifdef ENGINE_TABLE_DEBUG\n        fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, nothing "\n                "registered!\\n", f, l, nid);\n#endif\n        return NULL;\n    }\n    ERR_set_mark();\n    CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);\n    if (!int_table_check(table, 0))\n        goto end;\n    tmplate.nid = nid;\n    fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate);\n    if (!fnd)\n        goto end;\n    if (fnd->funct && engine_unlocked_init(fnd->funct)) {\n#ifdef ENGINE_TABLE_DEBUG\n        fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "\n                "ENGINE \'%s\' cached\\n", f, l, nid, fnd->funct->id);\n#endif\n        ret = fnd->funct;\n        goto end;\n    }\n    if (fnd->uptodate) {\n        ret = fnd->funct;\n        goto end;\n    }\n trynext:\n    ret = sk_ENGINE_value(fnd->sk, loop++);\n    if (!ret) {\n#ifdef ENGINE_TABLE_DEBUG\n        fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, no "\n                "registered implementations would initialise\\n", f, l, nid);\n#endif\n        goto end;\n    }\n    if ((ret->funct_ref > 0) || !(table_flags & ENGINE_TABLE_FLAG_NOINIT))\n        initres = engine_unlocked_init(ret);\n    else\n        initres = 0;\n    if (initres) {\n        if ((fnd->funct != ret) && engine_unlocked_init(ret)) {\n            if (fnd->funct)\n                engine_unlocked_finish(fnd->funct, 0);\n            fnd->funct = ret;\n#ifdef ENGINE_TABLE_DEBUG\n            fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, "\n                    "setting default to \'%s\'\\n", f, l, nid, ret->id);\n#endif\n        }\n#ifdef ENGINE_TABLE_DEBUG\n        fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "\n                "newly initialised \'%s\'\\n", f, l, nid, ret->id);\n#endif\n        goto end;\n    }\n    goto trynext;\n end:\n    if (fnd)\n        fnd->uptodate = 1;\n#ifdef ENGINE_TABLE_DEBUG\n    if (ret)\n        fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "\n                "ENGINE \'%s\'\\n", f, l, nid, ret->id);\n    else\n        fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "\n                "\'no matching ENGINE\'\\n", f, l, nid);\n#endif\n    CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);\n    ERR_pop_to_mark();\n    return ret;\n}', 'static int int_table_check(ENGINE_TABLE **t, int create)\n{\n    LHASH_OF(ENGINE_PILE) *lh;\n    if (*t)\n        return 1;\n    if (!create)\n        return 0;\n    if ((lh = lh_ENGINE_PILE_new()) == NULL)\n        return 0;\n    *t = (ENGINE_TABLE *)lh;\n    return 1;\n}', '_LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c)\n{\n    _LHASH *ret;\n    int i;\n    if ((ret = OPENSSL_malloc(sizeof(_LHASH))) == NULL)\n        goto err0;\n    if ((ret->b = OPENSSL_malloc(sizeof(LHASH_NODE *) * MIN_NODES)) == NULL)\n        goto err1;\n    for (i = 0; i < MIN_NODES; i++)\n        ret->b[i] = NULL;\n    ret->comp = ((c == NULL) ? (LHASH_COMP_FN_TYPE)strcmp : c);\n    ret->hash = ((h == NULL) ? (LHASH_HASH_FN_TYPE)lh_strhash : h);\n    ret->num_nodes = MIN_NODES / 2;\n    ret->num_alloc_nodes = MIN_NODES;\n    ret->p = 0;\n    ret->pmax = MIN_NODES / 2;\n    ret->up_load = UP_LOAD;\n    ret->down_load = DOWN_LOAD;\n    ret->num_items = 0;\n    ret->num_expands = 0;\n    ret->num_expand_reallocs = 0;\n    ret->num_contracts = 0;\n    ret->num_contract_reallocs = 0;\n    ret->num_hash_calls = 0;\n    ret->num_comp_calls = 0;\n    ret->num_insert = 0;\n    ret->num_replace = 0;\n    ret->num_delete = 0;\n    ret->num_no_delete = 0;\n    ret->num_retrieve = 0;\n    ret->num_retrieve_miss = 0;\n    ret->num_hash_comps = 0;\n    ret->error = 0;\n    return (ret);\n err1:\n    OPENSSL_free(ret);\n err0:\n    return (NULL);\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 = (SSL *)OPENSSL_malloc(sizeof(SSL));\n    if (s == NULL)\n        goto err;\n    memset(s, 0, sizeof(SSL));\n#ifndef OPENSSL_NO_KRB5\n    s->kssl_ctx = kssl_ctx_new();\n#endif\n    s->options = ctx->options;\n    s->mode = ctx->mode;\n    s->max_cert_list = ctx->max_cert_list;\n    s->cert = ssl_cert_dup(ctx->cert);\n    if (s->cert == NULL)\n        goto err;\n    s->read_ahead = 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)\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    CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX);\n    s->ctx = ctx;\n#ifndef OPENSSL_NO_TLSEXT\n    s->tlsext_debug_cb = 0;\n    s->tlsext_debug_arg = NULL;\n    s->tlsext_ticket_expected = 0;\n    s->tlsext_status_type = -1;\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    CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX);\n    s->initial_ctx = ctx;\n# ifndef OPENSSL_NO_EC\n    if (ctx->tlsext_ecpointformatlist) {\n        s->tlsext_ecpointformatlist =\n            BUF_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            BUF_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#endif\n    s->verify_result = X509_V_OK;\n    s->method = ctx->method;\n    if (!s->method->ssl_new(s))\n        goto err;\n    s->references = 1;\n    s->server = (ctx->method->ssl_accept == ssl_undefined_function) ? 0 : 1;\n    if(!SSL_clear(s))\n        goto err;\n    CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\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    return (s);\n err:\n    if (s != NULL)\n        SSL_free(s);\n    SSLerr(SSL_F_SSL_NEW, ERR_R_MALLOC_FAILURE);\n    return (NULL);\n}', 'int SSL_clear(SSL *s)\n{\n    if (s->method == NULL) {\n        SSLerr(SSL_F_SSL_CLEAR, SSL_R_NO_METHOD_SPECIFIED);\n        return (0);\n    }\n    if (ssl_clear_bad_session(s)) {\n        SSL_SESSION_free(s->session);\n        s->session = NULL;\n    }\n    s->error = 0;\n    s->hit = 0;\n    s->shutdown = 0;\n    if (s->renegotiate) {\n        SSLerr(SSL_F_SSL_CLEAR, ERR_R_INTERNAL_ERROR);\n        return 0;\n    }\n    s->type = 0;\n    s->state = SSL_ST_BEFORE | ((s->server) ? SSL_ST_ACCEPT : SSL_ST_CONNECT);\n    s->version = s->method->version;\n    s->client_version = s->version;\n    s->rwstate = SSL_NOTHING;\n    s->rstate = SSL_ST_READ_HEADER;\n    if (s->init_buf != NULL) {\n        BUF_MEM_free(s->init_buf);\n        s->init_buf = NULL;\n    }\n    ssl_clear_cipher_ctx(s);\n    ssl_clear_hash_ctx(&s->read_hash);\n    ssl_clear_hash_ctx(&s->write_hash);\n    s->first_packet = 0;\n    if (!s->in_handshake && (s->session == NULL)\n        && (s->method != s->ctx->method)) {\n        s->method->ssl_free(s);\n        s->method = s->ctx->method;\n        if (!s->method->ssl_new(s))\n            return (0);\n    } else\n        s->method->ssl_clear(s);\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->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_w_lock(CRYPTO_LOCK_SSL_CTX);\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        if (lck)\n            CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n        if (ret) {\n            r->not_resumable = 1;\n            if (ctx->remove_session_cb != NULL)\n                ctx->remove_session_cb(ctx, r);\n            SSL_SESSION_free(r);\n        }\n    } else\n        ret = 0;\n    return (ret);\n}', 'void *lh_delete(_LHASH *lh, const void *data)\n{\n    unsigned long hash;\n    LHASH_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}']