test/ectest.c:1957: error: INTEGER_OVERFLOW_L2
  ([-oo, 9223372036854775807] + 1):signed32 by call to `EC_GROUP_new_from_ecparameters`.
Showing all 6 steps of the trace


test/ectest.c:1957:10: Call
1955.        * "named" EC_GROUP
1956.        */
1957.       if (!TEST_ptr(tgroup = *g_next++ = EC_GROUP_new_from_ecparameters(params))
                 ^
1958.           || !TEST_int_ne((tnid = EC_GROUP_get_curve_name(tgroup)), NID_undef))
1959.           goto err;

crypto/ec/ec_asn1.c:571:1: Parameter `params->fieldID->p.char_two->m`
  569.   }
  570.   
  571. > EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params)
  572.   {
  573.       int ok = 0, tmp;

crypto/ec/ec_asn1.c:657:18: Call
  655.               if (!BN_set_bit(p, (int)char_two->m))
  656.                   goto err;
  657.               if (!BN_set_bit(p, (int)tmp_long))
                          ^
  658.                   goto err;
  659.               if (!BN_set_bit(p, 0))

crypto/bn/bn_lib.c:667:1: <LHS trace>
665.   }
666.   
667. > int BN_set_bit(BIGNUM *a, int n)
668.   {
669.       int i, j, k;

crypto/bn/bn_lib.c:667:1: Parameter `a->top`
    665.   }
    666.   
    667. > int BN_set_bit(BIGNUM *a, int n)
    668.   {
    669.       int i, j, k;

crypto/bn/bn_lib.c:679:37: Binary operation: ([-oo, 9223372036854775807] + 1):signed32 by call to `EC_GROUP_new_from_ecparameters` 
    677.           if (bn_wexpand(a, i + 1) == NULL)
    678.               return 0;
    679.           for (k = a->top; k < i + 1; k++)
                                               ^
    680.               a->d[k] = 0;
    681.           a->top = i + 1;

int BN_set_bit(BIGNUM *a, int n)
{
    int i, j, k;
    if (n < 0)
        return 0;
    i = n / BN_BITS2;
    j = n % BN_BITS2;
    if (a->top <= i) {
        if (bn_wexpand(a, i + 1) == NULL)
            return 0;
        for (k = a->top; k < i + 1; k++)
            a->d[k] = 0;
        a->top = i + 1;
        a->flags &= ~BN_FLG_FIXED_TOP;
    }
    a->d[i] |= (((BN_ULONG)1) << j);
    bn_check_top(a);
    return 1;
}
['static int check_named_curve_from_ecparameters(int id)\n{\n    int ret = 0, nid, tnid;\n    EC_GROUP *group = NULL, *tgroup = NULL, *tmpg = NULL;\n    const EC_POINT *group_gen = NULL;\n    EC_POINT *other_gen = NULL;\n    BIGNUM *group_cofactor = NULL, *other_cofactor = NULL;\n    BIGNUM *other_gen_x = NULL, *other_gen_y = NULL;\n    const BIGNUM *group_order = NULL;\n    BIGNUM *other_order = NULL;\n    BN_CTX *bn_ctx = NULL;\n    static const unsigned char invalid_seed[] = "THIS IS NOT A VALID SEED";\n    static size_t invalid_seed_len = sizeof(invalid_seed);\n    ECPARAMETERS *params = NULL, *other_params = NULL;\n    EC_GROUP *g_ary[8] = {NULL};\n    EC_GROUP **g_next = &g_ary[0];\n    ECPARAMETERS *p_ary[8] = {NULL};\n    ECPARAMETERS **p_next = &p_ary[0];\n    nid = curves[id].nid;\n    TEST_note("Curve %s", OBJ_nid2sn(nid));\n    if (!TEST_ptr(bn_ctx = BN_CTX_new()))\n        return ret;\n    BN_CTX_start(bn_ctx);\n    if (\n        !TEST_ptr(group_cofactor = BN_CTX_get(bn_ctx))\n        || !TEST_ptr(other_gen_x = BN_CTX_get(bn_ctx))\n        || !TEST_ptr(other_gen_y = BN_CTX_get(bn_ctx))\n        || !TEST_ptr(other_order = BN_CTX_get(bn_ctx))\n        || !TEST_ptr(other_cofactor = BN_CTX_get(bn_ctx))\n        || !TEST_ptr(group = EC_GROUP_new_by_curve_name(nid))\n        || !TEST_ptr(params = EC_GROUP_get_ecparameters(group, NULL))\n        || !TEST_ptr(group_gen = EC_GROUP_get0_generator(group))\n        || !TEST_ptr(group_order = EC_GROUP_get0_order(group))\n        || !TEST_true(EC_GROUP_get_cofactor(group, group_cofactor, NULL))\n        || !TEST_ptr(tmpg = EC_GROUP_dup(group))\n        || !TEST_ptr(other_gen = EC_POINT_dup(group_gen, group))\n        || !TEST_true(EC_POINT_add(group, other_gen, group_gen, group_gen, NULL))\n        || !TEST_true(EC_POINT_get_affine_coordinates(group, other_gen,\n                      other_gen_x, other_gen_y, bn_ctx))\n        || !TEST_true(BN_copy(other_order, group_order))\n        || !TEST_true(BN_add_word(other_order, 1))\n        || !TEST_true(BN_copy(other_cofactor, group_cofactor))\n        || !TEST_true(BN_add_word(other_cofactor, 1)))\n        goto err;\n    EC_POINT_free(other_gen);\n    other_gen = NULL;\n    if (!TEST_ptr(other_gen = EC_POINT_new(tmpg))\n        || !TEST_true(EC_POINT_set_affine_coordinates(tmpg, other_gen,\n                                                      other_gen_x, other_gen_y,\n                                                      bn_ctx)))\n        goto err;\n    if (!TEST_ptr(tgroup = *g_next++ = EC_GROUP_new_from_ecparameters(params))\n        || !TEST_int_ne((tnid = EC_GROUP_get_curve_name(tgroup)), NID_undef))\n        goto err;\n    if (!TEST_true(are_ec_nids_compatible(nid, tnid))) {\n        TEST_info("nid = %s, tnid = %s", OBJ_nid2sn(nid), OBJ_nid2sn(tnid));\n        goto err;\n    }\n    if (!TEST_int_eq(EC_GROUP_get_asn1_flag(tgroup), OPENSSL_EC_EXPLICIT_CURVE))\n        goto err;\n    if (!TEST_int_eq(EC_GROUP_set_seed(tmpg, invalid_seed, invalid_seed_len),\n                     invalid_seed_len)\n            || !TEST_ptr(other_params = *p_next++ =\n                         EC_GROUP_get_ecparameters(tmpg, NULL))\n            || !TEST_ptr(tgroup = *g_next++ =\n                          EC_GROUP_new_from_ecparameters(other_params))\n            || !TEST_int_ne((tnid = EC_GROUP_get_curve_name(tgroup)), NID_undef)\n            || !TEST_true(are_ec_nids_compatible(nid, tnid))\n            || !TEST_int_eq(EC_GROUP_get_asn1_flag(tgroup),\n                            OPENSSL_EC_EXPLICIT_CURVE)) {\n        TEST_info("nid = %s, tnid = %s", OBJ_nid2sn(nid), OBJ_nid2sn(tnid));\n        goto err;\n    }\n    if (!TEST_int_eq(EC_GROUP_set_seed(tmpg, NULL, 0), 1)\n            || !TEST_ptr(other_params = *p_next++ =\n                         EC_GROUP_get_ecparameters(tmpg, NULL))\n            || !TEST_ptr(tgroup = *g_next++ =\n                          EC_GROUP_new_from_ecparameters(other_params))\n            || !TEST_int_ne((tnid = EC_GROUP_get_curve_name(tgroup)), NID_undef)\n            || !TEST_true(are_ec_nids_compatible(nid, tnid))\n            || !TEST_int_eq(EC_GROUP_get_asn1_flag(tgroup),\n                            OPENSSL_EC_EXPLICIT_CURVE)) {\n        TEST_info("nid = %s, tnid = %s", OBJ_nid2sn(nid), OBJ_nid2sn(tnid));\n        goto err;\n    }\n    if (\n        !TEST_true(EC_GROUP_set_generator(tmpg, other_gen, group_order,\n                                          group_cofactor))\n        || !TEST_ptr(other_params = *p_next++ =\n                     EC_GROUP_get_ecparameters(tmpg, NULL))\n        || !TEST_ptr(tgroup = *g_next++ =\n                      EC_GROUP_new_from_ecparameters(other_params))\n        || !TEST_int_eq((tnid = EC_GROUP_get_curve_name(tgroup)), NID_undef)\n        || !TEST_true(EC_GROUP_set_generator(tmpg, group_gen, other_order,\n                                             group_cofactor))\n        || !TEST_ptr(other_params = *p_next++ =\n                     EC_GROUP_get_ecparameters(tmpg, NULL))\n        || !TEST_ptr(tgroup = *g_next++ =\n                      EC_GROUP_new_from_ecparameters(other_params))\n        || !TEST_int_eq((tnid = EC_GROUP_get_curve_name(tgroup)), NID_undef)\n        || !TEST_false(EC_GROUP_set_generator(tmpg, group_gen, NULL,\n                                              group_cofactor))\n        || !TEST_true(EC_GROUP_set_generator(tmpg, group_gen, group_order,\n                                             other_cofactor))\n        || !TEST_ptr(other_params = *p_next++ =\n                     EC_GROUP_get_ecparameters(tmpg, NULL))\n        || !TEST_ptr(tgroup = *g_next++ =\n                      EC_GROUP_new_from_ecparameters(other_params))\n        || !TEST_int_ne((tnid = EC_GROUP_get_curve_name(tgroup)), NID_undef)\n        || !TEST_true(are_ec_nids_compatible(nid, tnid))\n        || !TEST_int_eq(EC_GROUP_get_asn1_flag(tgroup),\n                        OPENSSL_EC_EXPLICIT_CURVE)\n        || !TEST_true(EC_GROUP_set_generator(tmpg, group_gen, group_order,\n                                             NULL))\n        || !TEST_ptr(other_params = *p_next++ =\n                     EC_GROUP_get_ecparameters(tmpg, NULL))\n        || !TEST_ptr(tgroup = *g_next++ =\n                      EC_GROUP_new_from_ecparameters(other_params))\n        || !TEST_int_ne((tnid = EC_GROUP_get_curve_name(tgroup)), NID_undef)\n        || !TEST_true(are_ec_nids_compatible(nid, tnid))\n        || !TEST_int_eq(EC_GROUP_get_asn1_flag(tgroup),\n                        OPENSSL_EC_EXPLICIT_CURVE)\n        || !TEST_true(EC_GROUP_set_generator(tmpg, group_gen, group_order,\n                                             group_cofactor))\n        || !TEST_ptr(other_params = *p_next++ =\n                     EC_GROUP_get_ecparameters(tmpg, NULL))\n        || !TEST_ptr(tgroup = *g_next++ =\n                      EC_GROUP_new_from_ecparameters(other_params))\n        || !TEST_int_ne((tnid = EC_GROUP_get_curve_name(tgroup)), NID_undef)\n        || !TEST_true(are_ec_nids_compatible(nid, tnid))\n        || !TEST_int_eq(EC_GROUP_get_asn1_flag(tgroup),\n                        OPENSSL_EC_EXPLICIT_CURVE))\n        goto err;\n    ret = 1;\nerr:\n    for (g_next = &g_ary[0]; g_next < g_ary + OSSL_NELEM(g_ary); g_next++)\n        EC_GROUP_free(*g_next);\n    for (p_next = &p_ary[0]; p_next < p_ary + OSSL_NELEM(g_ary); p_next++)\n        ECPARAMETERS_free(*p_next);\n    ECPARAMETERS_free(params);\n    EC_POINT_free(other_gen);\n    EC_GROUP_free(tmpg);\n    EC_GROUP_free(group);\n    BN_CTX_end(bn_ctx);\n    BN_CTX_free(bn_ctx);\n    return ret;\n}', 'EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params)\n{\n    int ok = 0, tmp;\n    EC_GROUP *ret = NULL, *dup = NULL;\n    BIGNUM *p = NULL, *a = NULL, *b = NULL;\n    EC_POINT *point = NULL;\n    long field_bits;\n    int curve_name = NID_undef;\n    BN_CTX *ctx = NULL;\n    if (!params->fieldID || !params->fieldID->fieldType ||\n        !params->fieldID->p.ptr) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR);\n        goto err;\n    }\n    if (!params->curve || !params->curve->a ||\n        !params->curve->a->data || !params->curve->b ||\n        !params->curve->b->data) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR);\n        goto err;\n    }\n    a = BN_bin2bn(params->curve->a->data, params->curve->a->length, NULL);\n    if (a == NULL) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_BN_LIB);\n        goto err;\n    }\n    b = BN_bin2bn(params->curve->b->data, params->curve->b->length, NULL);\n    if (b == NULL) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_BN_LIB);\n        goto err;\n    }\n    tmp = OBJ_obj2nid(params->fieldID->fieldType);\n    if (tmp == NID_X9_62_characteristic_two_field)\n#ifdef OPENSSL_NO_EC2M\n    {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_GF2M_NOT_SUPPORTED);\n        goto err;\n    }\n#else\n    {\n        X9_62_CHARACTERISTIC_TWO *char_two;\n        char_two = params->fieldID->p.char_two;\n        field_bits = char_two->m;\n        if (field_bits > OPENSSL_ECC_MAX_FIELD_BITS) {\n            ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_FIELD_TOO_LARGE);\n            goto err;\n        }\n        if ((p = BN_new()) == NULL) {\n            ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_MALLOC_FAILURE);\n            goto err;\n        }\n        tmp = OBJ_obj2nid(char_two->type);\n        if (tmp == NID_X9_62_tpBasis) {\n            long tmp_long;\n            if (!char_two->p.tpBasis) {\n                ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR);\n                goto err;\n            }\n            tmp_long = ASN1_INTEGER_get(char_two->p.tpBasis);\n            if (!(char_two->m > tmp_long && tmp_long > 0)) {\n                ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS,\n                      EC_R_INVALID_TRINOMIAL_BASIS);\n                goto err;\n            }\n            if (!BN_set_bit(p, (int)char_two->m))\n                goto err;\n            if (!BN_set_bit(p, (int)tmp_long))\n                goto err;\n            if (!BN_set_bit(p, 0))\n                goto err;\n        } else if (tmp == NID_X9_62_ppBasis) {\n            X9_62_PENTANOMIAL *penta;\n            penta = char_two->p.ppBasis;\n            if (!penta) {\n                ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR);\n                goto err;\n            }\n            if (!\n                (char_two->m > penta->k3 && penta->k3 > penta->k2\n                 && penta->k2 > penta->k1 && penta->k1 > 0)) {\n                ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS,\n                      EC_R_INVALID_PENTANOMIAL_BASIS);\n                goto err;\n            }\n            if (!BN_set_bit(p, (int)char_two->m))\n                goto err;\n            if (!BN_set_bit(p, (int)penta->k1))\n                goto err;\n            if (!BN_set_bit(p, (int)penta->k2))\n                goto err;\n            if (!BN_set_bit(p, (int)penta->k3))\n                goto err;\n            if (!BN_set_bit(p, 0))\n                goto err;\n        } else if (tmp == NID_X9_62_onBasis) {\n            ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_NOT_IMPLEMENTED);\n            goto err;\n        } else {\n            ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR);\n            goto err;\n        }\n        ret = EC_GROUP_new_curve_GF2m(p, a, b, NULL);\n    }\n#endif\n    else if (tmp == NID_X9_62_prime_field) {\n        if (!params->fieldID->p.prime) {\n            ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR);\n            goto err;\n        }\n        p = ASN1_INTEGER_to_BN(params->fieldID->p.prime, NULL);\n        if (p == NULL) {\n            ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_ASN1_LIB);\n            goto err;\n        }\n        if (BN_is_negative(p) || BN_is_zero(p)) {\n            ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_INVALID_FIELD);\n            goto err;\n        }\n        field_bits = BN_num_bits(p);\n        if (field_bits > OPENSSL_ECC_MAX_FIELD_BITS) {\n            ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_FIELD_TOO_LARGE);\n            goto err;\n        }\n        ret = EC_GROUP_new_curve_GFp(p, a, b, NULL);\n    } else {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_INVALID_FIELD);\n        goto err;\n    }\n    if (ret == NULL) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_EC_LIB);\n        goto err;\n    }\n    if (params->curve->seed != NULL) {\n        OPENSSL_free(ret->seed);\n        if ((ret->seed = OPENSSL_malloc(params->curve->seed->length)) == NULL) {\n            ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_MALLOC_FAILURE);\n            goto err;\n        }\n        memcpy(ret->seed, params->curve->seed->data,\n               params->curve->seed->length);\n        ret->seed_len = params->curve->seed->length;\n    }\n    if (!params->order || !params->base || !params->base->data) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_ASN1_ERROR);\n        goto err;\n    }\n    if ((point = EC_POINT_new(ret)) == NULL)\n        goto err;\n    EC_GROUP_set_point_conversion_form(ret, (point_conversion_form_t)\n                                       (params->base->data[0] & ~0x01));\n    if (!EC_POINT_oct2point(ret, point, params->base->data,\n                            params->base->length, NULL)) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_EC_LIB);\n        goto err;\n    }\n    if ((a = ASN1_INTEGER_to_BN(params->order, a)) == NULL) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_ASN1_LIB);\n        goto err;\n    }\n    if (BN_is_negative(a) || BN_is_zero(a)) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_INVALID_GROUP_ORDER);\n        goto err;\n    }\n    if (BN_num_bits(a) > (int)field_bits + 1) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, EC_R_INVALID_GROUP_ORDER);\n        goto err;\n    }\n    if (params->cofactor == NULL) {\n        BN_free(b);\n        b = NULL;\n    } else if ((b = ASN1_INTEGER_to_BN(params->cofactor, b)) == NULL) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_ASN1_LIB);\n        goto err;\n    }\n    if (!EC_GROUP_set_generator(ret, point, a, b)) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_EC_LIB);\n        goto err;\n    }\n    if ((ctx = BN_CTX_new()) == NULL) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_BN_LIB);\n        goto err;\n    }\n    if ((dup = EC_GROUP_dup(ret)) == NULL\n            || EC_GROUP_set_seed(dup, NULL, 0) != 1\n            || !EC_GROUP_set_generator(dup, point, a, NULL)) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_EC_LIB);\n        goto err;\n    }\n    if ((curve_name = ec_curve_nid_from_params(dup, ctx)) != NID_undef) {\n        EC_GROUP *named_group = NULL;\n#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128\n        if (curve_name == NID_wap_wsg_idm_ecid_wtls12)\n            curve_name = NID_secp224r1;\n#endif\n        if ((named_group = EC_GROUP_new_by_curve_name(curve_name)) == NULL) {\n            ECerr(EC_F_EC_GROUP_NEW_FROM_ECPARAMETERS, ERR_R_EC_LIB);\n            goto err;\n        }\n        EC_GROUP_free(ret);\n        ret = named_group;\n        EC_GROUP_set_asn1_flag(ret, OPENSSL_EC_EXPLICIT_CURVE);\n    }\n    ok = 1;\n err:\n    if (!ok) {\n        EC_GROUP_free(ret);\n        ret = NULL;\n    }\n    EC_GROUP_free(dup);\n    BN_free(p);\n    BN_free(a);\n    BN_free(b);\n    EC_POINT_free(point);\n    BN_CTX_free(ctx);\n    return ret;\n}', 'int BN_set_bit(BIGNUM *a, int n)\n{\n    int i, j, k;\n    if (n < 0)\n        return 0;\n    i = n / BN_BITS2;\n    j = n % BN_BITS2;\n    if (a->top <= i) {\n        if (bn_wexpand(a, i + 1) == NULL)\n            return 0;\n        for (k = a->top; k < i + 1; k++)\n            a->d[k] = 0;\n        a->top = i + 1;\n        a->flags &= ~BN_FLG_FIXED_TOP;\n    }\n    a->d[i] |= (((BN_ULONG)1) << j);\n    bn_check_top(a);\n    return 1;\n}']