apps/req.c:397: error: BUFFER_OVERRUN_L3
  Offset added: [272, +oo] (⇐ [16, +oo] + [256, +oo]) Size: [1, +oo] by call to `duplicated`.
Showing all 17 steps of the trace


apps/req.c:392:27: Call
390.               p = opt_arg();
391.               if (addexts == NULL) {
392.                   addexts = lh_OPENSSL_STRING_new(ext_name_hash, ext_name_cmp);
                                 ^
393.                   addext_bio = BIO_new(BIO_s_mem());
394.                   if (addexts == NULL || addext_bio == NULL)

include/openssl/lhash.h:197:1: Call
  195.       LHASH_OF(type)
  196.   
  197. > DEFINE_LHASH_OF(OPENSSL_STRING);
  198.   # ifdef _MSC_VER
  199.   /*

crypto/lhash/lhash.c:62:5: Assignment
    60.       ret->hash = ((h == NULL) ? (OPENSSL_LH_HASHFUNC)OPENSSL_LH_strhash : h);
    61.       ret->num_nodes = MIN_NODES / 2;
    62.       ret->num_alloc_nodes = MIN_NODES;
              ^
    63.       ret->pmax = MIN_NODES / 2;
    64.       ret->up_load = UP_LOAD;

apps/req.c:397:17: Call
395.                       goto end;
396.               }
397.               i = duplicated(addexts, p);
                       ^
398.               if (i == 1)
399.                   goto opthelp;

apps/req.c:176:1: Parameter `addexts->num_alloc_nodes`
  174.    * error.
  175.    */
  176. > static int duplicated(LHASH_OF(OPENSSL_STRING) *addexts, char *kv)
  177.   {
  178.       char *p;

apps/req.c:203:22: Call
  201.   
  202.       /* Finally have a clean "key"; see if it's there [by attempt to add it]. */
  203.       if ((p = (char *)lh_OPENSSL_STRING_insert(addexts, (OPENSSL_STRING*)kv))
                              ^
  204.           != NULL || lh_OPENSSL_STRING_error(addexts)) {
  205.           OPENSSL_free(p != NULL ? p : kv);

include/openssl/lhash.h:197:1: Parameter `lh->num_alloc_nodes`
    195.       LHASH_OF(type)
    196.   
    197. > DEFINE_LHASH_OF(OPENSSL_STRING);
    198.   # ifdef _MSC_VER
    199.   /*

include/openssl/lhash.h:197:1: Call
    195.       LHASH_OF(type)
    196.   
    197. > DEFINE_LHASH_OF(OPENSSL_STRING);
    198.   # ifdef _MSC_VER
    199.   /*

crypto/lhash/lhash.c:94:1: Parameter `lh->num_alloc_nodes`
      92.   }
      93.   
      94. > void *OPENSSL_LH_insert(OPENSSL_LHASH *lh, void *data)
      95.   {
      96.       unsigned long hash;

crypto/lhash/lhash.c:101:77: Call
      99.   
      100.       lh->error = 0;
      101.       if ((lh->up_load <= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)) && !expand(lh))
                                                                                         ^
      102.           return NULL;        /* 'lh->error++' already done in 'expand' */
      103.   

crypto/lhash/lhash.c:210:1: <Offset trace>
208.   }
209.   
210. > static int expand(OPENSSL_LHASH *lh)
211.   {
212.       OPENSSL_LH_NODE **n, **n1, **n2, *np;

crypto/lhash/lhash.c:210:1: Parameter `lh->num_alloc_nodes`
        208.   }
        209.   
        210. > static int expand(OPENSSL_LHASH *lh)
        211.   {
        212.       OPENSSL_LH_NODE **n, **n1, **n2, *np;

crypto/lhash/lhash.c:216:5: Assignment
        214.       unsigned long hash;
        215.   
        216.       nni = lh->num_alloc_nodes;
                   ^
        217.       p = lh->p;
        218.       pmax = lh->pmax;

crypto/lhash/lhash.c:210:1: <Length trace>
208.   }
209.   
210. > static int expand(OPENSSL_LHASH *lh)
211.   {
212.       OPENSSL_LH_NODE **n, **n1, **n2, *np;

crypto/lhash/lhash.c:210:1: Parameter `lh->num_alloc_nodes`
        208.   }
        209.   
        210. > static int expand(OPENSSL_LHASH *lh)
        211.   {
        212.       OPENSSL_LH_NODE **n, **n1, **n2, *np;

crypto/lhash/lhash.c:216:5: Assignment
        214.       unsigned long hash;
        215.   
        216.       nni = lh->num_alloc_nodes;
                   ^
        217.       p = lh->p;
        218.       pmax = lh->pmax;

crypto/lhash/lhash.c:227:9: Array access: Offset added: [272, +oo] (⇐ [16, +oo] + [256, +oo]) Size: [1, +oo] by call to `duplicated` 
        225.           }
        226.           lh->b = n;
        227.           memset(n + nni, 0, sizeof(*n) * (j - nni));
                       ^
        228.           lh->pmax = nni;
        229.           lh->num_alloc_nodes = j;

static int expand(OPENSSL_LHASH *lh)
{
    OPENSSL_LH_NODE **n, **n1, **n2, *np;
    unsigned int p, pmax, nni, j;
    unsigned long hash;
    nni = lh->num_alloc_nodes;
    p = lh->p;
    pmax = lh->pmax;
    if (p + 1 >= pmax) {
        j = nni * 2;
        n = OPENSSL_realloc(lh->b, sizeof(OPENSSL_LH_NODE *) * j);
        if (n == NULL) {
            lh->error++;
            return 0;
        }
        lh->b = n;
        memset(n + nni, 0, sizeof(*n) * (j - nni));
        lh->pmax = nni;
        lh->num_alloc_nodes = j;
        lh->num_expand_reallocs++;
        lh->p = 0;
    } else {
        lh->p++;
    }
    lh->num_nodes++;
    lh->num_expands++;
    n1 = &(lh->b[p]);
    n2 = &(lh->b[p + pmax]);
    *n2 = NULL;
    for (np = *n1; np != NULL;) {
        hash = np->hash;
        if ((hash % nni) != p) {
            *n1 = (*n1)->next;
            np->next = *n2;
            *n2 = np;
        } else
            n1 = &((*n1)->next);
        np = *n1;
    }
    return 1;
}
['int req_main(int argc, char **argv)\n{\n    ASN1_INTEGER *serial = NULL;\n    BIO *in = NULL, *out = NULL;\n    ENGINE *e = NULL, *gen_eng = NULL;\n    EVP_PKEY *pkey = NULL;\n    EVP_PKEY_CTX *genctx = NULL;\n    STACK_OF(OPENSSL_STRING) *pkeyopts = NULL, *sigopts = NULL;\n    LHASH_OF(OPENSSL_STRING) *addexts = NULL;\n    X509 *x509ss = NULL;\n    X509_REQ *req = NULL;\n    const EVP_CIPHER *cipher = NULL;\n    const EVP_MD *md_alg = NULL, *digest = NULL;\n    BIO *addext_bio = NULL;\n    char *extensions = NULL, *infile = NULL;\n    char *outfile = NULL, *keyfile = NULL;\n    char *keyalgstr = NULL, *p, *prog, *passargin = NULL, *passargout = NULL;\n    char *passin = NULL, *passout = NULL;\n    char *nofree_passin = NULL, *nofree_passout = NULL;\n    char *req_exts = NULL, *subj = NULL;\n    char *template = default_config_file, *keyout = NULL;\n    const char *keyalg = NULL;\n    OPTION_CHOICE o;\n    int ret = 1, x509 = 0, days = 0, i = 0, newreq = 0, verbose = 0;\n    int pkey_type = -1, private = 0;\n    int informat = FORMAT_PEM, outformat = FORMAT_PEM, keyform = FORMAT_PEM;\n    int modulus = 0, multirdn = 0, verify = 0, noout = 0, text = 0;\n    int nodes = 0, newhdr = 0, subject = 0, pubkey = 0, precert = 0;\n    long newkey = -1;\n    unsigned long chtype = MBSTRING_ASC, reqflag = 0;\n#ifndef OPENSSL_NO_DES\n    cipher = EVP_des_ede3_cbc();\n#endif\n    prog = opt_init(argc, argv, req_options);\n    while ((o = opt_next()) != OPT_EOF) {\n        switch (o) {\n        case OPT_EOF:\n        case OPT_ERR:\n opthelp:\n            BIO_printf(bio_err, "%s: Use -help for summary.\\n", prog);\n            goto end;\n        case OPT_HELP:\n            opt_help(req_options);\n            ret = 0;\n            goto end;\n        case OPT_INFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &informat))\n                goto opthelp;\n            break;\n        case OPT_OUTFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &outformat))\n                goto opthelp;\n            break;\n        case OPT_ENGINE:\n            e = setup_engine(opt_arg(), 0);\n            break;\n        case OPT_KEYGEN_ENGINE:\n#ifndef OPENSSL_NO_ENGINE\n            gen_eng = ENGINE_by_id(opt_arg());\n            if (gen_eng == NULL) {\n                BIO_printf(bio_err, "Can\'t find keygen engine %s\\n", *argv);\n                goto opthelp;\n            }\n#endif\n            break;\n        case OPT_KEY:\n            keyfile = opt_arg();\n            break;\n        case OPT_PUBKEY:\n            pubkey = 1;\n            break;\n        case OPT_NEW:\n            newreq = 1;\n            break;\n        case OPT_CONFIG:\n            template = opt_arg();\n            break;\n        case OPT_KEYFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_ANY, &keyform))\n                goto opthelp;\n            break;\n        case OPT_IN:\n            infile = opt_arg();\n            break;\n        case OPT_OUT:\n            outfile = opt_arg();\n            break;\n        case OPT_KEYOUT:\n            keyout = opt_arg();\n            break;\n        case OPT_PASSIN:\n            passargin = opt_arg();\n            break;\n        case OPT_PASSOUT:\n            passargout = opt_arg();\n            break;\n        case OPT_R_CASES:\n            if (!opt_rand(o))\n                goto end;\n            break;\n        case OPT_NEWKEY:\n            keyalg = opt_arg();\n            newreq = 1;\n            break;\n        case OPT_PKEYOPT:\n            if (!pkeyopts)\n                pkeyopts = sk_OPENSSL_STRING_new_null();\n            if (!pkeyopts || !sk_OPENSSL_STRING_push(pkeyopts, opt_arg()))\n                goto opthelp;\n            break;\n        case OPT_SIGOPT:\n            if (!sigopts)\n                sigopts = sk_OPENSSL_STRING_new_null();\n            if (!sigopts || !sk_OPENSSL_STRING_push(sigopts, opt_arg()))\n                goto opthelp;\n            break;\n        case OPT_BATCH:\n            batch = 1;\n            break;\n        case OPT_NEWHDR:\n            newhdr = 1;\n            break;\n        case OPT_MODULUS:\n            modulus = 1;\n            break;\n        case OPT_VERIFY:\n            verify = 1;\n            break;\n        case OPT_NODES:\n            nodes = 1;\n            break;\n        case OPT_NOOUT:\n            noout = 1;\n            break;\n        case OPT_VERBOSE:\n            verbose = 1;\n            break;\n        case OPT_UTF8:\n            chtype = MBSTRING_UTF8;\n            break;\n        case OPT_NAMEOPT:\n            if (!set_nameopt(opt_arg()))\n                goto opthelp;\n            break;\n        case OPT_REQOPT:\n            if (!set_cert_ex(&reqflag, opt_arg()))\n                goto opthelp;\n            break;\n        case OPT_TEXT:\n            text = 1;\n            break;\n        case OPT_X509:\n            x509 = 1;\n            break;\n        case OPT_DAYS:\n            days = atoi(opt_arg());\n            break;\n        case OPT_SET_SERIAL:\n            if (serial != NULL) {\n                BIO_printf(bio_err, "Serial number supplied twice\\n");\n                goto opthelp;\n            }\n            serial = s2i_ASN1_INTEGER(NULL, opt_arg());\n            if (serial == NULL)\n                goto opthelp;\n            break;\n        case OPT_SUBJECT:\n            subject = 1;\n            break;\n        case OPT_SUBJ:\n            subj = opt_arg();\n            break;\n        case OPT_MULTIVALUE_RDN:\n            multirdn = 1;\n            break;\n        case OPT_ADDEXT:\n            p = opt_arg();\n            if (addexts == NULL) {\n                addexts = lh_OPENSSL_STRING_new(ext_name_hash, ext_name_cmp);\n                addext_bio = BIO_new(BIO_s_mem());\n                if (addexts == NULL || addext_bio == NULL)\n                    goto end;\n            }\n            i = duplicated(addexts, p);\n            if (i == 1)\n                goto opthelp;\n            if (i < 0 || BIO_printf(addext_bio, "%s\\n", opt_arg()) < 0)\n                goto end;\n            break;\n        case OPT_EXTENSIONS:\n            extensions = opt_arg();\n            break;\n        case OPT_REQEXTS:\n            req_exts = opt_arg();\n            break;\n        case OPT_PRECERT:\n            newreq = precert = 1;\n            break;\n        case OPT_MD:\n            if (!opt_md(opt_unknown(), &md_alg))\n                goto opthelp;\n            digest = md_alg;\n            break;\n        }\n    }\n    argc = opt_num_rest();\n    if (argc != 0)\n        goto opthelp;\n    if (days && !x509)\n        BIO_printf(bio_err, "Ignoring -days; not generating a certificate\\n");\n    if (x509 && infile == NULL)\n        newreq = 1;\n    private = newreq && (pkey == NULL) ? 1 : 0;\n    if (!app_passwd(passargin, passargout, &passin, &passout)) {\n        BIO_printf(bio_err, "Error getting passwords\\n");\n        goto end;\n    }\n    if (verbose)\n        BIO_printf(bio_err, "Using configuration from %s\\n", template);\n    req_conf = app_load_config(template);\n    if (addext_bio) {\n        if (verbose)\n            BIO_printf(bio_err,\n                       "Using additional configuration from command line\\n");\n        addext_conf = app_load_config_bio(addext_bio, NULL);\n    }\n    if (template != default_config_file && !app_load_modules(req_conf))\n        goto end;\n    if (req_conf != NULL) {\n        p = NCONF_get_string(req_conf, NULL, "oid_file");\n        if (p == NULL)\n            ERR_clear_error();\n        if (p != NULL) {\n            BIO *oid_bio;\n            oid_bio = BIO_new_file(p, "r");\n            if (oid_bio == NULL) {\n            } else {\n                OBJ_create_objects(oid_bio);\n                BIO_free(oid_bio);\n            }\n        }\n    }\n    if (!add_oid_section(req_conf))\n        goto end;\n    if (md_alg == NULL) {\n        p = NCONF_get_string(req_conf, SECTION, "default_md");\n        if (p == NULL) {\n            ERR_clear_error();\n        } else {\n            if (!opt_md(p, &md_alg))\n                goto opthelp;\n            digest = md_alg;\n        }\n    }\n    if (extensions == NULL) {\n        extensions = NCONF_get_string(req_conf, SECTION, V3_EXTENSIONS);\n        if (extensions == NULL)\n            ERR_clear_error();\n    }\n    if (extensions != NULL) {\n        X509V3_CTX ctx;\n        X509V3_set_ctx_test(&ctx);\n        X509V3_set_nconf(&ctx, req_conf);\n        if (!X509V3_EXT_add_nconf(req_conf, &ctx, extensions, NULL)) {\n            BIO_printf(bio_err,\n                       "Error Loading extension section %s\\n", extensions);\n            goto end;\n        }\n    }\n    if (addext_conf != NULL) {\n        X509V3_CTX ctx;\n        X509V3_set_ctx_test(&ctx);\n        X509V3_set_nconf(&ctx, addext_conf);\n        if (!X509V3_EXT_add_nconf(addext_conf, &ctx, "default", NULL)) {\n            BIO_printf(bio_err, "Error Loading command line extensions\\n");\n            goto end;\n        }\n    }\n    if (passin == NULL) {\n        passin = nofree_passin =\n            NCONF_get_string(req_conf, SECTION, "input_password");\n        if (passin == NULL)\n            ERR_clear_error();\n    }\n    if (passout == NULL) {\n        passout = nofree_passout =\n            NCONF_get_string(req_conf, SECTION, "output_password");\n        if (passout == NULL)\n            ERR_clear_error();\n    }\n    p = NCONF_get_string(req_conf, SECTION, STRING_MASK);\n    if (p == NULL)\n        ERR_clear_error();\n    if (p != NULL && !ASN1_STRING_set_default_mask_asc(p)) {\n        BIO_printf(bio_err, "Invalid global string mask setting %s\\n", p);\n        goto end;\n    }\n    if (chtype != MBSTRING_UTF8) {\n        p = NCONF_get_string(req_conf, SECTION, UTF8_IN);\n        if (p == NULL)\n            ERR_clear_error();\n        else if (strcmp(p, "yes") == 0)\n            chtype = MBSTRING_UTF8;\n    }\n    if (req_exts == NULL) {\n        req_exts = NCONF_get_string(req_conf, SECTION, REQ_EXTENSIONS);\n        if (req_exts == NULL)\n            ERR_clear_error();\n    }\n    if (req_exts != NULL) {\n        X509V3_CTX ctx;\n        X509V3_set_ctx_test(&ctx);\n        X509V3_set_nconf(&ctx, req_conf);\n        if (!X509V3_EXT_add_nconf(req_conf, &ctx, req_exts, NULL)) {\n            BIO_printf(bio_err,\n                       "Error Loading request extension section %s\\n",\n                       req_exts);\n            goto end;\n        }\n    }\n    if (keyfile != NULL) {\n        pkey = load_key(keyfile, keyform, 0, passin, e, "Private Key");\n        if (pkey == NULL) {\n            goto end;\n        } else {\n            app_RAND_load_conf(req_conf, SECTION);\n        }\n    }\n    if (newreq && (pkey == NULL)) {\n        app_RAND_load_conf(req_conf, SECTION);\n        if (!NCONF_get_number(req_conf, SECTION, BITS, &newkey)) {\n            newkey = DEFAULT_KEY_LENGTH;\n        }\n        if (keyalg != NULL) {\n            genctx = set_keygen_ctx(keyalg, &pkey_type, &newkey,\n                                    &keyalgstr, gen_eng);\n            if (genctx == NULL)\n                goto end;\n        }\n        if (newkey < MIN_KEY_LENGTH\n            && (pkey_type == EVP_PKEY_RSA || pkey_type == EVP_PKEY_DSA)) {\n            BIO_printf(bio_err, "private key length is too short,\\n");\n            BIO_printf(bio_err, "it needs to be at least %d bits, not %ld\\n",\n                       MIN_KEY_LENGTH, newkey);\n            goto end;\n        }\n        if (pkey_type == EVP_PKEY_RSA && newkey > OPENSSL_RSA_MAX_MODULUS_BITS)\n            BIO_printf(bio_err,\n                       "Warning: It is not recommended to use more than %d bit for RSA keys.\\n"\n                       "         Your key size is %ld! Larger key size may behave not as expected.\\n",\n                       OPENSSL_RSA_MAX_MODULUS_BITS, newkey);\n#ifndef OPENSSL_NO_DSA\n        if (pkey_type == EVP_PKEY_DSA && newkey > OPENSSL_DSA_MAX_MODULUS_BITS)\n            BIO_printf(bio_err,\n                       "Warning: It is not recommended to use more than %d bit for DSA keys.\\n"\n                       "         Your key size is %ld! Larger key size may behave not as expected.\\n",\n                       OPENSSL_DSA_MAX_MODULUS_BITS, newkey);\n#endif\n        if (genctx == NULL) {\n            genctx = set_keygen_ctx(NULL, &pkey_type, &newkey,\n                                    &keyalgstr, gen_eng);\n            if (!genctx)\n                goto end;\n        }\n        if (pkeyopts != NULL) {\n            char *genopt;\n            for (i = 0; i < sk_OPENSSL_STRING_num(pkeyopts); i++) {\n                genopt = sk_OPENSSL_STRING_value(pkeyopts, i);\n                if (pkey_ctrl_string(genctx, genopt) <= 0) {\n                    BIO_printf(bio_err, "parameter error \\"%s\\"\\n", genopt);\n                    ERR_print_errors(bio_err);\n                    goto end;\n                }\n            }\n        }\n        if (pkey_type == EVP_PKEY_EC) {\n            BIO_printf(bio_err, "Generating an EC private key\\n");\n        } else {\n            BIO_printf(bio_err, "Generating a %ld bit %s private key\\n",\n                       newkey, keyalgstr);\n        }\n        EVP_PKEY_CTX_set_cb(genctx, genpkey_cb);\n        EVP_PKEY_CTX_set_app_data(genctx, bio_err);\n        if (EVP_PKEY_keygen(genctx, &pkey) <= 0) {\n            BIO_puts(bio_err, "Error Generating Key\\n");\n            goto end;\n        }\n        EVP_PKEY_CTX_free(genctx);\n        genctx = NULL;\n        if (keyout == NULL) {\n            keyout = NCONF_get_string(req_conf, SECTION, KEYFILE);\n            if (keyout == NULL)\n                ERR_clear_error();\n        }\n        if (keyout == NULL)\n            BIO_printf(bio_err, "writing new private key to stdout\\n");\n        else\n            BIO_printf(bio_err, "writing new private key to \'%s\'\\n", keyout);\n        out = bio_open_owner(keyout, outformat, private);\n        if (out == NULL)\n            goto end;\n        p = NCONF_get_string(req_conf, SECTION, "encrypt_rsa_key");\n        if (p == NULL) {\n            ERR_clear_error();\n            p = NCONF_get_string(req_conf, SECTION, "encrypt_key");\n            if (p == NULL)\n                ERR_clear_error();\n        }\n        if ((p != NULL) && (strcmp(p, "no") == 0))\n            cipher = NULL;\n        if (nodes)\n            cipher = NULL;\n        i = 0;\n loop:\n        assert(private);\n        if (!PEM_write_bio_PrivateKey(out, pkey, cipher,\n                                      NULL, 0, NULL, passout)) {\n            if ((ERR_GET_REASON(ERR_peek_error()) ==\n                 PEM_R_PROBLEMS_GETTING_PASSWORD) && (i < 3)) {\n                ERR_clear_error();\n                i++;\n                goto loop;\n            }\n            goto end;\n        }\n        BIO_free(out);\n        out = NULL;\n        BIO_printf(bio_err, "-----\\n");\n    }\n    if (!newreq) {\n        in = bio_open_default(infile, \'r\', informat);\n        if (in == NULL)\n            goto end;\n        if (informat == FORMAT_ASN1)\n            req = d2i_X509_REQ_bio(in, NULL);\n        else\n            req = PEM_read_bio_X509_REQ(in, NULL, NULL, NULL);\n        if (req == NULL) {\n            BIO_printf(bio_err, "unable to load X509 request\\n");\n            goto end;\n        }\n    }\n    if (newreq || x509) {\n        if (pkey == NULL) {\n            BIO_printf(bio_err, "you need to specify a private key\\n");\n            goto end;\n        }\n        if (req == NULL) {\n            req = X509_REQ_new();\n            if (req == NULL) {\n                goto end;\n            }\n            i = make_REQ(req, pkey, subj, multirdn, !x509, chtype);\n            subj = NULL;\n            if (!i) {\n                BIO_printf(bio_err, "problems making Certificate Request\\n");\n                goto end;\n            }\n        }\n        if (x509) {\n            EVP_PKEY *tmppkey;\n            X509V3_CTX ext_ctx;\n            if ((x509ss = X509_new()) == NULL)\n                goto end;\n            if ((extensions != NULL || addext_conf != NULL)\n                && !X509_set_version(x509ss, 2))\n                goto end;\n            if (serial != NULL) {\n                if (!X509_set_serialNumber(x509ss, serial))\n                    goto end;\n            } else {\n                if (!rand_serial(NULL, X509_get_serialNumber(x509ss)))\n                    goto end;\n            }\n            if (!X509_set_issuer_name(x509ss, X509_REQ_get_subject_name(req)))\n                goto end;\n            if (days == 0) {\n                days = 30;\n            }\n            if (!set_cert_times(x509ss, NULL, NULL, days))\n                goto end;\n            if (!X509_set_subject_name\n                (x509ss, X509_REQ_get_subject_name(req)))\n                goto end;\n            tmppkey = X509_REQ_get0_pubkey(req);\n            if (!tmppkey || !X509_set_pubkey(x509ss, tmppkey))\n                goto end;\n            X509V3_set_ctx(&ext_ctx, x509ss, x509ss, NULL, NULL, 0);\n            X509V3_set_nconf(&ext_ctx, req_conf);\n            if (extensions != NULL && !X509V3_EXT_add_nconf(req_conf,\n                                                            &ext_ctx, extensions,\n                                                            x509ss)) {\n                BIO_printf(bio_err, "Error Loading extension section %s\\n",\n                           extensions);\n                goto end;\n            }\n            if (addext_conf != NULL\n                && !X509V3_EXT_add_nconf(addext_conf, &ext_ctx, "default",\n                                         x509ss)) {\n                BIO_printf(bio_err, "Error Loading command line extensions\\n");\n                goto end;\n            }\n            if (precert) {\n                if (X509_add1_ext_i2d(x509ss, NID_ct_precert_poison, NULL, 1, 0)\n                    != 1) {\n                    BIO_printf(bio_err, "Error adding poison extension\\n");\n                    goto end;\n                }\n            }\n            i = do_X509_sign(x509ss, pkey, digest, sigopts);\n            if (!i) {\n                ERR_print_errors(bio_err);\n                goto end;\n            }\n        } else {\n            X509V3_CTX ext_ctx;\n            X509V3_set_ctx(&ext_ctx, NULL, NULL, req, NULL, 0);\n            X509V3_set_nconf(&ext_ctx, req_conf);\n            if (req_exts != NULL\n                && !X509V3_EXT_REQ_add_nconf(req_conf, &ext_ctx,\n                                             req_exts, req)) {\n                BIO_printf(bio_err, "Error Loading extension section %s\\n",\n                           req_exts);\n                goto end;\n            }\n            if (addext_conf != NULL\n                && !X509V3_EXT_REQ_add_nconf(addext_conf, &ext_ctx, "default",\n                                             req)) {\n                BIO_printf(bio_err, "Error Loading command line extensions\\n");\n                goto end;\n            }\n            i = do_X509_REQ_sign(req, pkey, digest, sigopts);\n            if (!i) {\n                ERR_print_errors(bio_err);\n                goto end;\n            }\n        }\n    }\n    if (subj && x509) {\n        BIO_printf(bio_err, "Cannot modify certificate subject\\n");\n        goto end;\n    }\n    if (subj && !x509) {\n        if (verbose) {\n            BIO_printf(bio_err, "Modifying Request\'s Subject\\n");\n            print_name(bio_err, "old subject=",\n                       X509_REQ_get_subject_name(req), get_nameopt());\n        }\n        if (build_subject(req, subj, chtype, multirdn) == 0) {\n            BIO_printf(bio_err, "ERROR: cannot modify subject\\n");\n            ret = 1;\n            goto end;\n        }\n        if (verbose) {\n            print_name(bio_err, "new subject=",\n                       X509_REQ_get_subject_name(req), get_nameopt());\n        }\n    }\n    if (verify && !x509) {\n        EVP_PKEY *tpubkey = pkey;\n        if (tpubkey == NULL) {\n            tpubkey = X509_REQ_get0_pubkey(req);\n            if (tpubkey == NULL)\n                goto end;\n        }\n        i = X509_REQ_verify(req, tpubkey);\n        if (i < 0) {\n            goto end;\n        } else if (i == 0) {\n            BIO_printf(bio_err, "verify failure\\n");\n            ERR_print_errors(bio_err);\n        } else {\n            BIO_printf(bio_err, "verify OK\\n");\n        }\n    }\n    if (noout && !text && !modulus && !subject && !pubkey) {\n        ret = 0;\n        goto end;\n    }\n    out = bio_open_default(outfile,\n                           keyout != NULL && outfile != NULL &&\n                           strcmp(keyout, outfile) == 0 ? \'a\' : \'w\',\n                           outformat);\n    if (out == NULL)\n        goto end;\n    if (pubkey) {\n        EVP_PKEY *tpubkey = X509_REQ_get0_pubkey(req);\n        if (tpubkey == NULL) {\n            BIO_printf(bio_err, "Error getting public key\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        PEM_write_bio_PUBKEY(out, tpubkey);\n    }\n    if (text) {\n        if (x509)\n            X509_print_ex(out, x509ss, get_nameopt(), reqflag);\n        else\n            X509_REQ_print_ex(out, req, get_nameopt(), reqflag);\n    }\n    if (subject) {\n        if (x509)\n            print_name(out, "subject=", X509_get_subject_name(x509ss),\n                       get_nameopt());\n        else\n            print_name(out, "subject=", X509_REQ_get_subject_name(req),\n                       get_nameopt());\n    }\n    if (modulus) {\n        EVP_PKEY *tpubkey;\n        if (x509)\n            tpubkey = X509_get0_pubkey(x509ss);\n        else\n            tpubkey = X509_REQ_get0_pubkey(req);\n        if (tpubkey == NULL) {\n            fprintf(stdout, "Modulus=unavailable\\n");\n            goto end;\n        }\n        fprintf(stdout, "Modulus=");\n#ifndef OPENSSL_NO_RSA\n        if (EVP_PKEY_base_id(tpubkey) == EVP_PKEY_RSA) {\n            const BIGNUM *n;\n            RSA_get0_key(EVP_PKEY_get0_RSA(tpubkey), &n, NULL, NULL);\n            BN_print(out, n);\n        } else\n#endif\n            fprintf(stdout, "Wrong Algorithm type");\n        fprintf(stdout, "\\n");\n    }\n    if (!noout && !x509) {\n        if (outformat == FORMAT_ASN1)\n            i = i2d_X509_REQ_bio(out, req);\n        else if (newhdr)\n            i = PEM_write_bio_X509_REQ_NEW(out, req);\n        else\n            i = PEM_write_bio_X509_REQ(out, req);\n        if (!i) {\n            BIO_printf(bio_err, "unable to write X509 request\\n");\n            goto end;\n        }\n    }\n    if (!noout && x509 && (x509ss != NULL)) {\n        if (outformat == FORMAT_ASN1)\n            i = i2d_X509_bio(out, x509ss);\n        else\n            i = PEM_write_bio_X509(out, x509ss);\n        if (!i) {\n            BIO_printf(bio_err, "unable to write X509 certificate\\n");\n            goto end;\n        }\n    }\n    ret = 0;\n end:\n    if (ret) {\n        ERR_print_errors(bio_err);\n    }\n    NCONF_free(req_conf);\n    NCONF_free(addext_conf);\n    BIO_free(addext_bio);\n    BIO_free(in);\n    BIO_free_all(out);\n    EVP_PKEY_free(pkey);\n    EVP_PKEY_CTX_free(genctx);\n    sk_OPENSSL_STRING_free(pkeyopts);\n    sk_OPENSSL_STRING_free(sigopts);\n    lh_OPENSSL_STRING_doall(addexts, exts_cleanup);\n    lh_OPENSSL_STRING_free(addexts);\n#ifndef OPENSSL_NO_ENGINE\n    ENGINE_free(gen_eng);\n#endif\n    OPENSSL_free(keyalgstr);\n    X509_REQ_free(req);\n    X509_free(x509ss);\n    ASN1_INTEGER_free(serial);\n    release_engine(e);\n    if (passin != nofree_passin)\n        OPENSSL_free(passin);\n    if (passout != nofree_passout)\n        OPENSSL_free(passout);\n    return ret;\n}', 'OPENSSL_LHASH *OPENSSL_LH_new(OPENSSL_LH_HASHFUNC h, OPENSSL_LH_COMPFUNC c)\n{\n    OPENSSL_LHASH *ret;\n    if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL) {\n        return NULL;\n    }\n    if ((ret->b = OPENSSL_zalloc(sizeof(*ret->b) * MIN_NODES)) == NULL)\n        goto err;\n    ret->comp = ((c == NULL) ? (OPENSSL_LH_COMPFUNC)strcmp : c);\n    ret->hash = ((h == NULL) ? (OPENSSL_LH_HASHFUNC)OPENSSL_LH_strhash : h);\n    ret->num_nodes = MIN_NODES / 2;\n    ret->num_alloc_nodes = MIN_NODES;\n    ret->pmax = MIN_NODES / 2;\n    ret->up_load = UP_LOAD;\n    ret->down_load = DOWN_LOAD;\n    return ret;\nerr:\n    OPENSSL_free(ret->b);\n    OPENSSL_free(ret);\n    return NULL;\n}', "static int duplicated(LHASH_OF(OPENSSL_STRING) *addexts, char *kv)\n{\n    char *p;\n    size_t off;\n    while (*kv && isspace(*kv))\n        if (*++kv == '\\0')\n            return 1;\n    if ((p = strchr(kv, '=')) == NULL)\n        return 1;\n    off = p - kv;\n    if ((kv = OPENSSL_strdup(kv)) == NULL)\n        return -1;\n    for (p = kv + off; p > kv; --p)\n        if (!isspace(p[-1]))\n            break;\n    if (p == kv) {\n        OPENSSL_free(kv);\n        return 1;\n    }\n    *p = '\\0';\n    if ((p = (char *)lh_OPENSSL_STRING_insert(addexts, (OPENSSL_STRING*)kv))\n        != NULL || lh_OPENSSL_STRING_error(addexts)) {\n        OPENSSL_free(p != NULL ? p : kv);\n        return -1;\n    }\n    return 0;\n}", 'void *OPENSSL_LH_insert(OPENSSL_LHASH *lh, void *data)\n{\n    unsigned long hash;\n    OPENSSL_LH_NODE *nn, **rn;\n    void *ret;\n    lh->error = 0;\n    if ((lh->up_load <= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)) && !expand(lh))\n        return NULL;\n    rn = getrn(lh, data, &hash);\n    if (*rn == NULL) {\n        if ((nn = OPENSSL_malloc(sizeof(*nn))) == NULL) {\n            lh->error++;\n            return NULL;\n        }\n        nn->data = data;\n        nn->next = NULL;\n        nn->hash = hash;\n        *rn = nn;\n        ret = NULL;\n        lh->num_insert++;\n        lh->num_items++;\n    } else {\n        ret = (*rn)->data;\n        (*rn)->data = data;\n        lh->num_replace++;\n    }\n    return ret;\n}', 'static int expand(OPENSSL_LHASH *lh)\n{\n    OPENSSL_LH_NODE **n, **n1, **n2, *np;\n    unsigned int p, pmax, nni, j;\n    unsigned long hash;\n    nni = lh->num_alloc_nodes;\n    p = lh->p;\n    pmax = lh->pmax;\n    if (p + 1 >= pmax) {\n        j = nni * 2;\n        n = OPENSSL_realloc(lh->b, sizeof(OPENSSL_LH_NODE *) * j);\n        if (n == NULL) {\n            lh->error++;\n            return 0;\n        }\n        lh->b = n;\n        memset(n + nni, 0, sizeof(*n) * (j - nni));\n        lh->pmax = nni;\n        lh->num_alloc_nodes = j;\n        lh->num_expand_reallocs++;\n        lh->p = 0;\n    } else {\n        lh->p++;\n    }\n    lh->num_nodes++;\n    lh->num_expands++;\n    n1 = &(lh->b[p]);\n    n2 = &(lh->b[p + pmax]);\n    *n2 = NULL;\n    for (np = *n1; np != NULL;) {\n        hash = np->hash;\n        if ((hash % nni) != p) {\n            *n1 = (*n1)->next;\n            np->next = *n2;\n            *n2 = np;\n        } else\n            n1 = &((*n1)->next);\n        np = *n1;\n    }\n    return 1;\n}']