test/bntest.c:1341: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 536870848] by call to `BN_from_montgomery`.
Showing all 12 steps of the trace


test/bntest.c:1323:10: Call
1321.           goto err;
1322.   
1323.       if (!TEST_true(BN_mod_mul(ret, a, b, m, ctx))
                 ^
1324.               || !equalBN("A * B (mod M)", mod_mul, ret))
1325.           goto err;

crypto/bn/bn_mod.c:73:1: Parameter `r->top`
  71.   
  72.   /* slow but works */
  73. > int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
  74.                  BN_CTX *ctx)
  75.   {

test/bntest.c:1341:21: Call
1339.                   || !TEST_true(BN_mod_mul_montgomery(ret, a_tmp, b_tmp,
1340.                                                       mont, ctx))
1341.                   || !TEST_true(BN_from_montgomery(ret, ret, mont, ctx))
                            ^
1342.                   || !equalBN("A * B (mod M) (mont)", mod_mul, ret))
1343.               st = 0;

crypto/bn/bn_mont.c:166:1: Parameter `a->top`
  164.   #endif                          /* MONT_WORD */
  165.   
  166. > int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
  167.                          BN_CTX *ctx)
  168.   {

crypto/bn/bn_mont.c:174:34: Call
  172.   
  173.       BN_CTX_start(ctx);
  174.       if ((t = BN_CTX_get(ctx)) && BN_copy(t, a))
                                          ^
  175.           retn = BN_from_montgomery_word(ret, t, mont);
  176.       BN_CTX_end(ctx);

crypto/bn/bn_lib.c:323:1: <Offset trace>
321.   }
322.   
323. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
324.   {
325.       bn_check_top(b);

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

crypto/bn/bn_lib.c:323:1: <Length trace>
321.   }
322.   
323. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
324.   {
325.       bn_check_top(b);

crypto/bn/bn_lib.c:323:1: Parameter `*a->d`
    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->d`
      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:333:9: Array access: Offset added: [8, +oo] Size: [0, 536870848] by call to `BN_from_montgomery` 
    331.   
    332.       if (b->top > 0)
    333.           memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
                   ^
    334.   
    335.       a->top = b->top;

BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
{
    bn_check_top(b);
    if (a == b)
        return a;
    if (bn_wexpand(a, b->top) == NULL)
        return NULL;
    if (b->top > 0)
        memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
    a->top = b->top;
    a->neg = b->neg;
    bn_check_top(a);
    return a;
}
['static int file_modmul(STANZA *s)\n{\n    BIGNUM *a = NULL, *b = NULL, *m = NULL, *mod_mul = NULL, *ret = NULL;\n    int st = 0;\n    if (!TEST_ptr(a = getBN(s, "A"))\n            || !TEST_ptr(b = getBN(s, "B"))\n            || !TEST_ptr(m = getBN(s, "M"))\n            || !TEST_ptr(mod_mul = getBN(s, "ModMul"))\n            || !TEST_ptr(ret = BN_new()))\n        goto err;\n    if (!TEST_true(BN_mod_mul(ret, a, b, m, ctx))\n            || !equalBN("A * B (mod M)", mod_mul, ret))\n        goto err;\n    if (BN_is_odd(m)) {\n        BN_MONT_CTX *mont = BN_MONT_CTX_new();\n        BIGNUM *a_tmp = BN_new();\n        BIGNUM *b_tmp = BN_new();\n        if (mont == NULL || a_tmp == NULL || b_tmp == NULL\n                || !TEST_true(BN_MONT_CTX_set(mont, m, ctx))\n                || !TEST_true(BN_nnmod(a_tmp, a, m, ctx))\n                || !TEST_true(BN_nnmod(b_tmp, b, m, ctx))\n                || !TEST_true(BN_to_montgomery(a_tmp, a_tmp, mont, ctx))\n                || !TEST_true(BN_to_montgomery(b_tmp, b_tmp, mont, ctx))\n                || !TEST_true(BN_mod_mul_montgomery(ret, a_tmp, b_tmp,\n                                                    mont, ctx))\n                || !TEST_true(BN_from_montgomery(ret, ret, mont, ctx))\n                || !equalBN("A * B (mod M) (mont)", mod_mul, ret))\n            st = 0;\n        else\n            st = 1;\n        BN_MONT_CTX_free(mont);\n        BN_free(a_tmp);\n        BN_free(b_tmp);\n        if (st == 0)\n            goto err;\n    }\n    st = 1;\nerr:\n    BN_free(a);\n    BN_free(b);\n    BN_free(m);\n    BN_free(mod_mul);\n    BN_free(ret);\n    return st;\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n               BN_CTX *ctx)\n{\n    BIGNUM *t;\n    int ret = 0;\n    bn_check_top(a);\n    bn_check_top(b);\n    bn_check_top(m);\n    BN_CTX_start(ctx);\n    if ((t = BN_CTX_get(ctx)) == NULL)\n        goto err;\n    if (a == b) {\n        if (!BN_sqr(t, a, ctx))\n            goto err;\n    } else {\n        if (!BN_mul(t, a, b, ctx))\n            goto err;\n    }\n    if (!BN_nnmod(r, t, m, ctx))\n        goto err;\n    bn_check_top(r);\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return (ret);\n}', 'int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,\n                       BN_CTX *ctx)\n{\n    int retn = 0;\n#ifdef MONT_WORD\n    BIGNUM *t;\n    BN_CTX_start(ctx);\n    if ((t = BN_CTX_get(ctx)) && BN_copy(t, a))\n        retn = BN_from_montgomery_word(ret, t, mont);\n    BN_CTX_end(ctx);\n#else\n    BIGNUM *t1, *t2;\n    BN_CTX_start(ctx);\n    t1 = BN_CTX_get(ctx);\n    t2 = BN_CTX_get(ctx);\n    if (t1 == NULL || t2 == NULL)\n        goto err;\n    if (!BN_copy(t1, a))\n        goto err;\n    BN_mask_bits(t1, mont->ri);\n    if (!BN_mul(t2, t1, &mont->Ni, ctx))\n        goto err;\n    BN_mask_bits(t2, mont->ri);\n    if (!BN_mul(t1, t2, &mont->N, ctx))\n        goto err;\n    if (!BN_add(t2, a, t1))\n        goto err;\n    if (!BN_rshift(ret, t2, mont->ri))\n        goto err;\n    if (BN_ucmp(ret, &(mont->N)) >= 0) {\n        if (!BN_usub(ret, ret, &(mont->N)))\n            goto err;\n    }\n    retn = 1;\n    bn_check_top(ret);\n err:\n    BN_CTX_end(ctx);\n#endif\n    return (retn);\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}']