test/bntest.c:598: error: BUFFER_OVERRUN_L3
  Offset added: [0, 392] Size: [0, 67108856] by call to `BN_lshift`.
Showing all 11 steps of the trace


test/bntest.c:86:1: Assignment
84.   #include "../crypto/bn/bn_lcl.h"
85.   
86. > static const int num0 = 100;           /* number of tests */
87.   static const int num1 = 50;            /* additional tests for some functions */
88.   static const int num2 = 5;             /* number of tests for slow functions */

test/bntest.c:598:13: Call
596.               BN_bntest_rand(a, 400, 0, 0);
597.               BN_copy(b, a);
598.               BN_lshift(a, a, i);
                   ^
599.               BN_add_word(a, i);
600.           } else

crypto/bn/bn_shift.c:130:1: <Offset trace>
128.   }
129.   
130. > int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
131.   {
132.       int i, nw, lb, rb;

crypto/bn/bn_shift.c:130:1: Parameter `n`
  128.   }
  129.   
  130. > int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
  131.   {
  132.       int i, nw, lb, rb;

crypto/bn/bn_shift.c:145:5: Assignment
  143.   
  144.       r->neg = a->neg;
  145.       nw = n / BN_BITS2;
             ^
  146.       if (bn_wexpand(r, a->top + nw + 1) == NULL)
  147.           return (0);

crypto/bn/bn_shift.c:130:1: <Length trace>
128.   }
129.   
130. > int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
131.   {
132.       int i, nw, lb, rb;

crypto/bn/bn_shift.c:130:1: Parameter `*r->d`
  128.   }
  129.   
  130. > int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
  131.   {
  132.       int i, nw, lb, rb;

crypto/bn/bn_shift.c:146:9: Call
  144.       r->neg = a->neg;
  145.       nw = n / BN_BITS2;
  146.       if (bn_wexpand(r, a->top + nw + 1) == NULL)
                 ^
  147.           return (0);
  148.       lb = n % BN_BITS2;

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_shift.c:151:5: Assignment
  149.       rb = BN_BITS2 - lb;
  150.       f = a->d;
  151.       t = r->d;
             ^
  152.       t[a->top + nw] = 0;
  153.       if (lb == 0)

crypto/bn/bn_shift.c:162:5: Array access: Offset added: [0, 392] Size: [0, 67108856] by call to `BN_lshift` 
  160.               t[nw + i] = (l << lb) & BN_MASK2;
  161.           }
  162.       memset(t, 0, sizeof(*t) * nw);
             ^
  163.       r->top = a->top + nw + 1;
  164.       bn_correct_top(r);

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;
    }
    r->neg = a->neg;
    nw = n / BN_BITS2;
    if (bn_wexpand(r, a->top + nw + 1) == NULL)
        return (0);
    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);
}
['int test_div_recp(BIO *bp, BN_CTX *ctx)\n{\n    BIGNUM *a, *b, *c, *d, *e;\n    BN_RECP_CTX *recp;\n    int i;\n    recp = BN_RECP_CTX_new();\n    a = BN_new();\n    b = BN_new();\n    c = BN_new();\n    d = BN_new();\n    e = BN_new();\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        a->neg = rand_neg();\n        b->neg = rand_neg();\n        BN_RECP_CTX_set(recp, b, ctx);\n        BN_div_recp(d, c, a, recp, ctx);\n        if (bp != NULL) {\n            if (!results) {\n                BN_print(bp, a);\n                BIO_puts(bp, " / ");\n                BN_print(bp, b);\n                BIO_puts(bp, " - ");\n            }\n            BN_print(bp, d);\n            BIO_puts(bp, "\\n");\n            if (!results) {\n                BN_print(bp, a);\n                BIO_puts(bp, " % ");\n                BN_print(bp, b);\n                BIO_puts(bp, " - ");\n            }\n            BN_print(bp, c);\n            BIO_puts(bp, "\\n");\n        }\n        BN_mul(e, d, b, ctx);\n        BN_add(d, e, c);\n        BN_sub(d, d, a);\n        if (!BN_is_zero(d)) {\n            fprintf(stderr, "Reciprocal division test failed!\\n");\n            fprintf(stderr, "a=");\n            BN_print_fp(stderr, a);\n            fprintf(stderr, "\\nb=");\n            BN_print_fp(stderr, b);\n            fprintf(stderr, "\\n");\n            return 0;\n        }\n    }\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 (1);\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    r->neg = a->neg;\n    nw = n / BN_BITS2;\n    if (bn_wexpand(r, a->top + nw + 1) == NULL)\n        return (0);\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}']