crypto/ec/ecp_mont.c:151: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 67108856] by call to `BN_MONT_CTX_set`.
Showing all 21 steps of the trace


crypto/ec/ecp_mont.c:151:10: Call
149.       if (mont == NULL)
150.           goto err;
151.       if (!BN_MONT_CTX_set(mont, p, ctx)) {
                ^
152.           ECerr(EC_F_EC_GFP_MONT_GROUP_SET_CURVE, ERR_R_BN_LIB);
153.           goto err;

crypto/bn/bn_mont.c:247:1: Parameter `mont->N.top`
  245.   }
  246.   
  247. > int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
  248.   {
  249.       int ret = 0;

crypto/bn/bn_mont.c:259:10: Call
  257.           goto err;
  258.       R = &(mont->RR);            /* grab RR as a temp */
  259.       if (!BN_copy(&(mont->N), mod))
                  ^
  260.           goto err;               /* Set N */
  261.       if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)

crypto/bn/bn_lib.c:312:1: Parameter `a->top`
    310.   }
    311.   
    312. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
    313.   {
    314.       bn_check_top(b);

crypto/bn/bn_lib.c:318:9: Call
    316.       if (a == b)
    317.           return a;
    318.       if (bn_wexpand(a, b->top) == NULL)
                   ^
    319.           return NULL;
    320.   

crypto/bn/bn_lib.c:937:1: Parameter `a->top`
      935.   }
      936.   
      937. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
      938.   {
      939.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:939:37: Call
      937.   BIGNUM *bn_wexpand(BIGNUM *a, int words)
      938.   {
      939.       return (words <= a->dmax) ? a : bn_expand2(a, words);
                                                 ^
      940.   }
      941.   

crypto/bn/bn_lib.c:273:1: Parameter `b->top`
        271.    */
        272.   
        273. > BIGNUM *bn_expand2(BIGNUM *b, int words)
        274.   {
        275.       bn_check_top(b);

crypto/bn/bn_lib.c:278:23: Call
        276.   
        277.       if (words > b->dmax) {
        278.           BN_ULONG *a = bn_expand_internal(b, words);
                                     ^
        279.           if (!a)
        280.               return NULL;

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

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

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

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

crypto/bn/bn_lib.c:252:13: Call
          250.           a = OPENSSL_secure_zalloc(words * sizeof(*a));
          251.       else
          252.           a = OPENSSL_zalloc(words * sizeof(*a));
                             ^
          253.       if (a == NULL) {
          254.           BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);

crypto/mem.c:221:1: Parameter `num`
            219.   }
            220.   
            221. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
            222.   {
            223.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:223:17: Call
            221.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
            222.   {
            223.       void *ret = CRYPTO_malloc(num, file, line);
                                   ^
            224.   
            225.       FAILTEST();

crypto/mem.c:201:9: Assignment
              199.   
              200.       if (num == 0)
              201.           return NULL;
                             ^
              202.   
              203.       FAILTEST();

crypto/mem.c:223:5: Assignment
            221.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
            222.   {
            223.       void *ret = CRYPTO_malloc(num, file, line);
                       ^
            224.   
            225.       FAILTEST();

crypto/mem.c:228:5: Assignment
            226.       if (ret != NULL)
            227.           memset(ret, 0, num);
            228.       return ret;
                       ^
            229.   }
            230.   

crypto/bn/bn_lib.c:252:9: Assignment
          250.           a = OPENSSL_secure_zalloc(words * sizeof(*a));
          251.       else
          252.           a = OPENSSL_zalloc(words * sizeof(*a));
                         ^
          253.       if (a == NULL) {
          254.           BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);

crypto/bn/bn_lib.c:260:9: Array access: Offset added: [8, +oo] Size: [0, 67108856] by call to `BN_MONT_CTX_set` 
          258.       assert(b->top <= words);
          259.       if (b->top > 0)
          260.           memcpy(a, b->d, sizeof(*a) * b->top);
                         ^
          261.   
          262.       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 ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p,\n                                const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n    BN_CTX *new_ctx = NULL;\n    BN_MONT_CTX *mont = NULL;\n    BIGNUM *one = NULL;\n    int ret = 0;\n    BN_MONT_CTX_free(group->field_data1);\n    group->field_data1 = NULL;\n    BN_free(group->field_data2);\n    group->field_data2 = NULL;\n    if (ctx == NULL) {\n        ctx = new_ctx = BN_CTX_new();\n        if (ctx == NULL)\n            return 0;\n    }\n    mont = BN_MONT_CTX_new();\n    if (mont == NULL)\n        goto err;\n    if (!BN_MONT_CTX_set(mont, p, ctx)) {\n        ECerr(EC_F_EC_GFP_MONT_GROUP_SET_CURVE, ERR_R_BN_LIB);\n        goto err;\n    }\n    one = BN_new();\n    if (one == NULL)\n        goto err;\n    if (!BN_to_montgomery(one, BN_value_one(), mont, ctx))\n        goto err;\n    group->field_data1 = mont;\n    mont = NULL;\n    group->field_data2 = one;\n    one = NULL;\n    ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx);\n    if (!ret) {\n        BN_MONT_CTX_free(group->field_data1);\n        group->field_data1 = NULL;\n        BN_free(group->field_data2);\n        group->field_data2 = NULL;\n    }\n err:\n    BN_free(one);\n    BN_CTX_free(new_ctx);\n    BN_MONT_CTX_free(mont);\n    return ret;\n}', 'int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)\n{\n    int ret = 0;\n    BIGNUM *Ri, *R;\n    if (BN_is_zero(mod))\n        return 0;\n    BN_CTX_start(ctx);\n    if ((Ri = BN_CTX_get(ctx)) == NULL)\n        goto err;\n    R = &(mont->RR);\n    if (!BN_copy(&(mont->N), mod))\n        goto err;\n    if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n        BN_set_flags(&(mont->N), BN_FLG_CONSTTIME);\n    mont->N.neg = 0;\n#ifdef MONT_WORD\n    {\n        BIGNUM tmod;\n        BN_ULONG buf[2];\n        bn_init(&tmod);\n        tmod.d = buf;\n        tmod.dmax = 2;\n        tmod.neg = 0;\n        if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)\n            BN_set_flags(&tmod, BN_FLG_CONSTTIME);\n        mont->ri = (BN_num_bits(mod) + (BN_BITS2 - 1)) / BN_BITS2 * BN_BITS2;\n# if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)\n        BN_zero(R);\n        if (!(BN_set_bit(R, 2 * BN_BITS2)))\n            goto err;\n        tmod.top = 0;\n        if ((buf[0] = mod->d[0]))\n            tmod.top = 1;\n        if ((buf[1] = mod->top > 1 ? mod->d[1] : 0))\n            tmod.top = 2;\n        if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n            goto err;\n        if (!BN_lshift(Ri, Ri, 2 * BN_BITS2))\n            goto err;\n        if (!BN_is_zero(Ri)) {\n            if (!BN_sub_word(Ri, 1))\n                goto err;\n        } else {\n            if (bn_expand(Ri, (int)sizeof(BN_ULONG) * 2) == NULL)\n                goto err;\n            Ri->neg = 0;\n            Ri->d[0] = BN_MASK2;\n            Ri->d[1] = BN_MASK2;\n            Ri->top = 2;\n        }\n        if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n            goto err;\n        mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n        mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;\n# else\n        BN_zero(R);\n        if (!(BN_set_bit(R, BN_BITS2)))\n            goto err;\n        buf[0] = mod->d[0];\n        buf[1] = 0;\n        tmod.top = buf[0] != 0 ? 1 : 0;\n        if ((BN_mod_inverse(Ri, R, &tmod, ctx)) == NULL)\n            goto err;\n        if (!BN_lshift(Ri, Ri, BN_BITS2))\n            goto err;\n        if (!BN_is_zero(Ri)) {\n            if (!BN_sub_word(Ri, 1))\n                goto err;\n        } else {\n            if (!BN_set_word(Ri, BN_MASK2))\n                goto err;\n        }\n        if (!BN_div(Ri, NULL, Ri, &tmod, ctx))\n            goto err;\n        mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;\n        mont->n0[1] = 0;\n# endif\n    }\n#else\n    {\n        mont->ri = BN_num_bits(&mont->N);\n        BN_zero(R);\n        if (!BN_set_bit(R, mont->ri))\n            goto err;\n        if ((BN_mod_inverse(Ri, R, &mont->N, ctx)) == NULL)\n            goto err;\n        if (!BN_lshift(Ri, Ri, mont->ri))\n            goto err;\n        if (!BN_sub_word(Ri, 1))\n            goto err;\n        if (!BN_div(&(mont->Ni), NULL, Ri, &mont->N, ctx))\n            goto err;\n    }\n#endif\n    BN_zero(&(mont->RR));\n    if (!BN_set_bit(&(mont->RR), mont->ri * 2))\n        goto err;\n    if (!BN_mod(&(mont->RR), &(mont->RR), &(mont->N), ctx))\n        goto err;\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return ret;\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    INCREMENT(malloc_count);\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    (void)(file); (void)(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}']