test/rsa_sp800_56b_test.c:193: error: BUFFER_OVERRUN_L3
  Offset: [1, +oo] Size: [0, 8388607] by call to `BN_sub`.
Showing all 10 steps of the trace


test/rsa_sp800_56b_test.c:193:14: Call
191.             && TEST_false(rsa_check_public_exponent(e))
192.             /* e = 2^256-1 is odd and in range */
193.             && TEST_true(BN_sub(e, e, BN_value_one()))
                    ^
194.             && TEST_true(rsa_check_public_exponent(e));
195.       BN_free(e);

crypto/bn/bn_lib.c:85:9: Assignment
  83.       static const BN_ULONG data_one = 1L;
  84.       static const BIGNUM const_one =
  85.           { (BN_ULONG *)&data_one, 1, 1, 0, BN_FLG_STATIC_DATA };
                ^
  86.   
  87.       return &const_one;

test/rsa_sp800_56b_test.c:193:14: Call
191.             && TEST_false(rsa_check_public_exponent(e))
192.             /* e = 2^256-1 is odd and in range */
193.             && TEST_true(BN_sub(e, e, BN_value_one()))
                    ^
194.             && TEST_true(rsa_check_public_exponent(e));
195.       BN_free(e);

crypto/bn/bn_add.c:45:1: Parameter `*a->d`
  43.   
  44.   /* signed sub of b from a. */
  45. > int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
  46.   {
  47.       int ret, r_neg, cmp_res;

crypto/bn/bn_add.c:59:19: Call
  57.           if (cmp_res > 0) {
  58.               r_neg = a->neg;
  59.               ret = BN_usub(r, a, b);
                          ^
  60.           } else if (cmp_res < 0) {
  61.               r_neg = !b->neg;

crypto/bn/bn_add.c:125:1: <Length trace>
123.   
124.   /* unsigned subtraction of b from a, a must be larger than b. */
125. > int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
126.   {
127.       int max, min, dif;

crypto/bn/bn_add.c:125:1: Parameter `b->top`
    123.   
    124.   /* unsigned subtraction of b from a, a must be larger than b. */
    125. > int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
    126.   {
    127.       int max, min, dif;

crypto/bn/bn_add.c:135:5: Assignment
    133.   
    134.       max = a->top;
    135.       min = b->top;
               ^
    136.       dif = max - min;
    137.   

crypto/bn/bn_add.c:151:5: Assignment
    149.   
    150.       borrow = bn_sub_words(rp, ap, bp, min);
    151.       ap += min;
               ^
    152.       rp += min;
    153.   

crypto/bn/bn_add.c:156:14: Array access: Offset: [1, +oo] Size: [0, 8388607] by call to `BN_sub` 
    154.       while (dif) {
    155.           dif--;
    156.           t1 = *(ap++);
                        ^
    157.           t2 = (t1 - borrow) & BN_MASK2;
    158.           *(rp++) = t2;

int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
{
    int max, min, dif;
    BN_ULONG t1, t2, borrow, *rp;
    const BN_ULONG *ap, *bp;
    bn_check_top(a);
    bn_check_top(b);
    max = a->top;
    min = b->top;
    dif = max - min;
    if (dif < 0) {
        BNerr(BN_F_BN_USUB, BN_R_ARG2_LT_ARG3);
        return 0;
    }
    if (bn_wexpand(r, max) == NULL)
        return 0;
    ap = a->d;
    bp = b->d;
    rp = r->d;
    borrow = bn_sub_words(rp, ap, bp, min);
    ap += min;
    rp += min;
    while (dif) {
        dif--;
        t1 = *(ap++);
        t2 = (t1 - borrow) & BN_MASK2;
        *(rp++) = t2;
        borrow &= (t1 == 0);
    }
    while (max && *--rp == 0)
        max--;
    r->top = max;
    r->neg = 0;
    bn_pollute(r);
    return 1;
}
['static int test_check_public_exponent(void)\n{\n    int ret = 0;\n    BIGNUM *e = NULL;\n    ret = TEST_ptr(e = BN_new())\n          && TEST_true(BN_set_word(e, 65535))\n          && TEST_false(rsa_check_public_exponent(e))\n          && TEST_true(BN_set_word(e, 65536))\n          && TEST_false(rsa_check_public_exponent(e))\n          && TEST_true(BN_set_word(e, 65537))\n          && TEST_true(rsa_check_public_exponent(e))\n          && TEST_true(BN_lshift(e, BN_value_one(), 256))\n          && TEST_false(rsa_check_public_exponent(e))\n          && TEST_true(BN_sub(e, e, BN_value_one()))\n          && TEST_true(rsa_check_public_exponent(e));\n    BN_free(e);\n    return ret;\n}', 'const BIGNUM *BN_value_one(void)\n{\n    static const BN_ULONG data_one = 1L;\n    static const BIGNUM const_one =\n        { (BN_ULONG *)&data_one, 1, 1, 0, BN_FLG_STATIC_DATA };\n    return &const_one;\n}', 'int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n    int ret, r_neg, cmp_res;\n    bn_check_top(a);\n    bn_check_top(b);\n    if (a->neg != b->neg) {\n        r_neg = a->neg;\n        ret = BN_uadd(r, a, b);\n    } else {\n        cmp_res = BN_ucmp(a, b);\n        if (cmp_res > 0) {\n            r_neg = a->neg;\n            ret = BN_usub(r, a, b);\n        } else if (cmp_res < 0) {\n            r_neg = !b->neg;\n            ret = BN_usub(r, b, a);\n        } else {\n            r_neg = 0;\n            BN_zero(r);\n            ret = 1;\n        }\n    }\n    r->neg = r_neg;\n    bn_check_top(r);\n    return ret;\n}', 'int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n    int max, min, dif;\n    BN_ULONG t1, t2, borrow, *rp;\n    const BN_ULONG *ap, *bp;\n    bn_check_top(a);\n    bn_check_top(b);\n    max = a->top;\n    min = b->top;\n    dif = max - min;\n    if (dif < 0) {\n        BNerr(BN_F_BN_USUB, BN_R_ARG2_LT_ARG3);\n        return 0;\n    }\n    if (bn_wexpand(r, max) == NULL)\n        return 0;\n    ap = a->d;\n    bp = b->d;\n    rp = r->d;\n    borrow = bn_sub_words(rp, ap, bp, min);\n    ap += min;\n    rp += min;\n    while (dif) {\n        dif--;\n        t1 = *(ap++);\n        t2 = (t1 - borrow) & BN_MASK2;\n        *(rp++) = t2;\n        borrow &= (t1 == 0);\n    }\n    while (max && *--rp == 0)\n        max--;\n    r->top = max;\n    r->neg = 0;\n    bn_pollute(r);\n    return 1;\n}']