apps/ecparam.c:320: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 67108856] by call to `EC_GROUP_get_order`.
Showing all 23 steps of the trace


apps/ecparam.c:280:14: Call
278.       if (check) {
279.           BIO_printf(bio_err, "checking elliptic curve parameters: ");
280.           if (!EC_GROUP_check(group, NULL)) {
                    ^
281.               BIO_printf(bio_err, "failed\n");
282.               ERR_print_errors(bio_err);

crypto/ec/ec_check.c:13:1: Parameter `group->order->top`
  11.   #include <openssl/err.h>
  12.   
  13. > int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx)
  14.   {
  15.       int ret = 0;

apps/ecparam.c:320:14: Call
318.                                  ec_gen, NULL))
319.               goto end;
320.           if (!EC_GROUP_get_order(group, ec_order, NULL))
                    ^
321.               goto end;
322.           if (!EC_GROUP_get_cofactor(group, ec_cofactor, NULL))

crypto/ec/ec_lib.c:321:1: Parameter `order->top`
  319.   }
  320.   
  321. > int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
  322.   {
  323.       if (group->order == NULL)

crypto/ec/ec_lib.c:325:10: Call
  323.       if (group->order == NULL)
  324.           return 0;
  325.       if (!BN_copy(order, group->order))
                  ^
  326.           return 0;
  327.   

crypto/bn/bn_lib.c:323:1: Parameter `a->top`
    321.   }
    322.   
    323. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
    324.   {
    325.       bn_check_top(b);

crypto/bn/bn_lib.c:329:9: Call
    327.       if (a == b)
    328.           return a;
    329.       if (bn_wexpand(a, b->top) == NULL)
                   ^
    330.           return NULL;
    331.   

crypto/bn/bn_lib.c:948:1: Parameter `a->top`
      946.   }
      947.   
      948. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
      949.   {
      950.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:950:37: Call
      948.   BIGNUM *bn_wexpand(BIGNUM *a, int words)
      949.   {
      950.       return (words <= a->dmax) ? a : bn_expand2(a, words);
                                                 ^
      951.   }
      952.   

crypto/bn/bn_lib.c:284:1: Parameter `b->top`
        282.    */
        283.   
        284. > BIGNUM *bn_expand2(BIGNUM *b, int words)
        285.   {
        286.       bn_check_top(b);

crypto/bn/bn_lib.c:289:23: Call
        287.   
        288.       if (words > b->dmax) {
        289.           BN_ULONG *a = bn_expand_internal(b, words);
                                     ^
        290.           if (!a)
        291.               return NULL;

crypto/bn/bn_lib.c:246:1: <Offset trace>
244.   /* This is used by bn_expand2() */
245.   /* The caller MUST check that words > b->dmax before calling this */
246. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
247.   {
248.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:246:1: Parameter `b->top`
          244.   /* This is used by bn_expand2() */
          245.   /* The caller MUST check that words > b->dmax before calling this */
          246. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
          247.   {
          248.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:246:1: <Length trace>
244.   /* This is used by bn_expand2() */
245.   /* The caller MUST check that words > b->dmax before calling this */
246. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
247.   {
248.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:246:1: Parameter `words`
          244.   /* This is used by bn_expand2() */
          245.   /* The caller MUST check that words > b->dmax before calling this */
          246. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
          247.   {
          248.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:263:13: Call
          261.           a = OPENSSL_secure_zalloc(words * sizeof(*a));
          262.       else
          263.           a = OPENSSL_zalloc(words * sizeof(*a));
                             ^
          264.       if (a == NULL) {
          265.           BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);

crypto/mem.c:186:1: Parameter `num`
            184.   }
            185.   
            186. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
            187.   {
            188.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:188:17: Call
            186.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
            187.   {
            188.       void *ret = CRYPTO_malloc(num, file, line);
                                   ^
            189.   
            190.       FAILTEST();

crypto/mem.c:166:9: Assignment
              164.   
              165.       if (num == 0)
              166.           return NULL;
                             ^
              167.   
              168.       FAILTEST();

crypto/mem.c:188:5: Assignment
            186.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
            187.   {
            188.       void *ret = CRYPTO_malloc(num, file, line);
                       ^
            189.   
            190.       FAILTEST();

crypto/mem.c:193:5: Assignment
            191.       if (ret != NULL)
            192.           memset(ret, 0, num);
            193.       return ret;
                       ^
            194.   }
            195.   

crypto/bn/bn_lib.c:263:9: Assignment
          261.           a = OPENSSL_secure_zalloc(words * sizeof(*a));
          262.       else
          263.           a = OPENSSL_zalloc(words * sizeof(*a));
                         ^
          264.       if (a == NULL) {
          265.           BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);

crypto/bn/bn_lib.c:271:9: Array access: Offset added: [8, +oo] Size: [0, 67108856] by call to `EC_GROUP_get_order` 
          269.       assert(b->top <= words);
          270.       if (b->top > 0)
          271.           memcpy(a, b->d, sizeof(*a) * b->top);
                         ^
          272.   
          273.       return a;

static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *a = NULL;
    bn_check_top(b);
    if (words > (INT_MAX / (4 * BN_BITS2))) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
        return NULL;
    }
    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
        return (NULL);
    }
    if (BN_get_flags(b, BN_FLG_SECURE))
        a = OPENSSL_secure_zalloc(words * sizeof(*a));
    else
        a = OPENSSL_zalloc(words * sizeof(*a));
    if (a == NULL) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
        return (NULL);
    }
    assert(b->top <= words);
    if (b->top > 0)
        memcpy(a, b->d, sizeof(*a) * b->top);
    return a;
}
['int ecparam_main(int argc, char **argv)\n{\n    ENGINE *e = NULL;\n    BIGNUM *ec_gen = NULL, *ec_order = NULL, *ec_cofactor = NULL;\n    BIGNUM *ec_p = NULL, *ec_a = NULL, *ec_b = NULL;\n    BIO *in = NULL, *out = NULL;\n    EC_GROUP *group = NULL;\n    point_conversion_form_t form = POINT_CONVERSION_UNCOMPRESSED;\n    char *curve_name = NULL, *inrand = NULL;\n    char *infile = NULL, *outfile = NULL, *prog;\n    unsigned char *buffer = NULL;\n    OPTION_CHOICE o;\n    int asn1_flag = OPENSSL_EC_NAMED_CURVE, new_asn1_flag = 0;\n    int informat = FORMAT_PEM, outformat = FORMAT_PEM, noout = 0, C = 0;\n    int ret = 1, private = 0;\n    int list_curves = 0, no_seed = 0, check = 0, new_form = 0;\n    int text = 0, i, need_rand = 0, genkey = 0;\n    prog = opt_init(argc, argv, ecparam_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(ecparam_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_IN:\n            infile = opt_arg();\n            break;\n        case OPT_OUTFORM:\n            if (!opt_format(opt_arg(), OPT_FMT_PEMDER, &outformat))\n                goto opthelp;\n            break;\n        case OPT_OUT:\n            outfile = opt_arg();\n            break;\n        case OPT_TEXT:\n            text = 1;\n            break;\n        case OPT_C:\n            C = 1;\n            break;\n        case OPT_CHECK:\n            check = 1;\n            break;\n        case OPT_LIST_CURVES:\n            list_curves = 1;\n            break;\n        case OPT_NO_SEED:\n            no_seed = 1;\n            break;\n        case OPT_NOOUT:\n            noout = 1;\n            break;\n        case OPT_NAME:\n            curve_name = opt_arg();\n            break;\n        case OPT_CONV_FORM:\n            if (!opt_pair(opt_arg(), forms, &new_form))\n                goto opthelp;\n            form = new_form;\n            new_form = 1;\n            break;\n        case OPT_PARAM_ENC:\n            if (!opt_pair(opt_arg(), encodings, &asn1_flag))\n                goto opthelp;\n            new_asn1_flag = 1;\n            break;\n        case OPT_GENKEY:\n            genkey = need_rand = 1;\n            break;\n        case OPT_RAND:\n            inrand = opt_arg();\n            need_rand = 1;\n            break;\n        case OPT_ENGINE:\n            e = setup_engine(opt_arg(), 0);\n            break;\n        }\n    }\n    argc = opt_num_rest();\n    if (argc != 0)\n        goto opthelp;\n    private = genkey ? 1 : 0;\n    in = bio_open_default(infile, \'r\', informat);\n    if (in == NULL)\n        goto end;\n    out = bio_open_owner(outfile, outformat, private);\n    if (out == NULL)\n        goto end;\n    if (list_curves) {\n        EC_builtin_curve *curves = NULL;\n        size_t crv_len = EC_get_builtin_curves(NULL, 0);\n        size_t n;\n        curves = app_malloc((int)sizeof(*curves) * crv_len, "list curves");\n        if (!EC_get_builtin_curves(curves, crv_len)) {\n            OPENSSL_free(curves);\n            goto end;\n        }\n        for (n = 0; n < crv_len; n++) {\n            const char *comment;\n            const char *sname;\n            comment = curves[n].comment;\n            sname = OBJ_nid2sn(curves[n].nid);\n            if (comment == NULL)\n                comment = "CURVE DESCRIPTION NOT AVAILABLE";\n            if (sname == NULL)\n                sname = "";\n            BIO_printf(out, "  %-10s: ", sname);\n            BIO_printf(out, "%s\\n", comment);\n        }\n        OPENSSL_free(curves);\n        ret = 0;\n        goto end;\n    }\n    if (curve_name != NULL) {\n        int nid;\n        if (strcmp(curve_name, "secp192r1") == 0) {\n            BIO_printf(bio_err, "using curve name prime192v1 "\n                       "instead of secp192r1\\n");\n            nid = NID_X9_62_prime192v1;\n        } else if (strcmp(curve_name, "secp256r1") == 0) {\n            BIO_printf(bio_err, "using curve name prime256v1 "\n                       "instead of secp256r1\\n");\n            nid = NID_X9_62_prime256v1;\n        } else\n            nid = OBJ_sn2nid(curve_name);\n        if (nid == 0)\n            nid = EC_curve_nist2nid(curve_name);\n        if (nid == 0) {\n            BIO_printf(bio_err, "unknown curve name (%s)\\n", curve_name);\n            goto end;\n        }\n        group = EC_GROUP_new_by_curve_name(nid);\n        if (group == NULL) {\n            BIO_printf(bio_err, "unable to create curve (%s)\\n", curve_name);\n            goto end;\n        }\n        EC_GROUP_set_asn1_flag(group, asn1_flag);\n        EC_GROUP_set_point_conversion_form(group, form);\n    } else if (informat == FORMAT_ASN1)\n        group = d2i_ECPKParameters_bio(in, NULL);\n    else\n        group = PEM_read_bio_ECPKParameters(in, NULL, NULL, NULL);\n    if (group == NULL) {\n        BIO_printf(bio_err, "unable to load elliptic curve parameters\\n");\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    if (new_form)\n        EC_GROUP_set_point_conversion_form(group, form);\n    if (new_asn1_flag)\n        EC_GROUP_set_asn1_flag(group, asn1_flag);\n    if (no_seed) {\n        EC_GROUP_set_seed(group, NULL, 0);\n    }\n    if (text) {\n        if (!ECPKParameters_print(out, group, 0))\n            goto end;\n    }\n    if (check) {\n        BIO_printf(bio_err, "checking elliptic curve parameters: ");\n        if (!EC_GROUP_check(group, NULL)) {\n            BIO_printf(bio_err, "failed\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        BIO_printf(bio_err, "ok\\n");\n    }\n    if (C) {\n        size_t buf_len = 0, tmp_len = 0;\n        const EC_POINT *point;\n        int is_prime, len = 0;\n        const EC_METHOD *meth = EC_GROUP_method_of(group);\n        if ((ec_p = BN_new()) == NULL\n                || (ec_a = BN_new()) == NULL\n                || (ec_b = BN_new()) == NULL\n                || (ec_gen = BN_new()) == NULL\n                || (ec_order = BN_new()) == NULL\n                || (ec_cofactor = BN_new()) == NULL) {\n            perror("Can\'t allocate BN");\n            goto end;\n        }\n        is_prime = (EC_METHOD_get_field_type(meth) == NID_X9_62_prime_field);\n        if (!is_prime) {\n            BIO_printf(bio_err, "Can only handle X9.62 prime fields\\n");\n            goto end;\n        }\n        if (!EC_GROUP_get_curve_GFp(group, ec_p, ec_a, ec_b, NULL))\n            goto end;\n        if ((point = EC_GROUP_get0_generator(group)) == NULL)\n            goto end;\n        if (!EC_POINT_point2bn(group, point,\n                               EC_GROUP_get_point_conversion_form(group),\n                               ec_gen, NULL))\n            goto end;\n        if (!EC_GROUP_get_order(group, ec_order, NULL))\n            goto end;\n        if (!EC_GROUP_get_cofactor(group, ec_cofactor, NULL))\n            goto end;\n        if (!ec_p || !ec_a || !ec_b || !ec_gen || !ec_order || !ec_cofactor)\n            goto end;\n        len = BN_num_bits(ec_order);\n        if ((tmp_len = (size_t)BN_num_bytes(ec_p)) > buf_len)\n            buf_len = tmp_len;\n        if ((tmp_len = (size_t)BN_num_bytes(ec_a)) > buf_len)\n            buf_len = tmp_len;\n        if ((tmp_len = (size_t)BN_num_bytes(ec_b)) > buf_len)\n            buf_len = tmp_len;\n        if ((tmp_len = (size_t)BN_num_bytes(ec_gen)) > buf_len)\n            buf_len = tmp_len;\n        if ((tmp_len = (size_t)BN_num_bytes(ec_order)) > buf_len)\n            buf_len = tmp_len;\n        if ((tmp_len = (size_t)BN_num_bytes(ec_cofactor)) > buf_len)\n            buf_len = tmp_len;\n        buffer = app_malloc(buf_len, "BN buffer");\n        BIO_printf(out, "EC_GROUP *get_ec_group_%d(void)\\n{\\n", len);\n        print_bignum_var(out, ec_p, "ec_p", len, buffer);\n        print_bignum_var(out, ec_a, "ec_a", len, buffer);\n        print_bignum_var(out, ec_b, "ec_b", len, buffer);\n        print_bignum_var(out, ec_gen, "ec_gen", len, buffer);\n        print_bignum_var(out, ec_order, "ec_order", len, buffer);\n        print_bignum_var(out, ec_cofactor, "ec_cofactor", len, buffer);\n        BIO_printf(out, "    int ok = 0;\\n"\n                        "    EC_GROUP *group = NULL;\\n"\n                        "    EC_POINT *point = NULL;\\n"\n                        "    BIGNUM *tmp_1 = NULL;\\n"\n                        "    BIGNUM *tmp_2 = NULL;\\n"\n                        "    BIGNUM *tmp_3 = NULL;\\n"\n                        "\\n");\n        BIO_printf(out, "    if ((tmp_1 = BN_bin2bn(ec_p_%d, sizeof (ec_p_%d), NULL)) == NULL)\\n"\n                        "        goto err;\\n", len, len);\n        BIO_printf(out, "    if ((tmp_2 = BN_bin2bn(ec_a_%d, sizeof (ec_a_%d), NULL)) == NULL)\\n"\n                        "        goto err;\\n", len, len);\n        BIO_printf(out, "    if ((tmp_3 = BN_bin2bn(ec_b_%d, sizeof (ec_b_%d), NULL)) == NULL)\\n"\n                        "        goto err;\\n", len, len);\n        BIO_printf(out, "    if ((group = EC_GROUP_new_curve_GFp(tmp_1, tmp_2, tmp_3, NULL)) == NULL)\\n"\n                        "        goto err;\\n"\n                        "\\n");\n        BIO_printf(out, "    /* build generator */\\n");\n        BIO_printf(out, "    if ((tmp_1 = BN_bin2bn(ec_gen_%d, sizeof (ec_gen_%d), tmp_1)) == NULL)\\n"\n                        "        goto err;\\n", len, len);\n        BIO_printf(out, "    point = EC_POINT_bn2point(group, tmp_1, NULL, NULL);\\n");\n        BIO_printf(out, "    if (point == NULL)\\n"\n                        "        goto err;\\n");\n        BIO_printf(out, "    if ((tmp_2 = BN_bin2bn(ec_order_%d, sizeof (ec_order_%d), tmp_2)) == NULL)\\n"\n                        "        goto err;\\n", len, len);\n        BIO_printf(out, "    if ((tmp_3 = BN_bin2bn(ec_cofactor_%d, sizeof (ec_cofactor_%d), tmp_3)) == NULL)\\n"\n                        "        goto err;\\n", len, len);\n        BIO_printf(out, "    if (!EC_GROUP_set_generator(group, point, tmp_2, tmp_3))\\n"\n                        "        goto err;\\n"\n                        "ok = 1;"\n                        "\\n");\n        BIO_printf(out, "err:\\n"\n                        "    BN_free(tmp_1);\\n"\n                        "    BN_free(tmp_2);\\n"\n                        "    BN_free(tmp_3);\\n"\n                        "    EC_POINT_free(point);\\n"\n                        "    if (!ok) {\\n"\n                        "        EC_GROUP_free(group);\\n"\n                        "        return NULL;\\n"\n                        "    }\\n"\n                        "    return (group);\\n"\n                        "}\\n");\n    }\n    if (!noout) {\n        if (outformat == FORMAT_ASN1)\n            i = i2d_ECPKParameters_bio(out, group);\n        else\n            i = PEM_write_bio_ECPKParameters(out, group);\n        if (!i) {\n            BIO_printf(bio_err, "unable to write elliptic "\n                       "curve parameters\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n    }\n    if (need_rand) {\n        app_RAND_load_file(NULL, (inrand != NULL));\n        if (inrand != NULL)\n            BIO_printf(bio_err, "%ld semi-random bytes loaded\\n",\n                       app_RAND_load_files(inrand));\n    }\n    if (genkey) {\n        EC_KEY *eckey = EC_KEY_new();\n        if (eckey == NULL)\n            goto end;\n        assert(need_rand);\n        if (EC_KEY_set_group(eckey, group) == 0) {\n            BIO_printf(bio_err, "unable to set group when generating key\\n");\n            EC_KEY_free(eckey);\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        if (!EC_KEY_generate_key(eckey)) {\n            BIO_printf(bio_err, "unable to generate key\\n");\n            EC_KEY_free(eckey);\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        assert(private);\n        if (outformat == FORMAT_ASN1)\n            i = i2d_ECPrivateKey_bio(out, eckey);\n        else\n            i = PEM_write_bio_ECPrivateKey(out, eckey, NULL,\n                                           NULL, 0, NULL, NULL);\n        EC_KEY_free(eckey);\n    }\n    if (need_rand)\n        app_RAND_write_file(NULL);\n    ret = 0;\n end:\n    BN_free(ec_p);\n    BN_free(ec_a);\n    BN_free(ec_b);\n    BN_free(ec_gen);\n    BN_free(ec_order);\n    BN_free(ec_cofactor);\n    OPENSSL_free(buffer);\n    EC_GROUP_free(group);\n    release_engine(e);\n    BIO_free(in);\n    BIO_free_all(out);\n    return (ret);\n}', 'int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx)\n{\n    int ret = 0;\n    const BIGNUM *order;\n    BN_CTX *new_ctx = NULL;\n    EC_POINT *point = NULL;\n    if ((group->meth->flags & EC_FLAGS_CUSTOM_CURVE) != 0)\n        return 1;\n    if (ctx == NULL) {\n        ctx = new_ctx = BN_CTX_new();\n        if (ctx == NULL) {\n            ECerr(EC_F_EC_GROUP_CHECK, ERR_R_MALLOC_FAILURE);\n            goto err;\n        }\n    }\n    if (!EC_GROUP_check_discriminant(group, ctx)) {\n        ECerr(EC_F_EC_GROUP_CHECK, EC_R_DISCRIMINANT_IS_ZERO);\n        goto err;\n    }\n    if (group->generator == NULL) {\n        ECerr(EC_F_EC_GROUP_CHECK, EC_R_UNDEFINED_GENERATOR);\n        goto err;\n    }\n    if (EC_POINT_is_on_curve(group, group->generator, ctx) <= 0) {\n        ECerr(EC_F_EC_GROUP_CHECK, EC_R_POINT_IS_NOT_ON_CURVE);\n        goto err;\n    }\n    if ((point = EC_POINT_new(group)) == NULL)\n        goto err;\n    order = EC_GROUP_get0_order(group);\n    if (order == NULL)\n        goto err;\n    if (BN_is_zero(order)) {\n        ECerr(EC_F_EC_GROUP_CHECK, EC_R_UNDEFINED_ORDER);\n        goto err;\n    }\n    if (!EC_POINT_mul(group, point, order, NULL, NULL, ctx))\n        goto err;\n    if (!EC_POINT_is_at_infinity(group, point)) {\n        ECerr(EC_F_EC_GROUP_CHECK, EC_R_INVALID_GROUP_ORDER);\n        goto err;\n    }\n    ret = 1;\n err:\n    BN_CTX_free(new_ctx);\n    EC_POINT_free(point);\n    return ret;\n}', 'int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)\n{\n    if (group->order == NULL)\n        return 0;\n    if (!BN_copy(order, group->order))\n        return 0;\n    return !BN_is_zero(order);\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n    bn_check_top(b);\n    if (a == b)\n        return a;\n    if (bn_wexpand(a, b->top) == NULL)\n        return NULL;\n    if (b->top > 0)\n        memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n    a->top = b->top;\n    a->neg = b->neg;\n    bn_check_top(a);\n    return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n    bn_check_top(b);\n    if (words > b->dmax) {\n        BN_ULONG *a = bn_expand_internal(b, words);\n        if (!a)\n            return NULL;\n        if (b->d) {\n            OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n            bn_free_d(b);\n        }\n        b->d = a;\n        b->dmax = words;\n    }\n    bn_check_top(b);\n    return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n    BN_ULONG *a = NULL;\n    bn_check_top(b);\n    if (words > (INT_MAX / (4 * BN_BITS2))) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n        return NULL;\n    }\n    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n        return (NULL);\n    }\n    if (BN_get_flags(b, BN_FLG_SECURE))\n        a = OPENSSL_secure_zalloc(words * sizeof(*a));\n    else\n        a = OPENSSL_zalloc(words * sizeof(*a));\n    if (a == NULL) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n        return (NULL);\n    }\n    assert(b->top <= words);\n    if (b->top > 0)\n        memcpy(a, b->d, sizeof(*a) * b->top);\n    return a;\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    FAILTEST();\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num == 0)\n        return NULL;\n    FAILTEST();\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    osslargused(file); osslargused(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}']