test/rsa_sp800_56b_test.c:295: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 536870848] by call to `BN_set_word`.
Showing all 15 steps of the trace


test/rsa_sp800_56b_test.c:294:14: Call
292.             && TEST_ptr(q = BN_new())
293.             /* lcm(15-1,17-1) = 14*16 / 2 = 112 */
294.             && TEST_true(BN_set_word(p, 15))
                    ^
295.             && TEST_true(BN_set_word(q, 17))
296.             && TEST_true(RSA_set0_factors(key, p, q));

crypto/bn/bn_lib.c:368:15: Assignment
  366.       a->neg = 0;
  367.       a->d[0] = w;
  368.       a->top = (w ? 1 : 0);
                       ^
  369.       a->flags &= ~BN_FLG_FIXED_TOP;
  370.       bn_check_top(a);

crypto/bn/bn_lib.c:368:5: Assignment
  366.       a->neg = 0;
  367.       a->d[0] = w;
  368.       a->top = (w ? 1 : 0);
             ^
  369.       a->flags &= ~BN_FLG_FIXED_TOP;
  370.       bn_check_top(a);

test/rsa_sp800_56b_test.c:295:14: Call
293.             /* lcm(15-1,17-1) = 14*16 / 2 = 112 */
294.             && TEST_true(BN_set_word(p, 15))
295.             && TEST_true(BN_set_word(q, 17))
                    ^
296.             && TEST_true(RSA_set0_factors(key, p, q));
297.       if (!ret) {

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_lcl.h:668:12: Call
    666.           return a;
    667.   
    668.       return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);
                      ^
    669.   }
    670.   

crypto/bn/bn_lib.c:245:1: Parameter `*b->d`
      243.    */
      244.   
      245. > BIGNUM *bn_expand2(BIGNUM *b, int words)
      246.   {
      247.       if (words > b->dmax) {

crypto/bn/bn_lib.c:248:23: Call
      246.   {
      247.       if (words > b->dmax) {
      248.           BN_ULONG *a = bn_expand_internal(b, words);
                                   ^
      249.           if (!a)
      250.               return NULL;

crypto/bn/bn_lib.c:209:1: <Offset trace>
207.   /* This is used by bn_expand2() */
208.   /* The caller MUST check that words > b->dmax before calling this */
209. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
210.   {
211.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:209:1: Parameter `b->top`
        207.   /* This is used by bn_expand2() */
        208.   /* The caller MUST check that words > b->dmax before calling this */
        209. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
        210.   {
        211.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:209:1: <Length trace>
207.   /* This is used by bn_expand2() */
208.   /* The caller MUST check that words > b->dmax before calling this */
209. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
210.   {
211.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:209:1: Parameter `*b->d`
        207.   /* This is used by bn_expand2() */
        208.   /* The caller MUST check that words > b->dmax before calling this */
        209. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
        210.   {
        211.       BN_ULONG *a = NULL;

crypto/bn/bn_lib.c:232:9: Array access: Offset added: [8, +oo] Size: [0, 536870848] by call to `BN_set_word` 
        230.       assert(b->top <= words);
        231.       if (b->top > 0)
        232.           memcpy(a, b->d, sizeof(*a) * b->top);
                       ^
        233.   
        234.       return a;

static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *a = NULL;
    if (words > (INT_MAX / (4 * BN_BITS2))) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
        return NULL;
    }
    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
        return NULL;
    }
    if (BN_get_flags(b, BN_FLG_SECURE))
        a = OPENSSL_secure_zalloc(words * sizeof(*a));
    else
        a = OPENSSL_zalloc(words * sizeof(*a));
    if (a == NULL) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
        return NULL;
    }
    assert(b->top <= words);
    if (b->top > 0)
        memcpy(a, b->d, sizeof(*a) * b->top);
    return a;
}
['static int test_check_private_exponent(void)\n{\n    int ret = 0;\n    RSA *key = NULL;\n    BN_CTX *ctx = NULL;\n    BIGNUM *p = NULL, *q = NULL, *e = NULL, *d = NULL, *n = NULL;\n    ret = TEST_ptr(key = RSA_new())\n          && TEST_ptr(ctx = BN_CTX_new())\n          && TEST_ptr(p = BN_new())\n          && TEST_ptr(q = BN_new())\n          && TEST_true(BN_set_word(p, 15))\n          && TEST_true(BN_set_word(q, 17))\n          && TEST_true(RSA_set0_factors(key, p, q));\n    if (!ret) {\n        BN_free(p);\n        BN_free(q);\n        goto end;\n    }\n    ret = TEST_ptr(e = BN_new())\n          && TEST_ptr(d = BN_new())\n          && TEST_ptr(n = BN_new())\n          && TEST_true(BN_set_word(e, 5))\n          && TEST_true(BN_set_word(d, 157))\n          && TEST_true(BN_set_word(n, 15*17))\n          && TEST_true(RSA_set0_key(key, n, e, d));\n    if (!ret) {\n        BN_free(e);\n        BN_free(d);\n        BN_free(n);\n        goto end;\n    }\n    ret = TEST_false(rsa_check_private_exponent(key, 8, ctx))\n          && TEST_true(BN_set_word(d, 45))\n          && TEST_true(rsa_check_private_exponent(key, 8, ctx))\n          && TEST_false(rsa_check_private_exponent(key, 16, ctx))\n          && TEST_true(BN_set_word(d, 16))\n          && TEST_false(rsa_check_private_exponent(key, 8, ctx))\n          && TEST_true(BN_set_word(d, 46))\n          && TEST_false(rsa_check_private_exponent(key, 8, ctx));\nend:\n    RSA_free(key);\n    BN_CTX_free(ctx);\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}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n    if (words > b->dmax) {\n        BN_ULONG *a = bn_expand_internal(b, words);\n        if (!a)\n            return NULL;\n        if (b->d) {\n            OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n            bn_free_d(b);\n        }\n        b->d = a;\n        b->dmax = words;\n    }\n    return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n    BN_ULONG *a = NULL;\n    if (words > (INT_MAX / (4 * BN_BITS2))) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n        return NULL;\n    }\n    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n        return NULL;\n    }\n    if (BN_get_flags(b, BN_FLG_SECURE))\n        a = OPENSSL_secure_zalloc(words * sizeof(*a));\n    else\n        a = OPENSSL_zalloc(words * sizeof(*a));\n    if (a == NULL) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n        return NULL;\n    }\n    assert(b->top <= words);\n    if (b->top > 0)\n        memcpy(a, b->d, sizeof(*a) * b->top);\n    return a;\n}']