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


crypto/rsa/rsa_sp800_56b_check.c:224:26: Call
222.                   BIGNUM *p1q1)
223.   {
224.       return BN_sub(p1, p, BN_value_one())    /* p-1 */
                                ^
225.              && BN_sub(q1, q, BN_value_one()) /* q-1 */
226.              && BN_mul(p1q1, p1, q1, ctx)     /* (p-1)(q-1) */

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;

crypto/rsa/rsa_sp800_56b_check.c:224:12: Call
222.                   BIGNUM *p1q1)
223.   {
224.       return BN_sub(p1, p, BN_value_one())    /* p-1 */
                  ^
225.              && BN_sub(q1, q, BN_value_one()) /* q-1 */
226.              && BN_mul(p1q1, p1, q1, ctx)     /* (p-1)(q-1) */

crypto/bn/bn_add.c:45:1: Parameter `b->top`
  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:152:5: Assignment
    150.       borrow = bn_sub_words(rp, ap, bp, min);
    151.       ap += min;
    152.       rp += min;
               ^
    153.   
    154.       while (dif) {

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

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;
}
['int rsa_get_lcm(BN_CTX *ctx, const BIGNUM *p, const BIGNUM *q,\n                BIGNUM *lcm, BIGNUM *gcd, BIGNUM *p1, BIGNUM *q1,\n                BIGNUM *p1q1)\n{\n    return BN_sub(p1, p, BN_value_one())\n           && BN_sub(q1, q, BN_value_one())\n           && BN_mul(p1q1, p1, q1, ctx)\n           && BN_gcd(gcd, p1, q1, ctx)\n           && BN_div(lcm, NULL, p1q1, gcd, ctx);\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}']