apps/srp.c:450: error: BUFFER_OVERRUN_L3
  Offset: [16, +oo] Size: [1, +oo] by call to `update_index`.
Showing all 29 steps of the trace


apps/srp.c:428:22: Call
426.                   if (!
427.                       (gNid =
428.                        srp_create_user(user, &(row[DB_srpverifier]),
                            ^
429.                                        &(row[DB_srpsalt]),
430.                                        gNrow ? gNrow[DB_srpsalt] : gN,

apps/srp.c:169:14: Call
  167.           if (!
  168.               (gNid =
  169.                SRP_create_verifier(user, password, &salt, srp_verifier, N,
                      ^
  170.                                    g))) {
  171.               BIO_printf(bio_err, "Internal error creating SRP verifier\n");

crypto/srp/srp_vfy.c:589:10: Call
    587.       }
    588.   
    589.       if (!SRP_create_verifier_BN(user, pass, &s, &v, N_bn, g_bn))
                    ^
    590.           goto err;
    591.   

crypto/srp/srp_vfy.c:655:9: Call
      653.       }
      654.   
      655.       x = SRP_Calc_x(salttmp, user, pass);
                     ^
      656.   
      657.       *verifier = BN_new();

crypto/srp/srp_lib.c:183:10: Call
        181.           goto err;
        182.   
        183.       if (!EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL)
                        ^
        184.           || !EVP_DigestUpdate(ctxt, user, strlen(user))
        185.           || !EVP_DigestUpdate(ctxt, ":", 1)

crypto/evp/digest.c:88:20: Call
          86.           } else {
          87.               /* Ask if an ENGINE is reserved for this job */
          88.               impl = ENGINE_get_digest_engine(type->type);
                                   ^
          89.           }
          90.           if (impl != NULL) {

crypto/engine/tb_digest.c:65:12: Call
            63.   ENGINE *ENGINE_get_digest_engine(int nid)
            64.   {
            65.       return engine_table_select(&digest_table, nid);
                             ^
            66.   }
            67.   

crypto/engine/eng_table.c:211:10: Call
              209.        * operations. But don't worry about a fprintf(stderr).
              210.        */
              211.       if (!int_table_check(table, 0))
                              ^
              212.           goto end;
              213.       tmplate.nid = nid;

crypto/engine/eng_table.c:72:15: Call
                70.       if (!create)
                71.           return 0;
                72.       if ((lh = lh_ENGINE_PILE_new(engine_pile_hash, engine_pile_cmp)) == NULL)
                                    ^
                73.           return 0;
                74.       *t = (ENGINE_TABLE *)lh;

crypto/engine/eng_int.h:177:1: Call
                  175.   typedef struct st_engine_pile ENGINE_PILE;
                  176.   
                  177. > DEFINE_LHASH_OF(ENGINE_PILE);
                  178.   
                  179.   #ifdef  __cplusplus

crypto/lhash/lhash.c:38:5: Assignment
                    36.       ret->hash = ((h == NULL) ? (OPENSSL_LH_HASHFUNC)OPENSSL_LH_strhash : h);
                    37.       ret->num_nodes = MIN_NODES / 2;
                    38.       ret->num_alloc_nodes = MIN_NODES;
                              ^
                    39.       ret->pmax = MIN_NODES / 2;
                    40.       ret->up_load = UP_LOAD;

apps/srp.c:450:25: Call
448.                       || (userinfo
449.                           && ((row[DB_srpinfo] = OPENSSL_strdup(userinfo)) == NULL))
450.                       || !update_index(db, row)) {
                               ^
451.                       OPENSSL_free(row[DB_srpid]);
452.                       OPENSSL_free(row[DB_srpgN]);

apps/srp.c:89:1: Parameter `(*db->db->index)->num_alloc_nodes`
  87.   }
  88.   
  89. > static int update_index(CA_DB *db, char **row)
  90.   {
  91.       char **irow;

apps/srp.c:101:10: Call
  99.       irow[DB_NUMBER] = NULL;
  100.   
  101.       if (!TXT_DB_insert(db->db, irow)) {
                  ^
  102.           BIO_printf(bio_err, "failed to update srpvfile\n");
  103.           BIO_printf(bio_err, "TXT_DB error number %ld\n", db->db->error);

crypto/txt_db/txt_db.c:229:1: Parameter `(*db->index)->num_alloc_nodes`
    227.   }
    228.   
    229. > int TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *row)
    230.   {
    231.       int i;

crypto/txt_db/txt_db.c:257:19: Call
    255.               if ((db->qual[i] != NULL) && (db->qual[i] (row) == 0))
    256.                   continue;
    257.               (void)lh_OPENSSL_STRING_insert(db->index[i], row);
                             ^
    258.           }
    259.       }

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

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

crypto/lhash/lhash.c:70:1: Parameter `lh->num_alloc_nodes`
        68.   }
        69.   
        70. > void *OPENSSL_LH_insert(OPENSSL_LHASH *lh, void *data)
        71.   {
        72.       unsigned long hash;

crypto/lhash/lhash.c:77:77: Call
        75.   
        76.       lh->error = 0;
        77.       if ((lh->up_load <= (lh->num_items * LH_LOAD_MULT / lh->num_nodes)) && !expand(lh))
                                                                                          ^
        78.           return NULL;        /* 'lh->error++' already done in 'expand' */
        79.   

crypto/lhash/lhash.c:187:1: <Offset trace>
185.   }
186.   
187. > static int expand(OPENSSL_LHASH *lh)
188.   {
189.       OPENSSL_LH_NODE **n, **n1, **n2, *np;

crypto/lhash/lhash.c:187:1: Parameter `lh->num_alloc_nodes`
          185.   }
          186.   
          187. > static int expand(OPENSSL_LHASH *lh)
          188.   {
          189.       OPENSSL_LH_NODE **n, **n1, **n2, *np;

crypto/lhash/lhash.c:213:9: Assignment
          211.   
          212.       if ((lh->p) >= lh->pmax) {
          213.           j = (int)lh->num_alloc_nodes * 2;
                         ^
          214.           n = OPENSSL_realloc(lh->b, (int)(sizeof(OPENSSL_LH_NODE *) * j));
          215.           if (n == NULL) {

crypto/lhash/lhash.c:187:1: <Length trace>
185.   }
186.   
187. > static int expand(OPENSSL_LHASH *lh)
188.   {
189.       OPENSSL_LH_NODE **n, **n1, **n2, *np;

crypto/lhash/lhash.c:187:1: Parameter `*lh->b`
          185.   }
          186.   
          187. > static int expand(OPENSSL_LHASH *lh)
          188.   {
          189.       OPENSSL_LH_NODE **n, **n1, **n2, *np;

crypto/lhash/lhash.c:214:13: Call
          212.       if ((lh->p) >= lh->pmax) {
          213.           j = (int)lh->num_alloc_nodes * 2;
          214.           n = OPENSSL_realloc(lh->b, (int)(sizeof(OPENSSL_LH_NODE *) * j));
                             ^
          215.           if (n == NULL) {
          216.               lh->error++;

crypto/mem.c:117:9: Assignment
            115.       if (num == 0) {
            116.           CRYPTO_free(str, file, line);
            117.           return NULL;
                           ^
            118.       }
            119.   

crypto/lhash/lhash.c:214:9: Assignment
          212.       if ((lh->p) >= lh->pmax) {
          213.           j = (int)lh->num_alloc_nodes * 2;
          214.           n = OPENSSL_realloc(lh->b, (int)(sizeof(OPENSSL_LH_NODE *) * j));
                         ^
          215.           if (n == NULL) {
          216.               lh->error++;

crypto/lhash/lhash.c:222:13: Array access: Offset: [16, +oo] Size: [1, +oo] by call to `update_index` 
          220.           }
          221.           for (i = (int)lh->num_alloc_nodes; i < j; i++) /* 26/02/92 eay */
          222.               n[i] = NULL;        /* 02/03/92 eay */
                             ^
          223.           lh->pmax = lh->num_alloc_nodes;
          224.           lh->num_alloc_nodes = j;

static int expand(OPENSSL_LHASH *lh)
{
    OPENSSL_LH_NODE **n, **n1, **n2, *np;
    unsigned int p, i, j;
    unsigned long hash, nni;
    lh->num_nodes++;
    lh->num_expands++;
    p = (int)lh->p++;
    n1 = &(lh->b[p]);
    n2 = &(lh->b[p + (int)lh->pmax]);
    *n2 = NULL;
    nni = lh->num_alloc_nodes;
    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;
    }
    if ((lh->p) >= lh->pmax) {
        j = (int)lh->num_alloc_nodes * 2;
        n = OPENSSL_realloc(lh->b, (int)(sizeof(OPENSSL_LH_NODE *) * j));
        if (n == NULL) {
            lh->error++;
            lh->num_nodes--;
            lh->p = 0;
            return 0;
        }
        for (i = (int)lh->num_alloc_nodes; i < j; i++)
            n[i] = NULL;
        lh->pmax = lh->num_alloc_nodes;
        lh->num_alloc_nodes = j;
        lh->num_expand_reallocs++;
        lh->p = 0;
        lh->b = n;
    }
    return 1;
}
['int srp_main(int argc, char **argv)\n{\n    CA_DB *db = NULL;\n    CONF *conf = NULL;\n    int gNindex = -1, maxgN = -1, ret = 1, errors = 0, verbose = 0, i;\n    int doupdatedb = 0, mode = OPT_ERR;\n    char *user = NULL, *passinarg = NULL, *passoutarg = NULL;\n    char *passin = NULL, *passout = NULL, *gN = NULL, *userinfo = NULL;\n    char *randfile = NULL, *section = NULL;\n    char **gNrow = NULL, *configfile = NULL;\n    char *srpvfile = NULL, **pp, *prog;\n    OPTION_CHOICE o;\n    prog = opt_init(argc, argv, srp_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(srp_options);\n            ret = 0;\n            goto end;\n        case OPT_VERBOSE:\n            verbose++;\n            break;\n        case OPT_CONFIG:\n            configfile = opt_arg();\n            break;\n        case OPT_NAME:\n            section = opt_arg();\n            break;\n        case OPT_SRPVFILE:\n            srpvfile = opt_arg();\n            break;\n        case OPT_ADD:\n        case OPT_DELETE:\n        case OPT_MODIFY:\n        case OPT_LIST:\n            if (mode != OPT_ERR) {\n                BIO_printf(bio_err,\n                           "%s: Only one of -add/delete-modify/-list\\n",\n                           prog);\n                goto opthelp;\n            }\n            mode = o;\n            break;\n        case OPT_GN:\n            gN = opt_arg();\n            break;\n        case OPT_USERINFO:\n            userinfo = opt_arg();\n            break;\n        case OPT_PASSIN:\n            passinarg = opt_arg();\n            break;\n        case OPT_PASSOUT:\n            passoutarg = opt_arg();\n            break;\n        case OPT_ENGINE:\n            (void)setup_engine(opt_arg(), 0);\n            break;\n        }\n    }\n    argc = opt_num_rest();\n    argv = opt_rest();\n    if (srpvfile && configfile) {\n        BIO_printf(bio_err,\n                   "-srpvfile and -configfile cannot be specified together.\\n");\n        goto end;\n    }\n    if (mode == OPT_ERR) {\n        BIO_printf(bio_err,\n                   "Exactly one of the options -add, -delete, -modify -list must be specified.\\n");\n        goto opthelp;\n    }\n    if ((mode == OPT_DELETE || mode == OPT_MODIFY || mode == OPT_ADD)\n        && argc < 1) {\n        BIO_printf(bio_err,\n                   "Need at least one user for options -add, -delete, -modify. \\n");\n        goto opthelp;\n    }\n    if ((passin || passout) && argc != 1) {\n        BIO_printf(bio_err,\n                   "-passin, -passout arguments only valid with one user.\\n");\n        goto opthelp;\n    }\n    if (!app_passwd(passinarg, passoutarg, &passin, &passout)) {\n        BIO_printf(bio_err, "Error getting passwords\\n");\n        goto end;\n    }\n    if (!srpvfile) {\n        if (!configfile)\n            configfile = default_config_file;\n        if (verbose)\n            BIO_printf(bio_err, "Using configuration from %s\\n",\n                       configfile);\n        conf = app_load_config(configfile);\n        if (conf == NULL)\n            goto end;\n        if (configfile != default_config_file && !app_load_modules(conf))\n            goto end;\n        if (section == NULL) {\n            if (verbose)\n                BIO_printf(bio_err,\n                           "trying to read " ENV_DEFAULT_SRP\n                           " in " BASE_SECTION "\\n");\n            section = lookup_conf(conf, BASE_SECTION, ENV_DEFAULT_SRP);\n            if (section == NULL)\n                goto end;\n        }\n        if (randfile == NULL)\n            randfile = NCONF_get_string(conf, BASE_SECTION, "RANDFILE");\n        if (verbose)\n            BIO_printf(bio_err,\n                       "trying to read " ENV_DATABASE " in section \\"%s\\"\\n",\n                       section);\n        srpvfile = lookup_conf(conf, section, ENV_DATABASE);\n        if (srpvfile == NULL)\n            goto end;\n    }\n    if (randfile == NULL)\n        ERR_clear_error();\n    else\n        app_RAND_load_file(randfile, 0);\n    if (verbose)\n        BIO_printf(bio_err, "Trying to read SRP verifier file \\"%s\\"\\n",\n                   srpvfile);\n    db = load_index(srpvfile, NULL);\n    if (db == NULL)\n        goto end;\n    for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {\n        pp = sk_OPENSSL_PSTRING_value(db->db->data, i);\n        if (pp[DB_srptype][0] == DB_SRP_INDEX) {\n            maxgN = i;\n            if ((gNindex < 0) && (gN != NULL) && strcmp(gN, pp[DB_srpid]) == 0)\n                gNindex = i;\n            print_index(db, i, verbose > 1);\n        }\n    }\n    if (verbose)\n        BIO_printf(bio_err, "Database initialised\\n");\n    if (gNindex >= 0) {\n        gNrow = sk_OPENSSL_PSTRING_value(db->db->data, gNindex);\n        print_entry(db, gNindex, verbose > 1, "Default g and N");\n    } else if (maxgN > 0 && !SRP_get_default_gN(gN)) {\n        BIO_printf(bio_err, "No g and N value for index \\"%s\\"\\n", gN);\n        goto end;\n    } else {\n        if (verbose)\n            BIO_printf(bio_err, "Database has no g N information.\\n");\n        gNrow = NULL;\n    }\n    if (verbose > 1)\n        BIO_printf(bio_err, "Starting user processing\\n");\n    if (argc > 0)\n        user = *(argv++);\n    while (mode == OPT_LIST || user) {\n        int userindex = -1;\n        if (user != NULL && verbose > 1)\n            BIO_printf(bio_err, "Processing user \\"%s\\"\\n", user);\n        if ((userindex = get_index(db, user, \'U\')) >= 0) {\n            print_user(db, userindex, (verbose > 0) || mode == OPT_LIST);\n        }\n        if (mode == OPT_LIST) {\n            if (user == NULL) {\n                BIO_printf(bio_err, "List all users\\n");\n                for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {\n                    print_user(db, i, 1);\n                }\n            } else if (userindex < 0) {\n                BIO_printf(bio_err,\n                           "user \\"%s\\" does not exist, ignored. t\\n", user);\n                errors++;\n            }\n        } else if (mode == OPT_ADD) {\n            if (userindex >= 0) {\n                char **row =\n                    sk_OPENSSL_PSTRING_value(db->db->data, userindex);\n                BIO_printf(bio_err, "user \\"%s\\" reactivated.\\n", user);\n                row[DB_srptype][0] = \'V\';\n                doupdatedb = 1;\n            } else {\n                char *row[DB_NUMBER];\n                char *gNid;\n                row[DB_srpverifier] = NULL;\n                row[DB_srpsalt] = NULL;\n                row[DB_srpinfo] = NULL;\n                if (!\n                    (gNid =\n                     srp_create_user(user, &(row[DB_srpverifier]),\n                                     &(row[DB_srpsalt]),\n                                     gNrow ? gNrow[DB_srpsalt] : gN,\n                                     gNrow ? gNrow[DB_srpverifier] : NULL,\n                                     passout, verbose))) {\n                    BIO_printf(bio_err,\n                               "Cannot create srp verifier for user \\"%s\\", operation abandoned .\\n",\n                               user);\n                    errors++;\n                    goto end;\n                }\n                row[DB_srpid] = OPENSSL_strdup(user);\n                row[DB_srptype] = OPENSSL_strdup("v");\n                row[DB_srpgN] = OPENSSL_strdup(gNid);\n                if ((row[DB_srpid] == NULL)\n                    || (row[DB_srpgN] == NULL)\n                    || (row[DB_srptype] == NULL)\n                    || (row[DB_srpverifier] == NULL)\n                    || (row[DB_srpsalt] == NULL)\n                    || (userinfo\n                        && ((row[DB_srpinfo] = OPENSSL_strdup(userinfo)) == NULL))\n                    || !update_index(db, row)) {\n                    OPENSSL_free(row[DB_srpid]);\n                    OPENSSL_free(row[DB_srpgN]);\n                    OPENSSL_free(row[DB_srpinfo]);\n                    OPENSSL_free(row[DB_srptype]);\n                    OPENSSL_free(row[DB_srpverifier]);\n                    OPENSSL_free(row[DB_srpsalt]);\n                    goto end;\n                }\n                doupdatedb = 1;\n            }\n        } else if (mode == OPT_MODIFY) {\n            if (userindex < 0) {\n                BIO_printf(bio_err,\n                           "user \\"%s\\" does not exist, operation ignored.\\n",\n                           user);\n                errors++;\n            } else {\n                char **row =\n                    sk_OPENSSL_PSTRING_value(db->db->data, userindex);\n                char type = row[DB_srptype][0];\n                if (type == \'v\') {\n                    BIO_printf(bio_err,\n                               "user \\"%s\\" already updated, operation ignored.\\n",\n                               user);\n                    errors++;\n                } else {\n                    char *gNid;\n                    if (row[DB_srptype][0] == \'V\') {\n                        int user_gN;\n                        char **irow = NULL;\n                        if (verbose)\n                            BIO_printf(bio_err,\n                                       "Verifying password for user \\"%s\\"\\n",\n                                       user);\n                        if ((user_gN =\n                             get_index(db, row[DB_srpgN], DB_SRP_INDEX)) >= 0)\n                            irow =\n                                sk_OPENSSL_PSTRING_value(db->db->data,\n                                                         userindex);\n                        if (!srp_verify_user\n                            (user, row[DB_srpverifier], row[DB_srpsalt],\n                             irow ? irow[DB_srpsalt] : row[DB_srpgN],\n                             irow ? irow[DB_srpverifier] : NULL, passin,\n                             verbose)) {\n                            BIO_printf(bio_err,\n                                       "Invalid password for user \\"%s\\", operation abandoned.\\n",\n                                       user);\n                            errors++;\n                            goto end;\n                        }\n                    }\n                    if (verbose)\n                        BIO_printf(bio_err, "Password for user \\"%s\\" ok.\\n",\n                                   user);\n                    if (!\n                        (gNid =\n                         srp_create_user(user, &(row[DB_srpverifier]),\n                                         &(row[DB_srpsalt]),\n                                         gNrow ? gNrow[DB_srpsalt] : NULL,\n                                         gNrow ? gNrow[DB_srpverifier] : NULL,\n                                         passout, verbose))) {\n                        BIO_printf(bio_err,\n                                   "Cannot create srp verifier for user \\"%s\\", operation abandoned.\\n",\n                                   user);\n                        errors++;\n                        goto end;\n                    }\n                    row[DB_srptype][0] = \'v\';\n                    row[DB_srpgN] = OPENSSL_strdup(gNid);\n                    if (row[DB_srpid] == NULL\n                        || row[DB_srpgN] == NULL\n                        || row[DB_srptype] == NULL\n                        || row[DB_srpverifier] == NULL\n                        || row[DB_srpsalt] == NULL\n                        || (userinfo\n                            && ((row[DB_srpinfo] = OPENSSL_strdup(userinfo))\n                                == NULL)))\n                        goto end;\n                    doupdatedb = 1;\n                }\n            }\n        } else if (mode == OPT_DELETE) {\n            if (userindex < 0) {\n                BIO_printf(bio_err,\n                           "user \\"%s\\" does not exist, operation ignored. t\\n",\n                           user);\n                errors++;\n            } else {\n                char **xpp = sk_OPENSSL_PSTRING_value(db->db->data, userindex);\n                BIO_printf(bio_err, "user \\"%s\\" revoked. t\\n", user);\n                xpp[DB_srptype][0] = \'R\';\n                doupdatedb = 1;\n            }\n        }\n        if (--argc > 0)\n            user = *(argv++);\n        else {\n            user = NULL;\n        }\n    }\n    if (verbose)\n        BIO_printf(bio_err, "User procession done.\\n");\n    if (doupdatedb) {\n        for (i = 0; i < sk_OPENSSL_PSTRING_num(db->db->data); i++) {\n            pp = sk_OPENSSL_PSTRING_value(db->db->data, i);\n            if (pp[DB_srptype][0] == \'v\') {\n                pp[DB_srptype][0] = \'V\';\n                print_user(db, i, verbose);\n            }\n        }\n        if (verbose)\n            BIO_printf(bio_err, "Trying to update srpvfile.\\n");\n        if (!save_index(srpvfile, "new", db))\n            goto end;\n        if (verbose)\n            BIO_printf(bio_err, "Temporary srpvfile created.\\n");\n        if (!rotate_index(srpvfile, "new", "old"))\n            goto end;\n        if (verbose)\n            BIO_printf(bio_err, "srpvfile updated.\\n");\n    }\n    ret = (errors != 0);\n end:\n    if (errors != 0)\n        if (verbose)\n            BIO_printf(bio_err, "User errors %d.\\n", errors);\n    if (verbose)\n        BIO_printf(bio_err, "SRP terminating with code %d.\\n", ret);\n    OPENSSL_free(passin);\n    OPENSSL_free(passout);\n    if (ret)\n        ERR_print_errors(bio_err);\n    if (randfile)\n        app_RAND_write_file(randfile);\n    NCONF_free(conf);\n    free_index(db);\n    return (ret);\n}', 'static char *srp_create_user(char *user, char **srp_verifier,\n                             char **srp_usersalt, char *g, char *N,\n                             char *passout, int verbose)\n{\n    char password[1024];\n    PW_CB_DATA cb_tmp;\n    char *gNid = NULL;\n    char *salt = NULL;\n    cb_tmp.prompt_info = user;\n    cb_tmp.password = passout;\n    if (password_callback(password, sizeof(password), 1, &cb_tmp) > 0) {\n        if (verbose)\n            BIO_printf(bio_err, "Creating\\n user=\\"%s\\"\\n g=\\"%s\\"\\n N=\\"%s\\"\\n",\n                       user, g, N);\n        if (!\n            (gNid =\n             SRP_create_verifier(user, password, &salt, srp_verifier, N,\n                                 g))) {\n            BIO_printf(bio_err, "Internal error creating SRP verifier\\n");\n        } else\n            *srp_usersalt = salt;\n        if (verbose > 1)\n            BIO_printf(bio_err, "gNid=%s salt =\\"%s\\"\\n verifier =\\"%s\\"\\n", gNid,\n                       salt, *srp_verifier);\n    }\n    return gNid;\n}', 'char *SRP_create_verifier(const char *user, const char *pass, char **salt,\n                          char **verifier, const char *N, const char *g)\n{\n    int len;\n    char *result = NULL, *vf = NULL;\n    const BIGNUM *N_bn = NULL, *g_bn = NULL;\n    BIGNUM *N_bn_alloc = NULL, *g_bn_alloc = NULL, *s = NULL, *v = NULL;\n    unsigned char tmp[MAX_LEN];\n    unsigned char tmp2[MAX_LEN];\n    char *defgNid = NULL;\n    int vfsize = 0;\n    if ((user == NULL) ||\n        (pass == NULL) || (salt == NULL) || (verifier == NULL))\n        goto err;\n    if (N) {\n        if ((len = t_fromb64(tmp, sizeof(tmp), N)) <= 0)\n            goto err;\n        N_bn_alloc = BN_bin2bn(tmp, len, NULL);\n        N_bn = N_bn_alloc;\n        if ((len = t_fromb64(tmp, sizeof(tmp) ,g)) <= 0)\n            goto err;\n        g_bn_alloc = BN_bin2bn(tmp, len, NULL);\n        g_bn = g_bn_alloc;\n        defgNid = "*";\n    } else {\n        SRP_gN *gN = SRP_get_gN_by_id(g, NULL);\n        if (gN == NULL)\n            goto err;\n        N_bn = gN->N;\n        g_bn = gN->g;\n        defgNid = gN->id;\n    }\n    if (*salt == NULL) {\n        if (RAND_bytes(tmp2, SRP_RANDOM_SALT_LEN) <= 0)\n            goto err;\n        s = BN_bin2bn(tmp2, SRP_RANDOM_SALT_LEN, NULL);\n    } else {\n        if ((len = t_fromb64(tmp2, sizeof(tmp2), *salt)) <= 0)\n            goto err;\n        s = BN_bin2bn(tmp2, len, NULL);\n    }\n    if (!SRP_create_verifier_BN(user, pass, &s, &v, N_bn, g_bn))\n        goto err;\n    BN_bn2bin(v, tmp);\n    vfsize = BN_num_bytes(v) * 2;\n    if (((vf = OPENSSL_malloc(vfsize)) == NULL))\n        goto err;\n    t_tob64(vf, tmp, BN_num_bytes(v));\n    if (*salt == NULL) {\n        char *tmp_salt;\n        if ((tmp_salt = OPENSSL_malloc(SRP_RANDOM_SALT_LEN * 2)) == NULL) {\n            goto err;\n        }\n        t_tob64(tmp_salt, tmp2, SRP_RANDOM_SALT_LEN);\n        *salt = tmp_salt;\n    }\n    *verifier = vf;\n    vf = NULL;\n    result = defgNid;\n err:\n    BN_free(N_bn_alloc);\n    BN_free(g_bn_alloc);\n    OPENSSL_clear_free(vf, vfsize);\n    BN_clear_free(s);\n    BN_clear_free(v);\n    return result;\n}', 'int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,\n                           BIGNUM **verifier, const BIGNUM *N,\n                           const BIGNUM *g)\n{\n    int result = 0;\n    BIGNUM *x = NULL;\n    BN_CTX *bn_ctx = BN_CTX_new();\n    unsigned char tmp2[MAX_LEN];\n    BIGNUM *salttmp = NULL;\n    if ((user == NULL) ||\n        (pass == NULL) ||\n        (salt == NULL) ||\n        (verifier == NULL) || (N == NULL) || (g == NULL) || (bn_ctx == NULL))\n        goto err;\n    if (*salt == NULL) {\n        if (RAND_bytes(tmp2, SRP_RANDOM_SALT_LEN) <= 0)\n            goto err;\n        salttmp = BN_bin2bn(tmp2, SRP_RANDOM_SALT_LEN, NULL);\n    } else {\n        salttmp = *salt;\n    }\n    x = SRP_Calc_x(salttmp, user, pass);\n    *verifier = BN_new();\n    if (*verifier == NULL)\n        goto err;\n    if (!BN_mod_exp(*verifier, g, x, N, bn_ctx)) {\n        BN_clear_free(*verifier);\n        goto err;\n    }\n    result = 1;\n    *salt = salttmp;\n err:\n    if (salt != NULL && *salt != salttmp)\n        BN_clear_free(salttmp);\n    BN_clear_free(x);\n    BN_CTX_free(bn_ctx);\n    return result;\n}', 'BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass)\n{\n    unsigned char dig[SHA_DIGEST_LENGTH];\n    EVP_MD_CTX *ctxt;\n    unsigned char *cs = NULL;\n    BIGNUM *res = NULL;\n    if ((s == NULL) || (user == NULL) || (pass == NULL))\n        return NULL;\n    ctxt = EVP_MD_CTX_new();\n    if (ctxt == NULL)\n        return NULL;\n    if ((cs = OPENSSL_malloc(BN_num_bytes(s))) == NULL)\n        goto err;\n    if (!EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL)\n        || !EVP_DigestUpdate(ctxt, user, strlen(user))\n        || !EVP_DigestUpdate(ctxt, ":", 1)\n        || !EVP_DigestUpdate(ctxt, pass, strlen(pass))\n        || !EVP_DigestFinal_ex(ctxt, dig, NULL)\n        || !EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL))\n        goto err;\n    BN_bn2bin(s, cs);\n    if (!EVP_DigestUpdate(ctxt, cs, BN_num_bytes(s)))\n        goto err;\n    if (!EVP_DigestUpdate(ctxt, dig, sizeof(dig))\n        || !EVP_DigestFinal_ex(ctxt, dig, NULL))\n        goto err;\n    res = BN_bin2bn(dig, sizeof(dig), NULL);\n err:\n    OPENSSL_free(cs);\n    EVP_MD_CTX_free(ctxt);\n    return res;\n}', 'int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)\n{\n    EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_CLEANED);\n#ifndef OPENSSL_NO_ENGINE\n    if (ctx->engine && ctx->digest &&\n        (type == NULL || (type->type == ctx->digest->type)))\n        goto skip_to_init;\n    if (type) {\n        ENGINE_finish(ctx->engine);\n        if (impl != NULL) {\n            if (!ENGINE_init(impl)) {\n                EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_INITIALIZATION_ERROR);\n                return 0;\n            }\n        } else {\n            impl = ENGINE_get_digest_engine(type->type);\n        }\n        if (impl != NULL) {\n            const EVP_MD *d = ENGINE_get_digest(impl, type->type);\n            if (d == NULL) {\n                EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_INITIALIZATION_ERROR);\n                ENGINE_finish(impl);\n                return 0;\n            }\n            type = d;\n            ctx->engine = impl;\n        } else\n            ctx->engine = NULL;\n    } else {\n        if (!ctx->digest) {\n            EVPerr(EVP_F_EVP_DIGESTINIT_EX, EVP_R_NO_DIGEST_SET);\n            return 0;\n        }\n        type = ctx->digest;\n    }\n#endif\n    if (ctx->digest != type) {\n        if (ctx->digest && ctx->digest->ctx_size) {\n            OPENSSL_clear_free(ctx->md_data, ctx->digest->ctx_size);\n            ctx->md_data = NULL;\n        }\n        ctx->digest = type;\n        if (!(ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) && type->ctx_size) {\n            ctx->update = type->update;\n            ctx->md_data = OPENSSL_zalloc(type->ctx_size);\n            if (ctx->md_data == NULL) {\n                EVPerr(EVP_F_EVP_DIGESTINIT_EX, ERR_R_MALLOC_FAILURE);\n                return 0;\n            }\n        }\n    }\n#ifndef OPENSSL_NO_ENGINE\n skip_to_init:\n#endif\n    if (ctx->pctx) {\n        int r;\n        r = EVP_PKEY_CTX_ctrl(ctx->pctx, -1, EVP_PKEY_OP_TYPE_SIG,\n                              EVP_PKEY_CTRL_DIGESTINIT, 0, ctx);\n        if (r <= 0 && (r != -2))\n            return 0;\n    }\n    if (ctx->flags & EVP_MD_CTX_FLAG_NO_INIT)\n        return 1;\n    return ctx->digest->init(ctx);\n}', 'ENGINE *ENGINE_get_digest_engine(int nid)\n{\n    return engine_table_select(&digest_table, 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_THREAD_write_lock(global_engine_lock);\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_THREAD_unlock(global_engine_lock);\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(engine_pile_hash, engine_pile_cmp)) == NULL)\n        return 0;\n    *t = (ENGINE_TABLE *)lh;\n    return 1;\n}', 'DEFINE_LHASH_OF(ENGINE_PILE)', '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        goto err0;\n    if ((ret->b = OPENSSL_zalloc(sizeof(*ret->b) * MIN_NODES)) == NULL)\n        goto err1;\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);\n err1:\n    OPENSSL_free(ret);\n err0:\n    return (NULL);\n}', 'static int update_index(CA_DB *db, char **row)\n{\n    char **irow;\n    int i;\n    irow = app_malloc(sizeof(*irow) * (DB_NUMBER + 1), "row pointers");\n    for (i = 0; i < DB_NUMBER; i++) {\n        irow[i] = row[i];\n        row[i] = NULL;\n    }\n    irow[DB_NUMBER] = NULL;\n    if (!TXT_DB_insert(db->db, irow)) {\n        BIO_printf(bio_err, "failed to update srpvfile\\n");\n        BIO_printf(bio_err, "TXT_DB error number %ld\\n", db->db->error);\n        OPENSSL_free(irow);\n        return 0;\n    }\n    return 1;\n}', 'int TXT_DB_insert(TXT_DB *db, OPENSSL_STRING *row)\n{\n    int i;\n    OPENSSL_STRING *r;\n    for (i = 0; i < db->num_fields; i++) {\n        if (db->index[i] != NULL) {\n            if ((db->qual[i] != NULL) && (db->qual[i] (row) == 0))\n                continue;\n            r = lh_OPENSSL_STRING_retrieve(db->index[i], row);\n            if (r != NULL) {\n                db->error = DB_ERROR_INDEX_CLASH;\n                db->arg1 = i;\n                db->arg_row = r;\n                goto err;\n            }\n        }\n    }\n    if (!sk_OPENSSL_PSTRING_push(db->data, row)) {\n        db->error = DB_ERROR_MALLOC;\n        goto err;\n    }\n    for (i = 0; i < db->num_fields; i++) {\n        if (db->index[i] != NULL) {\n            if ((db->qual[i] != NULL) && (db->qual[i] (row) == 0))\n                continue;\n            (void)lh_OPENSSL_STRING_insert(db->index[i], row);\n        }\n    }\n    return (1);\n err:\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, i, j;\n    unsigned long hash, nni;\n    lh->num_nodes++;\n    lh->num_expands++;\n    p = (int)lh->p++;\n    n1 = &(lh->b[p]);\n    n2 = &(lh->b[p + (int)lh->pmax]);\n    *n2 = NULL;\n    nni = lh->num_alloc_nodes;\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    if ((lh->p) >= lh->pmax) {\n        j = (int)lh->num_alloc_nodes * 2;\n        n = OPENSSL_realloc(lh->b, (int)(sizeof(OPENSSL_LH_NODE *) * j));\n        if (n == NULL) {\n            lh->error++;\n            lh->num_nodes--;\n            lh->p = 0;\n            return 0;\n        }\n        for (i = (int)lh->num_alloc_nodes; i < j; i++)\n            n[i] = NULL;\n        lh->pmax = lh->num_alloc_nodes;\n        lh->num_alloc_nodes = j;\n        lh->num_expand_reallocs++;\n        lh->p = 0;\n        lh->b = n;\n    }\n    return 1;\n}', 'void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)\n{\n    if (realloc_impl != NULL && realloc_impl != &CRYPTO_realloc)\n        return realloc_impl(str, num, file, line);\n    if (str == NULL)\n        return CRYPTO_malloc(num, file, line);\n    if (num == 0) {\n        CRYPTO_free(str, file, line);\n        return NULL;\n    }\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        void *ret;\n        CRYPTO_mem_debug_realloc(str, NULL, num, 0, file, line);\n        ret = realloc(str, num);\n        CRYPTO_mem_debug_realloc(str, ret, num, 1, file, line);\n        return ret;\n    }\n#else\n    osslargused(file); osslargused(line);\n#endif\n    return realloc(str, num);\n}']