test/rsa_sp800_56b_test.c:608: error: BUFFER_OVERRUN_L3
  Offset: 0 Size: [0, 8388607] by call to `BN_set_word`.
Showing all 9 steps of the trace


test/rsa_sp800_56b_test.c:595:14: Call
593.             && TEST_false(rsa_sp800_56b_check_private(key))
594.             /* load private key */
595.             && TEST_ptr(n = bn_load_new(cav_n, sizeof(cav_n)))
                    ^
596.             && TEST_ptr(d = bn_load_new(cav_d, sizeof(cav_d)))
597.             && TEST_ptr(e = bn_load_new(cav_e, sizeof(cav_e)))

test/rsa_sp800_56b_test.c:161:9: Call
  159.       BIGNUM *ret = BN_new();
  160.       if (ret != NULL)
  161.           BN_bin2bn(data, sz, ret);
                 ^
  162.       return ret;
  163.   }

crypto/bn/bn_lib.c:374:1: Parameter `*ret->d`
    372.   }
    373.   
    374. > BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
    375.   {
    376.       unsigned int i, m;

test/rsa_sp800_56b_test.c:608:14: Call
606.       ret = TEST_true(rsa_sp800_56b_check_private(key))
607.             /* check d is too low */
608.             && TEST_true(BN_set_word(d, 0))
                    ^
609.             && TEST_false(rsa_sp800_56b_check_private(key))
610.             /* check d is too high */

crypto/bn/bn_lib.c:361:1: <Length trace>
359.   }
360.   
361. > int BN_set_word(BIGNUM *a, BN_ULONG w)
362.   {
363.       bn_check_top(a);

crypto/bn/bn_lib.c:361:1: Parameter `*a->d`
  359.   }
  360.   
  361. > int BN_set_word(BIGNUM *a, BN_ULONG w)
  362.   {
  363.       bn_check_top(a);

crypto/bn/bn_lib.c:364:9: Call
  362.   {
  363.       bn_check_top(a);
  364.       if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
                 ^
  365.           return 0;
  366.       a->neg = 0;

crypto/bn/bn_lcl.h:660:1: Parameter `*a->d`
    658.                            const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx);
    659.   
    660. > static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)
    661.   {
    662.       if (bits > (INT_MAX - BN_BITS2 + 1))

crypto/bn/bn_lib.c:367:5: Array access: Offset: 0 Size: [0, 8388607] by call to `BN_set_word` 
  365.           return 0;
  366.       a->neg = 0;
  367.       a->d[0] = w;
             ^
  368.       a->top = (w ? 1 : 0);
  369.       a->flags &= ~BN_FLG_FIXED_TOP;

int BN_set_word(BIGNUM *a, BN_ULONG w)
{
    bn_check_top(a);
    if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
        return 0;
    a->neg = 0;
    a->d[0] = w;
    a->top = (w ? 1 : 0);
    a->flags &= ~BN_FLG_FIXED_TOP;
    bn_check_top(a);
    return 1;
}
['static int test_check_private_key(void)\n{\n    int ret = 0;\n    BIGNUM *n = NULL, *d = NULL, *e = NULL;\n    RSA *key = NULL;\n    ret = TEST_ptr(key = RSA_new())\n          && TEST_false(rsa_sp800_56b_check_private(key))\n          && TEST_ptr(n = bn_load_new(cav_n, sizeof(cav_n)))\n          && TEST_ptr(d = bn_load_new(cav_d, sizeof(cav_d)))\n          && TEST_ptr(e = bn_load_new(cav_e, sizeof(cav_e)))\n          && TEST_true(RSA_set0_key(key, n, e, d));\n    if (!ret) {\n        BN_free(n);\n        BN_free(e);\n        BN_free(d);\n        goto end;\n    }\n    ret = TEST_true(rsa_sp800_56b_check_private(key))\n          && TEST_true(BN_set_word(d, 0))\n          && TEST_false(rsa_sp800_56b_check_private(key))\n          && TEST_ptr(BN_copy(d, n))\n          && TEST_false(rsa_sp800_56b_check_private(key));\nend:\n    RSA_free(key);\n    return ret;\n}', 'static BIGNUM *bn_load_new(const unsigned char *data, int sz)\n{\n    BIGNUM *ret = BN_new();\n    if (ret != NULL)\n        BN_bin2bn(data, sz, ret);\n    return ret;\n}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n    unsigned int i, m;\n    unsigned int n;\n    BN_ULONG l;\n    BIGNUM *bn = NULL;\n    if (ret == NULL)\n        ret = bn = BN_new();\n    if (ret == NULL)\n        return NULL;\n    bn_check_top(ret);\n    for ( ; len > 0 && *s == 0; s++, len--)\n        continue;\n    n = len;\n    if (n == 0) {\n        ret->top = 0;\n        return ret;\n    }\n    i = ((n - 1) / BN_BYTES) + 1;\n    m = ((n - 1) % (BN_BYTES));\n    if (bn_wexpand(ret, (int)i) == NULL) {\n        BN_free(bn);\n        return NULL;\n    }\n    ret->top = i;\n    ret->neg = 0;\n    l = 0;\n    while (n--) {\n        l = (l << 8L) | *(s++);\n        if (m-- == 0) {\n            ret->d[--i] = l;\n            l = 0;\n            m = BN_BYTES - 1;\n        }\n    }\n    bn_correct_top(ret);\n    return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n    bn_check_top(a);\n    if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n        return 0;\n    a->neg = 0;\n    a->d[0] = w;\n    a->top = (w ? 1 : 0);\n    a->flags &= ~BN_FLG_FIXED_TOP;\n    bn_check_top(a);\n    return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n    if (bits > (INT_MAX - BN_BITS2 + 1))\n        return NULL;\n    if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n        return a;\n    return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}']