crypto/sm2/sm2_sign.c:334: error: BUFFER_OVERRUN_L3
  Offset: 0 Size: [0, 8388607] by call to `BN_mod_add`.
Showing all 15 steps of the trace


crypto/sm2/sm2_sign.c:307:9: Call
305.   
306.       BN_CTX_start(ctx);
307.       t = BN_CTX_get(ctx);
               ^
308.       x1 = BN_CTX_get(ctx);
309.       if (x1 == NULL) {

crypto/bn/bn_ctx.c:229:5: Call
  227.       }
  228.       /* OK, make sure the returned bignum is "zero" */
  229.       BN_zero(ret);
             ^
  230.       ctx->used++;
  231.       CTXDBG_RET(ctx, ret);

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

crypto/bn/bn_lib.c:362:9: Call
    360.   {
    361.       bn_check_top(a);
    362.       if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
                   ^
    363.           return 0;
    364.       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/sm2/sm2_sign.c:334:10: Call
332.       }
333.   
334.       if (!BN_mod_add(t, r, s, order, ctx)) {
                ^
335.           SM2err(SM2_F_SM2_SIG_VERIFY, ERR_R_BN_LIB);
336.           goto done;

crypto/bn/bn_mod.c:28:1: Parameter `*r->d`
  26.   }
  27.   
  28. > int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
  29.                  BN_CTX *ctx)
  30.   {

crypto/bn/bn_mod.c:31:10: Call
  29.                  BN_CTX *ctx)
  30.   {
  31.       if (!BN_add(r, a, b))
                 ^
  32.           return 0;
  33.       return BN_nnmod(r, r, m, ctx);

crypto/bn/bn_add.c:14:1: Parameter `*r->d`
    12.   
    13.   /* signed add of b to a. */
    14. > int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
    15.   {
    16.       int ret, r_neg, cmp_res;

crypto/bn/bn_add.c:34:13: Call
    32.           } else {
    33.               r_neg = 0;
    34.               BN_zero(r);
                      ^
    35.               ret = 1;
    36.           }

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

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

crypto/bn/bn_lib.c:362:9: Call
      360.   {
      361.       bn_check_top(a);
      362.       if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
                     ^
      363.           return 0;
      364.       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:365:5: Array access: Offset: 0 Size: [0, 8388607] by call to `BN_mod_add` 
      363.           return 0;
      364.       a->neg = 0;
      365.       a->d[0] = w;
                 ^
      366.       a->top = (w ? 1 : 0);
      367.       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 sm2_sig_verify(const EC_KEY *key, const ECDSA_SIG *sig,\n                          const BIGNUM *e)\n{\n    int ret = 0;\n    const EC_GROUP *group = EC_KEY_get0_group(key);\n    const BIGNUM *order = EC_GROUP_get0_order(group);\n    BN_CTX *ctx = NULL;\n    EC_POINT *pt = NULL;\n    BIGNUM *t = NULL;\n    BIGNUM *x1 = NULL;\n    const BIGNUM *r = NULL;\n    const BIGNUM *s = NULL;\n    ctx = BN_CTX_new();\n    pt = EC_POINT_new(group);\n    if (ctx == NULL || pt == NULL) {\n        SM2err(SM2_F_SM2_SIG_VERIFY, ERR_R_MALLOC_FAILURE);\n        goto done;\n    }\n    BN_CTX_start(ctx);\n    t = BN_CTX_get(ctx);\n    x1 = BN_CTX_get(ctx);\n    if (x1 == NULL) {\n        SM2err(SM2_F_SM2_SIG_VERIFY, ERR_R_MALLOC_FAILURE);\n        goto done;\n    }\n    ECDSA_SIG_get0(sig, &r, &s);\n    if (BN_cmp(r, BN_value_one()) < 0\n            || BN_cmp(s, BN_value_one()) < 0\n            || BN_cmp(order, r) <= 0\n            || BN_cmp(order, s) <= 0) {\n        SM2err(SM2_F_SM2_SIG_VERIFY, SM2_R_BAD_SIGNATURE);\n        goto done;\n    }\n    if (!BN_mod_add(t, r, s, order, ctx)) {\n        SM2err(SM2_F_SM2_SIG_VERIFY, ERR_R_BN_LIB);\n        goto done;\n    }\n    if (BN_is_zero(t)) {\n        SM2err(SM2_F_SM2_SIG_VERIFY, SM2_R_BAD_SIGNATURE);\n        goto done;\n    }\n    if (!EC_POINT_mul(group, pt, s, EC_KEY_get0_public_key(key), t, ctx)\n            || !EC_POINT_get_affine_coordinates(group, pt, x1, NULL, ctx)) {\n        SM2err(SM2_F_SM2_SIG_VERIFY, ERR_R_EC_LIB);\n        goto done;\n    }\n    if (!BN_mod_add(t, e, x1, order, ctx)) {\n        SM2err(SM2_F_SM2_SIG_VERIFY, ERR_R_BN_LIB);\n        goto done;\n    }\n    if (BN_cmp(r, t) == 0)\n        ret = 1;\n done:\n    EC_POINT_free(pt);\n    BN_CTX_free(ctx);\n    return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n    BIGNUM *ret;\n    CTXDBG_ENTRY("BN_CTX_get", ctx);\n    if (ctx->err_stack || ctx->too_many)\n        return NULL;\n    if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n        ctx->too_many = 1;\n        BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n        return NULL;\n    }\n    BN_zero(ret);\n    ctx->used++;\n    CTXDBG_RET(ctx, 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}', 'int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n               BN_CTX *ctx)\n{\n    if (!BN_add(r, a, b))\n        return 0;\n    return BN_nnmod(r, r, m, ctx);\n}', 'int BN_add(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}']