test/exptest.c:69: 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/exptest.c:68:5: Call
66.           goto err;
67.   
68.       BN_one(m);
          ^
69.       BN_one(a);
70.       BN_zero(p);

crypto/bn/bn_lib.c:402:15: Assignment
  400.       a->neg = 0;
  401.       a->d[0] = w;
  402.       a->top = (w ? 1 : 0);
                       ^
  403.       bn_check_top(a);
  404.       return (1);

crypto/bn/bn_lib.c:402:5: Assignment
  400.       a->neg = 0;
  401.       a->d[0] = w;
  402.       a->top = (w ? 1 : 0);
             ^
  403.       bn_check_top(a);
  404.       return (1);

test/exptest.c:69:5: Call
67.   
68.       BN_one(m);
69.       BN_one(a);
          ^
70.       BN_zero(p);
71.   

crypto/bn/bn_lib.c:395:1: Parameter `*a->d`
  393.   }
  394.   
  395. > int BN_set_word(BIGNUM *a, BN_ULONG w)
  396.   {
  397.       bn_check_top(a);

crypto/bn/bn_lib.c:398:9: Call
  396.   {
  397.       bn_check_top(a);
  398.       if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
                 ^
  399.           return (0);
  400.       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:284:1: Parameter `*b->d`
      282.    */
      283.   
      284. > BIGNUM *bn_expand2(BIGNUM *b, int words)
      285.   {
      286.       bn_check_top(b);

crypto/bn/bn_lib.c:289:23: Call
      287.   
      288.       if (words > b->dmax) {
      289.           BN_ULONG *a = bn_expand_internal(b, words);
                                   ^
      290.           if (!a)
      291.               return NULL;

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

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

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

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

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

static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *a = NULL;
    bn_check_top(b);
    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_mod_exp_zero()\n{\n    BIGNUM *a = NULL, *p = NULL, *m = NULL;\n    BIGNUM *r = NULL;\n    BN_ULONG one_word = 1;\n    BN_CTX *ctx = BN_CTX_new();\n    int ret = 1, failed = 0;\n    if (!TEST_ptr(m = BN_new())\n        || !TEST_ptr(a = BN_new())\n        || !TEST_ptr(p = BN_new())\n        || !TEST_ptr(r = BN_new()))\n        goto err;\n    BN_one(m);\n    BN_one(a);\n    BN_zero(p);\n    if (!TEST_true(BN_rand(a, 1024, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY)))\n        goto err;\n    if (!TEST_true(BN_mod_exp(r, a, p, m, ctx)))\n        goto err;\n    if (!TEST_true(a_is_zero_mod_one("BN_mod_exp", r, a)))\n        failed = 1;\n    if (!TEST_true(BN_mod_exp_recp(r, a, p, m, ctx)))\n        goto err;\n    if (!TEST_true(a_is_zero_mod_one("BN_mod_exp_recp", r, a)))\n        failed = 1;\n    if (!TEST_true(BN_mod_exp_simple(r, a, p, m, ctx)))\n        goto err;\n    if (!TEST_true(a_is_zero_mod_one("BN_mod_exp_simple", r, a)))\n        failed = 1;\n    if (!TEST_true(BN_mod_exp_mont(r, a, p, m, ctx, NULL)))\n        goto err;\n    if (!TEST_true(a_is_zero_mod_one("BN_mod_exp_mont", r, a)))\n        failed = 1;\n    if (!TEST_true(BN_mod_exp_mont_consttime(r, a, p, m, ctx, NULL)))\n        goto err;\n    if (!TEST_true(a_is_zero_mod_one("BN_mod_exp_mont_consttime", r, a)))\n        failed = 1;\n    if (!TEST_true(BN_mod_exp_mont_word(r, one_word, p, m, ctx, NULL)))\n        goto err;\n    if (!TEST_true(BN_is_zero(r))) {\n        fprintf(stderr, "BN_mod_exp_mont_word failed:\\n");\n        fprintf(stderr, "1 ** 0 mod 1 = r (should be 0)\\n");\n        BN_print_var(r);\n        goto err;\n    }\n    ret = !failed;\n err:\n    BN_free(r);\n    BN_free(a);\n    BN_free(p);\n    BN_free(m);\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    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    bn_check_top(b);\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    bn_check_top(b);\n    return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n    BN_ULONG *a = NULL;\n    bn_check_top(b);\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}']