test/bntest.c:179: error: BUFFER_OVERRUN_L3
  Offset: [10, +oo] Size: [0, 8388607] by call to `BN_consttime_swap`.
Showing all 9 steps of the trace


test/bntest.c:169:11: Call
167.       BN_copy(c, a);
168.       BN_copy(d, b);
169.       top = BN_num_bits(a)/BN_BITS2;
                 ^
170.   
171.       /* regular swap */

crypto/bn/bn_lib.c:140:9: Assignment
  138.   
  139.       if (BN_is_zero(a))
  140.           return 0;
                 ^
  141.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
  142.   }

test/bntest.c:169:5: Assignment
167.       BN_copy(c, a);
168.       BN_copy(d, b);
169.       top = BN_num_bits(a)/BN_BITS2;
           ^
170.   
171.       /* regular swap */

test/bntest.c:179:5: Call
177.       /* conditional swap: true */
178.       cond = 1;
179.       BN_consttime_swap(cond, a, b, top);
           ^
180.       if (!equalBN("cswap true", a, c)
181.               || !equalBN("cswap true", b, d))

crypto/bn/bn_lib.c:727:1: <Offset trace>
725.    * a and b cannot be the same number
726.    */
727. > void BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)
728.   {
729.       BN_ULONG t;

crypto/bn/bn_lib.c:727:1: Parameter `nwords`
  725.    * a and b cannot be the same number
  726.    */
  727. > void BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)
  728.   {
  729.       BN_ULONG t;

crypto/bn/bn_lib.c:727:1: <Length trace>
725.    * a and b cannot be the same number
726.    */
727. > void BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)
728.   {
729.       BN_ULONG t;

crypto/bn/bn_lib.c:727:1: Parameter `*b->d`
  725.    * a and b cannot be the same number
  726.    */
  727. > void BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)
  728.   {
  729.       BN_ULONG t;

crypto/bn/bn_lib.c:783:13: Array access: Offset: [10, +oo] Size: [0, 8388607] by call to `BN_consttime_swap` 
  781.       default:
  782.           for (i = 10; i < nwords; i++)
  783.               BN_CONSTTIME_SWAP(i);
                     ^
  784.           /* Fallthrough */
  785.       case 10:

void BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)
{
    BN_ULONG t;
    int i;
    bn_wcheck_size(a, nwords);
    bn_wcheck_size(b, nwords);
    assert(a != b);
    assert((condition & (condition - 1)) == 0);
    assert(sizeof(BN_ULONG) >= sizeof(int));
    condition = ((condition - 1) >> (BN_BITS2 - 1)) - 1;
    t = (a->top ^ b->top) & condition;
    a->top ^= t;
    b->top ^= t;
    t = (a->neg ^ b->neg) & condition;
    a->neg ^= t;
    b->neg ^= t;
    t = ((a->flags ^ b->flags) & BN_FLG_CONSTTIME) & condition;
    a->flags ^= t;
    b->flags ^= t;
#define BN_CONSTTIME_SWAP(ind) \
        do { \
                t = (a->d[ind] ^ b->d[ind]) & condition; \
                a->d[ind] ^= t; \
                b->d[ind] ^= t; \
        } while (0)
    switch (nwords) {
    default:
        for (i = 10; i < nwords; i++)
            BN_CONSTTIME_SWAP(i);
    case 10:
        BN_CONSTTIME_SWAP(9);
    case 9:
        BN_CONSTTIME_SWAP(8);
    case 8:
        BN_CONSTTIME_SWAP(7);
    case 7:
        BN_CONSTTIME_SWAP(6);
    case 6:
        BN_CONSTTIME_SWAP(5);
    case 5:
        BN_CONSTTIME_SWAP(4);
    case 4:
        BN_CONSTTIME_SWAP(3);
    case 3:
        BN_CONSTTIME_SWAP(2);
    case 2:
        BN_CONSTTIME_SWAP(1);
    case 1:
        BN_CONSTTIME_SWAP(0);
    }
#undef BN_CONSTTIME_SWAP
}
['static int test_swap(void)\n{\n    BIGNUM *a = NULL, *b = NULL, *c = NULL, *d = NULL;\n    int top, cond, st = 0;\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        goto err;\n    BN_bntest_rand(a, 1024, 1, 0);\n    BN_bntest_rand(b, 1024, 1, 0);\n    BN_copy(c, a);\n    BN_copy(d, b);\n    top = BN_num_bits(a)/BN_BITS2;\n    BN_swap(a, b);\n    if (!equalBN("swap", a, d)\n            || !equalBN("swap", b, c))\n        goto err;\n    cond = 1;\n    BN_consttime_swap(cond, a, b, top);\n    if (!equalBN("cswap true", a, c)\n            || !equalBN("cswap true", b, d))\n        goto err;\n    cond = 0;\n    BN_consttime_swap(cond, a, b, top);\n    if (!equalBN("cswap false", a, c)\n            || !equalBN("cswap false", b, d))\n        goto err;\n    BN_set_flags(a, BN_FLG_CONSTTIME);\n    BN_swap(a, b);\n    if (!equalBN("swap, flags", a, d)\n            || !equalBN("swap, flags", b, c)\n            || !TEST_true(BN_get_flags(b, BN_FLG_CONSTTIME))\n            || !TEST_false(BN_get_flags(a, BN_FLG_CONSTTIME)))\n        goto err;\n    cond = 1;\n    BN_consttime_swap(cond, a, b, top);\n    if (!equalBN("cswap true, flags", a, c)\n            || !equalBN("cswap true, flags", b, d)\n            || !TEST_true(BN_get_flags(a, BN_FLG_CONSTTIME))\n            || !TEST_false(BN_get_flags(b, BN_FLG_CONSTTIME)))\n        goto err;\n    cond = 0;\n    BN_consttime_swap(cond, a, b, top);\n    if (!equalBN("cswap false, flags", a, c)\n            || !equalBN("cswap false, flags", b, d)\n            || !TEST_true(BN_get_flags(a, BN_FLG_CONSTTIME))\n            || !TEST_false(BN_get_flags(b, BN_FLG_CONSTTIME)))\n        goto err;\n    st = 1;\n err:\n    BN_free(a);\n    BN_free(b);\n    BN_free(c);\n    BN_free(d);\n    return st;\n}', 'int BN_num_bits(const BIGNUM *a)\n{\n    int i = a->top - 1;\n    bn_check_top(a);\n    if (BN_is_zero(a))\n        return 0;\n    return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));\n}', 'void BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)\n{\n    BN_ULONG t;\n    int i;\n    bn_wcheck_size(a, nwords);\n    bn_wcheck_size(b, nwords);\n    assert(a != b);\n    assert((condition & (condition - 1)) == 0);\n    assert(sizeof(BN_ULONG) >= sizeof(int));\n    condition = ((condition - 1) >> (BN_BITS2 - 1)) - 1;\n    t = (a->top ^ b->top) & condition;\n    a->top ^= t;\n    b->top ^= t;\n    t = (a->neg ^ b->neg) & condition;\n    a->neg ^= t;\n    b->neg ^= t;\n    t = ((a->flags ^ b->flags) & BN_FLG_CONSTTIME) & condition;\n    a->flags ^= t;\n    b->flags ^= t;\n#define BN_CONSTTIME_SWAP(ind) \\\n        do { \\\n                t = (a->d[ind] ^ b->d[ind]) & condition; \\\n                a->d[ind] ^= t; \\\n                b->d[ind] ^= t; \\\n        } while (0)\n    switch (nwords) {\n    default:\n        for (i = 10; i < nwords; i++)\n            BN_CONSTTIME_SWAP(i);\n    case 10:\n        BN_CONSTTIME_SWAP(9);\n    case 9:\n        BN_CONSTTIME_SWAP(8);\n    case 8:\n        BN_CONSTTIME_SWAP(7);\n    case 7:\n        BN_CONSTTIME_SWAP(6);\n    case 6:\n        BN_CONSTTIME_SWAP(5);\n    case 5:\n        BN_CONSTTIME_SWAP(4);\n    case 4:\n        BN_CONSTTIME_SWAP(3);\n    case 3:\n        BN_CONSTTIME_SWAP(2);\n    case 2:\n        BN_CONSTTIME_SWAP(1);\n    case 1:\n        BN_CONSTTIME_SWAP(0);\n    }\n#undef BN_CONSTTIME_SWAP\n}']