test/ectest.c:1799: error: BUFFER_OVERRUN_L3
  Offset: [0, 7] Size: [0, +oo] by call to `EC_GROUP_new_from_ecparameters`.
Showing all 22 steps of the trace


test/ectest.c:1773:13: Call
1771.       if (!TEST_ptr(ctx = BN_CTX_new())
1772.           || !TEST_ptr(g = EC_GROUP_new_by_curve_name(nid))
1773.           || !TEST_ptr(p = EC_GROUP_get_ecparameters(g, NULL)))
                    ^
1774.           goto err;
1775.   

crypto/ec/ec_asn1.c:440:1: Parameter `*params->curve->seed->data`
  438.   }
  439.   
  440. > ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group,
  441.                                                  ECPARAMETERS *params)
  442.   {

test/ectest.c:1778:10: Call
1776.       /* replace with group from explicit parameters */
1777.       EC_GROUP_free(g);
1778.       if (!TEST_ptr(g = EC_GROUP_new_from_ecparameters(p)))
                 ^
1779.           goto err;
1780.   

crypto/ec/ec_asn1.c:568:1: Parameter `*params->base->data`
  566.   }
  567.   
  568. > EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params)
  569.   {
  570.       int ok = 0, tmp;

test/ectest.c:1794:21: Call
1792.            */
1793.           if (!TEST_ptr(ga = EC_GROUP_new_by_curve_name(rv))
1794.                   || !TEST_ptr(pa = EC_GROUP_get_ecparameters(ga, NULL)))
                            ^
1795.               goto err;
1796.   

crypto/ec/ec_asn1.c:440:1: Parameter `*params->curve->seed->data`
  438.   }
  439.   
  440. > ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group,
  441.                                                  ECPARAMETERS *params)
  442.   {

test/ectest.c:1799:14: Call
1797.           /* replace with group from explicit parameters, then compare */
1798.           EC_GROUP_free(ga);
1799.           if (!TEST_ptr(ga = EC_GROUP_new_from_ecparameters(pa))
                     ^
1800.                   || !TEST_int_eq(EC_GROUP_cmp(g, ga, ctx), 0))
1801.               goto err;

crypto/ec/ec_asn1.c:568:1: Parameter `*params->fieldID->p.char_two->p.tpBasis->data`
  566.   }
  567.   
  568. > EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params)
  569.   {
  570.       int ok = 0, tmp;

crypto/ec/ec_asn1.c:641:24: Call
  639.               }
  640.   
  641.               tmp_long = ASN1_INTEGER_get(char_two->p.tpBasis);
                                ^
  642.   
  643.               if (!(char_two->m > tmp_long && tmp_long > 0)) {

crypto/asn1/a_int.c:538:1: Parameter `*a->data`
    536.   }
    537.   
    538. > long ASN1_INTEGER_get(const ASN1_INTEGER *a)
    539.   {
    540.       int i;

crypto/asn1/a_int.c:544:9: Call
    542.       if (a == NULL)
    543.           return 0;
    544.       i = ASN1_INTEGER_get_int64(&r, a);
                   ^
    545.       if (i == 0)
    546.           return -1;

crypto/asn1/a_int.c:513:1: Parameter `*a->data`
      511.   }
      512.   
      513. > int ASN1_INTEGER_get_int64(int64_t *pr, const ASN1_INTEGER *a)
      514.   {
      515.       return asn1_string_get_int64(pr, a, V_ASN1_INTEGER);

crypto/asn1/a_int.c:515:12: Call
      513.   int ASN1_INTEGER_get_int64(int64_t *pr, const ASN1_INTEGER *a)
      514.   {
      515.       return asn1_string_get_int64(pr, a, V_ASN1_INTEGER);
                        ^
      516.   }
      517.   

crypto/asn1/a_int.c:319:1: Parameter `*a->data`
        317.   }
        318.   
        319. > static int asn1_string_get_int64(int64_t *pr, const ASN1_STRING *a, int itype)
        320.   {
        321.       if (a == NULL) {

crypto/asn1/a_int.c:329:12: Call
        327.           return 0;
        328.       }
        329.       return asn1_get_int64(pr, a->data, a->length, a->type & V_ASN1_NEG);
                          ^
        330.   }
        331.   

crypto/asn1/a_int.c:249:1: Parameter `blen`
          247.   
          248.   /* signed version of asn1_get_uint64 */
          249. > static int asn1_get_int64(int64_t *pr, const unsigned char *b, size_t blen,
          250.                             int neg)
          251.   {

crypto/asn1/a_int.c:253:9: Call
          251.   {
          252.       uint64_t r;
          253.       if (asn1_get_uint64(&r, b, blen) == 0)
                         ^
          254.           return 0;
          255.       if (neg) {

crypto/asn1/a_int.c:207:1: <Offset trace>
205.   
206.   /* Convert big endian buffer into uint64_t, return 0 on error */
207. > static int asn1_get_uint64(uint64_t *pr, const unsigned char *b, size_t blen)
208.   {
209.       size_t i;

crypto/asn1/a_int.c:207:1: Parameter `blen`
            205.   
            206.   /* Convert big endian buffer into uint64_t, return 0 on error */
            207. > static int asn1_get_uint64(uint64_t *pr, const unsigned char *b, size_t blen)
            208.   {
            209.       size_t i;

crypto/asn1/a_int.c:207:1: <Length trace>
205.   
206.   /* Convert big endian buffer into uint64_t, return 0 on error */
207. > static int asn1_get_uint64(uint64_t *pr, const unsigned char *b, size_t blen)
208.   {
209.       size_t i;

crypto/asn1/a_int.c:207:1: Parameter `*b`
            205.   
            206.   /* Convert big endian buffer into uint64_t, return 0 on error */
            207. > static int asn1_get_uint64(uint64_t *pr, const unsigned char *b, size_t blen)
            208.   {
            209.       size_t i;

crypto/asn1/a_int.c:220:14: Array access: Offset: [0, 7] Size: [0, +oo] by call to `EC_GROUP_new_from_ecparameters` 
            218.       for (r = 0, i = 0; i < blen; i++) {
            219.           r <<= 8;
            220.           r |= b[i];
                                ^
            221.       }
            222.       *pr = r;

static int asn1_get_uint64(uint64_t *pr, const unsigned char *b, size_t blen)
{
    size_t i;
    uint64_t r;
    if (blen > sizeof(*pr)) {
        ASN1err(ASN1_F_ASN1_GET_UINT64, ASN1_R_TOO_LARGE);
        return 0;
    }
    if (b == NULL)
        return 0;
    for (r = 0, i = 0; i < blen; i++) {
        r <<= 8;
        r |= b[i];
    }
    *pr = r;
    return 1;
}
['static int check_named_curve_lookup_test(int id)\n{\n    int ret = 0, nid, rv = 0;\n    EC_GROUP *g = NULL , *ga = NULL;\n    ECPARAMETERS *p = NULL, *pa = NULL;\n    BN_CTX *ctx = NULL;\n    nid = curves[id].nid;\n    if (!TEST_ptr(ctx = BN_CTX_new())\n        || !TEST_ptr(g = EC_GROUP_new_by_curve_name(nid))\n        || !TEST_ptr(p = EC_GROUP_get_ecparameters(g, NULL)))\n        goto err;\n    EC_GROUP_free(g);\n    if (!TEST_ptr(g = EC_GROUP_new_from_ecparameters(p)))\n        goto err;\n    if (!TEST_int_gt(rv = EC_GROUP_check_named_curve(g, 0), 0))\n        goto err;\n    if (rv != nid) {\n        if (!TEST_ptr(ga = EC_GROUP_new_by_curve_name(rv))\n                || !TEST_ptr(pa = EC_GROUP_get_ecparameters(ga, NULL)))\n            goto err;\n        EC_GROUP_free(ga);\n        if (!TEST_ptr(ga = EC_GROUP_new_from_ecparameters(pa))\n                || !TEST_int_eq(EC_GROUP_cmp(g, ga, ctx), 0))\n            goto err;\n    }\n    ret = 1;\n err:\n    EC_GROUP_free(g);\n    EC_GROUP_free(ga);\n    ECPARAMETERS_free(p);\n    ECPARAMETERS_free(pa);\n    BN_CTX_free(ctx);\n    return ret;\n}', 'ECPARAMETERS *EC_GROUP_get_ecparameters(const EC_GROUP *group,\n                                               ECPARAMETERS *params)\n{\n    size_t len = 0;\n    ECPARAMETERS *ret = NULL;\n    const BIGNUM *tmp;\n    unsigned char *buffer = NULL;\n    const EC_POINT *point = NULL;\n    point_conversion_form_t form;\n    if (params == NULL) {\n        if ((ret = ECPARAMETERS_new()) == NULL) {\n            ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_MALLOC_FAILURE);\n            goto err;\n        }\n    } else\n        ret = params;\n    ret->version = (long)0x1;\n    if (!ec_asn1_group2fieldid(group, ret->fieldID)) {\n        ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_EC_LIB);\n        goto err;\n    }\n    if (!ec_asn1_group2curve(group, ret->curve)) {\n        ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_EC_LIB);\n        goto err;\n    }\n    if ((point = EC_GROUP_get0_generator(group)) == NULL) {\n        ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, EC_R_UNDEFINED_GENERATOR);\n        goto err;\n    }\n    form = EC_GROUP_get_point_conversion_form(group);\n    len = EC_POINT_point2buf(group, point, form, &buffer, NULL);\n    if (len == 0) {\n        ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_EC_LIB);\n        goto err;\n    }\n    if (ret->base == NULL && (ret->base = ASN1_OCTET_STRING_new()) == NULL) {\n        OPENSSL_free(buffer);\n        ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    ASN1_STRING_set0(ret->base, buffer, len);\n    tmp = EC_GROUP_get0_order(group);\n    if (tmp == NULL) {\n        ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_EC_LIB);\n        goto err;\n    }\n    ret->order = BN_to_ASN1_INTEGER(tmp, ret->order);\n    if (ret->order == NULL) {\n        ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_ASN1_LIB);\n        goto err;\n    }\n    tmp = EC_GROUP_get0_cofactor(group);\n    if (tmp != NULL) {\n        ret->cofactor = BN_to_ASN1_INTEGER(tmp, ret->cofactor);\n        if (ret->cofactor == NULL) {\n            ECerr(EC_F_EC_GROUP_GET_ECPARAMETERS, ERR_R_ASN1_LIB);\n            goto err;\n        }\n    }\n    return ret;\n err:\n    if (params == NULL)\n        ECPARAMETERS_free(ret);\n    return NULL;\n}', 'EC_GROUP *EC_GROUP_new_from_ecparameters(const ECPARAMETERS *params)\n{\n    int ok = 0, tmp;\n    EC_GROUP *ret = NULL;\n    BIGNUM *p = NULL, *a = NULL, *b = NULL;\n    EC_POINT *point = NULL;\n    long field_bits;\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    ok = 1;\n err:\n    if (!ok) {\n        EC_GROUP_clear_free(ret);\n        ret = NULL;\n    }\n    BN_free(p);\n    BN_free(a);\n    BN_free(b);\n    EC_POINT_free(point);\n    return ret;\n}', 'long ASN1_INTEGER_get(const ASN1_INTEGER *a)\n{\n    int i;\n    int64_t r;\n    if (a == NULL)\n        return 0;\n    i = ASN1_INTEGER_get_int64(&r, a);\n    if (i == 0)\n        return -1;\n    if (r > LONG_MAX || r < LONG_MIN)\n        return -1;\n    return (long)r;\n}', 'int ASN1_INTEGER_get_int64(int64_t *pr, const ASN1_INTEGER *a)\n{\n    return asn1_string_get_int64(pr, a, V_ASN1_INTEGER);\n}', 'static int asn1_string_get_int64(int64_t *pr, const ASN1_STRING *a, int itype)\n{\n    if (a == NULL) {\n        ASN1err(ASN1_F_ASN1_STRING_GET_INT64, ERR_R_PASSED_NULL_PARAMETER);\n        return 0;\n    }\n    if ((a->type & ~V_ASN1_NEG) != itype) {\n        ASN1err(ASN1_F_ASN1_STRING_GET_INT64, ASN1_R_WRONG_INTEGER_TYPE);\n        return 0;\n    }\n    return asn1_get_int64(pr, a->data, a->length, a->type & V_ASN1_NEG);\n}', 'static int asn1_get_int64(int64_t *pr, const unsigned char *b, size_t blen,\n                          int neg)\n{\n    uint64_t r;\n    if (asn1_get_uint64(&r, b, blen) == 0)\n        return 0;\n    if (neg) {\n        if (r <= INT64_MAX) {\n            *pr = -(int64_t)r;\n        } else if (r == ABS_INT64_MIN) {\n            *pr = (int64_t)(0 - r);\n        } else {\n            ASN1err(ASN1_F_ASN1_GET_INT64, ASN1_R_TOO_SMALL);\n            return 0;\n        }\n    } else {\n        if (r <= INT64_MAX) {\n            *pr = (int64_t)r;\n        } else {\n            ASN1err(ASN1_F_ASN1_GET_INT64, ASN1_R_TOO_LARGE);\n            return 0;\n        }\n    }\n    return 1;\n}', 'static int asn1_get_uint64(uint64_t *pr, const unsigned char *b, size_t blen)\n{\n    size_t i;\n    uint64_t r;\n    if (blen > sizeof(*pr)) {\n        ASN1err(ASN1_F_ASN1_GET_UINT64, ASN1_R_TOO_LARGE);\n        return 0;\n    }\n    if (b == NULL)\n        return 0;\n    for (r = 0, i = 0; i < blen; i++) {\n        r <<= 8;\n        r |= b[i];\n    }\n    *pr = r;\n    return 1;\n}']