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


test/bntest.c:543:18: Call
541.               BN_bntest_rand(a, 512, -1, 0);
542.               BN_bntest_rand(b, BN_BITS2, -1, 0);
543.           } while (BN_is_zero(b));
                        ^
544.   
545.           s = b->d[0];

crypto/bn/bn_lib.c:899:1: Parameter `a->top`
  897.   }
  898.   
  899. > int BN_is_zero(const BIGNUM *a)
  900.   {
  901.       return a->top == 0;

test/bntest.c:547:13: Call
545.           s = b->d[0];
546.           BN_copy(b, a);
547.           r = BN_div_word(b, s);
                   ^
548.   
549.           if (bp != NULL) {

crypto/bn/bn_word.c:88:1: Parameter `*a->d`
  86.   }
  87.   
  88. > BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w)
  89.   {
  90.       BN_ULONG ret = 0;

crypto/bn/bn_word.c:105:10: Call
  103.       j = BN_BITS2 - BN_num_bits_word(w);
  104.       w <<= j;
  105.       if (!BN_lshift(a, a, j))
                  ^
  106.           return (BN_ULONG)-1;
  107.   

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:159:13: Array access: Offset: [1, +oo] Size: [0, 8388607] by call to `BN_div_word` 
    157.           for (i = a->top - 1; i >= 0; i--) {
    158.               l = f[i];
    159.               t[nw + i + 1] |= (l >> rb) & BN_MASK2;
                       ^
    160.               t[nw + i] = (l << lb) & BN_MASK2;
    161.           }

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_word(BIO *bp)\n{\n    BIGNUM *a, *b;\n    BN_ULONG r, s;\n    int i;\n    a = BN_new();\n    b = BN_new();\n    for (i = 0; i < num0; i++) {\n        do {\n            BN_bntest_rand(a, 512, -1, 0);\n            BN_bntest_rand(b, BN_BITS2, -1, 0);\n        } while (BN_is_zero(b));\n        s = b->d[0];\n        BN_copy(b, a);\n        r = BN_div_word(b, s);\n        if (bp != NULL) {\n            if (!results) {\n                BN_print(bp, a);\n                BIO_puts(bp, " / ");\n                print_word(bp, s);\n                BIO_puts(bp, " - ");\n            }\n            BN_print(bp, b);\n            BIO_puts(bp, "\\n");\n            if (!results) {\n                BN_print(bp, a);\n                BIO_puts(bp, " % ");\n                print_word(bp, s);\n                BIO_puts(bp, " - ");\n            }\n            print_word(bp, r);\n            BIO_puts(bp, "\\n");\n        }\n        BN_mul_word(b, s);\n        BN_add_word(b, r);\n        BN_sub(b, a, b);\n        if (!BN_is_zero(b)) {\n            fprintf(stderr, "Division (word) test failed!\\n");\n            return 0;\n        }\n    }\n    BN_free(a);\n    BN_free(b);\n    return (1);\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n    return a->top == 0;\n}', 'BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w)\n{\n    BN_ULONG ret = 0;\n    int i, j;\n    bn_check_top(a);\n    w &= BN_MASK2;\n    if (!w)\n        return (BN_ULONG)-1;\n    if (a->top == 0)\n        return 0;\n    j = BN_BITS2 - BN_num_bits_word(w);\n    w <<= j;\n    if (!BN_lshift(a, a, j))\n        return (BN_ULONG)-1;\n    for (i = a->top - 1; i >= 0; i--) {\n        BN_ULONG l, d;\n        l = a->d[i];\n        d = bn_div_words(ret, l, w);\n        ret = (l - ((d * w) & BN_MASK2)) & BN_MASK2;\n        a->d[i] = d;\n    }\n    if ((a->top > 0) && (a->d[a->top - 1] == 0))\n        a->top--;\n    ret >>= j;\n    bn_check_top(a);\n    return (ret);\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}']