test/bntest.c:281: error: BUFFER_OVERRUN_L3
  Offset: [1, +oo] Size: [0, 8388607] by call to `BN_lshift`.
Showing all 11 steps of the trace


test/bntest.c:44:1: Assignment
42.   } MPITEST;
43.   
44. > static const int NUM0 = 100;           /* number of tests */
45.   static const int NUM1 = 50;            /* additional tests for some functions */
46.   static BN_CTX *ctx;

test/bntest.c:281:13: Call
279.               BN_bntest_rand(a, 400, 0, 0);
280.               BN_copy(b, a);
281.               BN_lshift(a, a, i);
                   ^
282.               BN_add_word(a, i);
283.           } else

crypto/bn/bn_shift.c:83:1: <Offset trace>
81.   }
82.   
83. > int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
84.   {
85.       int i, nw, lb, rb;

crypto/bn/bn_shift.c:83:1: Parameter `n`
  81.   }
  82.   
  83. > int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
  84.   {
  85.       int i, nw, lb, rb;

crypto/bn/bn_shift.c:97:5: Assignment
  95.       }
  96.   
  97.       nw = n / BN_BITS2;
             ^
  98.       if (bn_wexpand(r, a->top + nw + 1) == NULL)
  99.           return 0;

crypto/bn/bn_shift.c:83:1: <Length trace>
81.   }
82.   
83. > int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
84.   {
85.       int i, nw, lb, rb;

crypto/bn/bn_shift.c:83:1: Parameter `*r->d`
  81.   }
  82.   
  83. > int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
  84.   {
  85.       int i, nw, lb, rb;

crypto/bn/bn_shift.c:98:9: Call
  96.   
  97.       nw = n / BN_BITS2;
  98.       if (bn_wexpand(r, a->top + nw + 1) == NULL)
                 ^
  99.           return 0;
  100.       r->neg = a->neg;

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

crypto/bn/bn_shift.c:104:5: Assignment
  102.       rb = BN_BITS2 - lb;
  103.       f = a->d;
  104.       t = r->d;
             ^
  105.       t[a->top + nw] = 0;
  106.       if (lb == 0)

crypto/bn/bn_shift.c:112:13: Array access: Offset: [1, +oo] Size: [0, 8388607] by call to `BN_lshift` 
  110.           for (i = a->top - 1; i >= 0; i--) {
  111.               l = f[i];
  112.               t[nw + i + 1] |= (l >> rb) & BN_MASK2;
                     ^
  113.               t[nw + i] = (l << lb) & BN_MASK2;
  114.           }

int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
{
    int i, nw, lb, rb;
    BN_ULONG *t, *f;
    BN_ULONG l;
    bn_check_top(r);
    bn_check_top(a);
    if (n < 0) {
        BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);
        return 0;
    }
    nw = n / BN_BITS2;
    if (bn_wexpand(r, a->top + nw + 1) == NULL)
        return 0;
    r->neg = a->neg;
    lb = n % BN_BITS2;
    rb = BN_BITS2 - lb;
    f = a->d;
    t = r->d;
    t[a->top + nw] = 0;
    if (lb == 0)
        for (i = a->top - 1; i >= 0; i--)
            t[nw + i] = f[i];
    else
        for (i = a->top - 1; i >= 0; i--) {
            l = f[i];
            t[nw + i + 1] |= (l >> rb) & BN_MASK2;
            t[nw + i] = (l << lb) & BN_MASK2;
        }
    memset(t, 0, sizeof(*t) * nw);
    r->top = a->top + nw + 1;
    bn_correct_top(r);
    bn_check_top(r);
    return 1;
}
['static int test_div_recip(void)\n{\n    BIGNUM *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL;\n    BN_RECP_CTX *recp = NULL;\n    int st = 0, i;\n    if (!TEST_ptr(a = BN_new())\n            || !TEST_ptr(b = BN_new())\n            || !TEST_ptr(c = BN_new())\n            || !TEST_ptr(d = BN_new())\n            || !TEST_ptr(e = BN_new())\n            || !TEST_ptr(recp = BN_RECP_CTX_new()))\n        goto err;\n    for (i = 0; i < NUM0 + NUM1; i++) {\n        if (i < NUM1) {\n            BN_bntest_rand(a, 400, 0, 0);\n            BN_copy(b, a);\n            BN_lshift(a, a, i);\n            BN_add_word(a, i);\n        } else\n            BN_bntest_rand(b, 50 + 3 * (i - NUM1), 0, 0);\n        BN_set_negative(a, rand_neg());\n        BN_set_negative(b, rand_neg());\n        BN_RECP_CTX_set(recp, b, ctx);\n        BN_div_recp(d, c, a, recp, ctx);\n        BN_mul(e, d, b, ctx);\n        BN_add(d, e, c);\n        BN_sub(d, d, a);\n        if (!TEST_BN_eq_zero(d))\n            goto err;\n    }\n    st = 1;\nerr:\n    BN_free(a);\n    BN_free(b);\n    BN_free(c);\n    BN_free(d);\n    BN_free(e);\n    BN_RECP_CTX_free(recp);\n    return st;\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n    int i, nw, lb, rb;\n    BN_ULONG *t, *f;\n    BN_ULONG l;\n    bn_check_top(r);\n    bn_check_top(a);\n    if (n < 0) {\n        BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n        return 0;\n    }\n    nw = n / BN_BITS2;\n    if (bn_wexpand(r, a->top + nw + 1) == NULL)\n        return 0;\n    r->neg = a->neg;\n    lb = n % BN_BITS2;\n    rb = BN_BITS2 - lb;\n    f = a->d;\n    t = r->d;\n    t[a->top + nw] = 0;\n    if (lb == 0)\n        for (i = a->top - 1; i >= 0; i--)\n            t[nw + i] = f[i];\n    else\n        for (i = a->top - 1; i >= 0; i--) {\n            l = f[i];\n            t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n            t[nw + i] = (l << lb) & BN_MASK2;\n        }\n    memset(t, 0, sizeof(*t) * nw);\n    r->top = a->top + nw + 1;\n    bn_correct_top(r);\n    bn_check_top(r);\n    return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']