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


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

test/bntest.c:1938:9: Call
1936.       }
1937.       for (i = 0; i < num0; i++) {
1938.           BN_lshift(b, a, i + 1);
                ^
1939.           BN_add(c, c, c);
1940.           if (bp != NULL) {

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

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

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

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

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

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

crypto/bn/bn_lib.c:1016:1: Parameter `*a->d`
    1014.   }
    1015.   
    1016. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
    1017.   {
    1018.       return (words <= a->dmax) ? a : bn_expand2(a, words);

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

crypto/bn/bn_shift.c:113:5: Array access: Offset added: [0, 800] Size: [0, 67108856] by call to `BN_lshift` 
  111.               t[nw + i] = (l << lb) & BN_MASK2;
  112.           }
  113.       memset(t, 0, sizeof(*t) * nw);
             ^
  114.       r->top = a->top + nw + 1;
  115.       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_lshift(BIO *bp, BN_CTX *ctx, BIGNUM *a_)\n{\n    BIGNUM *a, *b, *c, *d;\n    int i;\n    b = BN_new();\n    c = BN_new();\n    d = BN_new();\n    BN_one(c);\n    if (a_)\n        a = a_;\n    else {\n        a = BN_new();\n        BN_bntest_rand(a, 200, 0, 0);\n        a->neg = rand_neg();\n    }\n    for (i = 0; i < num0; i++) {\n        BN_lshift(b, a, i + 1);\n        BN_add(c, c, c);\n        if (bp != NULL) {\n            if (!results) {\n                BN_print(bp, a);\n                BIO_puts(bp, " * ");\n                BN_print(bp, c);\n                BIO_puts(bp, " - ");\n            }\n            BN_print(bp, b);\n            BIO_puts(bp, "\\n");\n        }\n        BN_mul(d, a, c, ctx);\n        BN_sub(d, d, b);\n        if (!BN_is_zero(d)) {\n            fprintf(stderr, "Left shift 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, "\\nc=");\n            BN_print_fp(stderr, c);\n            fprintf(stderr, "\\nd=");\n            BN_print_fp(stderr, d);\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    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}']