engines/ccgost/gost_ameth.c:279: error: BUFFER_OVERRUN_L3
  Offset: [3, +oo] (⇐ [0, +oo] + 3) Size: [0, 8388607] by call to `BN_bin2bn`.
Showing all 16 steps of the trace


engines/ccgost/gost_ameth.c:263:10: Call
261.           return 0;
262.       p = pkey_buf;
263.       if (!decode_gost_algor_params(pk, palg)) {
                ^
264.           return 0;
265.       }

engines/ccgost/gost_ameth.c:125:22: Call
  123.               EC_KEY *ec = EVP_PKEY_get0(pkey);
  124.               if (!ec) {
  125.                   ec = EC_KEY_new();
                              ^
  126.                   if (!EVP_PKEY_assign(pkey, pkey_nid, ec))
  127.                       return 0;

crypto/ec/ec_key.c:74:12: Call
    72.   EC_KEY *EC_KEY_new(void)
    73.   {
    74.       return EC_KEY_new_method(NULL);
                     ^
    75.   }
    76.   

crypto/ec/ec_kmeth.c:130:9: Call
      128.       ret->references = 1;
      129.       if (ret->meth->init != NULL && ret->meth->init(ret) == 0) {
      130.           EC_KEY_free(ret);
                     ^
      131.           return NULL;
      132.       }

crypto/ec/ec_key.c:95:1: Parameter `r->priv_key->d`
        93.   }
        94.   
        95. > void EC_KEY_free(EC_KEY *r)
        96.   {
        97.       int i;

engines/ccgost/gost_ameth.c:279:18: Call
277.           }
278.           ASN1_STRING_free(s);
279.           pk_num = BN_bin2bn(rev_buf, 32, NULL);
                        ^
280.       } else {
281.           priv_key = d2i_ASN1_INTEGER(NULL, &p, priv_len);

crypto/bn/bn_lib.c:542:1: Parameter `*ret->d`
  540.   }
  541.   
  542. > BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
  543.   {
  544.       unsigned int i, m;

crypto/bn/bn_lib.c:564:9: Call
  562.       i = ((n - 1) / BN_BYTES) + 1;
  563.       m = ((n - 1) % (BN_BYTES));
  564.       if (bn_wexpand(ret, (int)i) == NULL) {
                 ^
  565.           BN_free(bn);
  566.           return NULL;

crypto/bn/bn_lib.c:995:1: Parameter `*a->d`
    993.   }
    994.   
    995. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
    996.   {
    997.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:997:37: Call
    995.   BIGNUM *bn_wexpand(BIGNUM *a, int words)
    996.   {
    997.       return (words <= a->dmax) ? a : bn_expand2(a, words);
                                                ^
    998.   }
    999.   

crypto/bn/bn_lib.c:390:1: Parameter `*b->d`
      388.    */
      389.   
      390. > BIGNUM *bn_expand2(BIGNUM *b, int words)
      391.   {
      392.       bn_check_top(b);

crypto/bn/bn_lib.c:395:23: Call
      393.   
      394.       if (words > b->dmax) {
      395.           BN_ULONG *a = bn_expand_internal(b, words);
                                   ^
      396.           if (!a)
      397.               return NULL;

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

crypto/bn/bn_lib.c:300:1: Parameter `*b->d`
        298.   /* This is used by bn_expand2() */
        299.   /* The caller MUST check that words > b->dmax before calling this */
        300. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
        301.   {
        302.       BN_ULONG *A, *a = NULL;

crypto/bn/bn_lib.c:335:5: Assignment
        333.   
        334.   #if 1
        335.       B = b->d;
                   ^
        336.       /* Check if the previous number needs to be copied */
        337.       if (B != NULL) {

crypto/bn/bn_lib.c:352:18: Array access: Offset: [3, +oo] (⇐ [0, +oo] + 3) Size: [0, 8388607] by call to `BN_bin2bn` 
        350.               a1 = B[1];
        351.               a2 = B[2];
        352.               a3 = B[3];
                                ^
        353.               A[0] = a0;
        354.               A[1] = a1;

static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *A, *a = NULL;
    const BN_ULONG *B;
    int i;
    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 = A = OPENSSL_secure_malloc(words * sizeof(*a));
    else
        a = A = OPENSSL_malloc(words * sizeof(*a));
    if (A == NULL) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
        return (NULL);
    }
#ifdef PURIFY
    memset(a, 0, sizeof(*a) * words);
#endif
#if 1
    B = b->d;
    if (B != NULL) {
        for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {
            BN_ULONG a0, a1, a2, a3;
            a0 = B[0];
            a1 = B[1];
            a2 = B[2];
            a3 = B[3];
            A[0] = a0;
            A[1] = a1;
            A[2] = a2;
            A[3] = a3;
        }
        switch (b->top & 3) {
        case 3:
            A[2] = B[2];
        case 2:
            A[1] = B[1];
        case 1:
            A[0] = B[0];
        case 0:
            ;
        }
    }
#else
    memset(A, 0, sizeof(*A) * words);
    memcpy(A, b->d, sizeof(b->d[0]) * b->top);
#endif
    return (a);
}
['static int priv_decode_gost(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf)\n{\n    const unsigned char *pkey_buf = NULL, *p = NULL;\n    int priv_len = 0;\n    BIGNUM *pk_num = NULL;\n    int ret = 0;\n    X509_ALGOR *palg = NULL;\n    ASN1_OBJECT *palg_obj = NULL;\n    ASN1_INTEGER *priv_key = NULL;\n    if (!PKCS8_pkey_get0(&palg_obj, &pkey_buf, &priv_len, &palg, p8inf))\n        return 0;\n    p = pkey_buf;\n    if (!decode_gost_algor_params(pk, palg)) {\n        return 0;\n    }\n    if (V_ASN1_OCTET_STRING == *p) {\n        unsigned char rev_buf[32];\n        int i;\n        ASN1_OCTET_STRING *s = d2i_ASN1_OCTET_STRING(NULL, &p, priv_len);\n        if (!s || s->length != 32) {\n            GOSTerr(GOST_F_PRIV_DECODE_GOST, EVP_R_DECODE_ERROR);\n            return 0;\n        }\n        for (i = 0; i < 32; i++) {\n            rev_buf[31 - i] = s->data[i];\n        }\n        ASN1_STRING_free(s);\n        pk_num = BN_bin2bn(rev_buf, 32, NULL);\n    } else {\n        priv_key = d2i_ASN1_INTEGER(NULL, &p, priv_len);\n        if (!priv_key)\n            return 0;\n        ret = ((pk_num = ASN1_INTEGER_to_BN(priv_key, NULL)) != NULL);\n        ASN1_INTEGER_free(priv_key);\n        if (!ret) {\n            GOSTerr(GOST_F_PRIV_DECODE_GOST, EVP_R_DECODE_ERROR);\n            return 0;\n        }\n    }\n    ret = gost_set_priv_key(pk, pk_num);\n    BN_free(pk_num);\n    return ret;\n}', 'static int decode_gost_algor_params(EVP_PKEY *pkey, X509_ALGOR *palg)\n{\n    ASN1_OBJECT *palg_obj = NULL;\n    int ptype = V_ASN1_UNDEF;\n    int pkey_nid = NID_undef, param_nid = NID_undef;\n    void *_pval;\n    ASN1_STRING *pval = NULL;\n    const unsigned char *p;\n    GOST_KEY_PARAMS *gkp = NULL;\n    X509_ALGOR_get0(&palg_obj, &ptype, &_pval, palg);\n    pval = _pval;\n    if (ptype != V_ASN1_SEQUENCE) {\n        GOSTerr(GOST_F_DECODE_GOST_ALGOR_PARAMS,\n                GOST_R_BAD_KEY_PARAMETERS_FORMAT);\n        return 0;\n    }\n    p = pval->data;\n    pkey_nid = OBJ_obj2nid(palg_obj);\n    gkp = d2i_GOST_KEY_PARAMS(NULL, &p, pval->length);\n    if (!gkp) {\n        GOSTerr(GOST_F_DECODE_GOST_ALGOR_PARAMS,\n                GOST_R_BAD_PKEY_PARAMETERS_FORMAT);\n        return 0;\n    }\n    param_nid = OBJ_obj2nid(gkp->key_params);\n    GOST_KEY_PARAMS_free(gkp);\n    if (!EVP_PKEY_set_type(pkey, pkey_nid)) {\n        GOSTerr(GOST_F_DECODE_GOST_ALGOR_PARAMS, ERR_R_INTERNAL_ERROR);\n        return 0;\n    }\n    switch (pkey_nid) {\n    case NID_id_GostR3410_2001:\n        {\n            EC_KEY *ec = EVP_PKEY_get0(pkey);\n            if (!ec) {\n                ec = EC_KEY_new();\n                if (!EVP_PKEY_assign(pkey, pkey_nid, ec))\n                    return 0;\n            }\n            if (!fill_GOST2001_params(ec, param_nid))\n                return 0;\n        }\n    }\n    return 1;\n}', 'EC_KEY *EC_KEY_new(void)\n{\n    return EC_KEY_new_method(NULL);\n}', 'EC_KEY *EC_KEY_new_method(ENGINE *engine)\n{\n    EC_KEY *ret = OPENSSL_zalloc(sizeof(*ret));\n    if (ret == NULL) {\n        ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_MALLOC_FAILURE);\n        return (NULL);\n    }\n    ret->meth = EC_KEY_get_default_method();\n#ifndef OPENSSL_NO_ENGINE\n    if (engine != NULL) {\n        if (!ENGINE_init(engine)) {\n            ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_ENGINE_LIB);\n            OPENSSL_free(ret);\n            return NULL;\n        }\n        ret->engine = engine;\n    } else\n        ret->engine = ENGINE_get_default_EC();\n    if (ret->engine != NULL) {\n        ret->meth = ENGINE_get_EC(ret->engine);\n        if (ret->meth == NULL) {\n            ECerr(EC_F_EC_KEY_NEW_METHOD, ERR_R_ENGINE_LIB);\n            ENGINE_finish(ret->engine);\n            OPENSSL_free(ret);\n            return NULL;\n        }\n    }\n#endif\n    ret->version = 1;\n    ret->conv_form = POINT_CONVERSION_UNCOMPRESSED;\n    ret->references = 1;\n    if (ret->meth->init != NULL && ret->meth->init(ret) == 0) {\n        EC_KEY_free(ret);\n        return NULL;\n    }\n    return ret;\n}', 'void EC_KEY_free(EC_KEY *r)\n{\n    int i;\n    if (r == NULL)\n        return;\n    i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_EC);\n#ifdef REF_PRINT\n    REF_PRINT("EC_KEY", r);\n#endif\n    if (i > 0)\n        return;\n#ifdef REF_CHECK\n    if (i < 0) {\n        fprintf(stderr, "EC_KEY_free, bad reference count\\n");\n        abort();\n    }\n#endif\n    if (r->meth->finish != NULL)\n        r->meth->finish(r);\n#ifndef OPENSSL_NO_ENGINE\n    if (r->engine != NULL)\n        ENGINE_finish(r->engine);\n#endif\n    EC_GROUP_free(r->group);\n    EC_POINT_free(r->pub_key);\n    BN_clear_free(r->priv_key);\n    EC_EX_DATA_free_all_data(&r->method_data);\n    OPENSSL_clear_free((void *)r, sizeof(EC_KEY));\n}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n    unsigned int i, m;\n    unsigned int n;\n    BN_ULONG l;\n    BIGNUM *bn = NULL;\n    if (ret == NULL)\n        ret = bn = BN_new();\n    if (ret == NULL)\n        return (NULL);\n    bn_check_top(ret);\n    for ( ; len > 0 && *s == 0; s++, len--)\n        continue;\n    n = len;\n    if (n == 0) {\n        ret->top = 0;\n        return (ret);\n    }\n    i = ((n - 1) / BN_BYTES) + 1;\n    m = ((n - 1) % (BN_BYTES));\n    if (bn_wexpand(ret, (int)i) == NULL) {\n        BN_free(bn);\n        return NULL;\n    }\n    ret->top = i;\n    ret->neg = 0;\n    l = 0;\n    while (n--) {\n        l = (l << 8L) | *(s++);\n        if (m-- == 0) {\n            ret->d[--i] = l;\n            l = 0;\n            m = BN_BYTES - 1;\n        }\n    }\n    bn_correct_top(ret);\n    return (ret);\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, *a = NULL;\n    const BN_ULONG *B;\n    int i;\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 = A = OPENSSL_secure_malloc(words * sizeof(*a));\n    else\n        a = A = OPENSSL_malloc(words * sizeof(*a));\n    if (A == NULL) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n        return (NULL);\n    }\n#ifdef PURIFY\n    memset(a, 0, sizeof(*a) * words);\n#endif\n#if 1\n    B = b->d;\n    if (B != NULL) {\n        for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n            BN_ULONG a0, a1, a2, a3;\n            a0 = B[0];\n            a1 = B[1];\n            a2 = B[2];\n            a3 = B[3];\n            A[0] = a0;\n            A[1] = a1;\n            A[2] = a2;\n            A[3] = a3;\n        }\n        switch (b->top & 3) {\n        case 3:\n            A[2] = B[2];\n        case 2:\n            A[1] = B[1];\n        case 1:\n            A[0] = B[0];\n        case 0:\n            ;\n        }\n    }\n#else\n    memset(A, 0, sizeof(*A) * words);\n    memcpy(A, b->d, sizeof(b->d[0]) * b->top);\n#endif\n    return (a);\n}']