crypto/sm2/sm2_sign.c:214: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 67108856] by call to `BN_mod_add`.
Showing all 26 steps of the trace


crypto/sm2/sm2_sign.c:208:9: Call
206.           goto done;
207.   
208.       if (EC_POINT_mul(group, pt, s, EC_KEY_get0_public_key(key), t, ctx) == 0)
               ^
209.           goto done;
210.   

crypto/ec/ec_lib.c:932:12: Call
  930.       scalars[0] = p_scalar;
  931.   
  932.       return EC_POINTs_mul(group, r, g_scalar,
                    ^
  933.                            (point != NULL
  934.                             && p_scalar != NULL), points, scalars, ctx);

crypto/ec/ec_lib.c:910:1: Parameter `(*scalars)->top`
    908.    */
    909.   
    910. > int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
    911.                     size_t num, const EC_POINT *points[],
    912.                     const BIGNUM *scalars[], BN_CTX *ctx)

crypto/sm2/sm2_sign.c:214:9: Call
212.           goto done;
213.   
214.       if (BN_mod_add(t, e, x1, order, ctx) == 0)
               ^
215.           goto done;
216.   

crypto/bn/bn_mod.c:28:1: Parameter `r->top`
  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->top`
    12.   
    13.   /* r can == a or b */
    14. > int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
    15.   {
    16.       int a_neg = a->neg, ret;

crypto/bn/bn_add.c:51:11: Call
    49.       }
    50.   
    51.       ret = BN_uadd(r, a, b);
                    ^
    52.       r->neg = a_neg;
    53.       bn_check_top(r);

crypto/bn/bn_add.c:58:1: Parameter `r->top`
      56.   
      57.   /* unsigned add of b to a */
      58. > int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
      59.   {
      60.       int max, min, dif;

crypto/bn/bn_add.c:78:9: Call
      76.       dif = max - min;
      77.   
      78.       if (bn_wexpand(r, max + 1) == NULL)
                    ^
      79.           return 0;
      80.   

crypto/bn/bn_lib.c:910:1: Parameter `a->top`
        908.   }
        909.   
        910. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
        911.   {
        912.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:912:37: Call
        910.   BIGNUM *bn_wexpand(BIGNUM *a, int words)
        911.   {
        912.       return (words <= a->dmax) ? a : bn_expand2(a, words);
                                                   ^
        913.   }
        914.   

crypto/bn/bn_lib.c:246:1: Parameter `b->top`
          244.    */
          245.   
          246. > BIGNUM *bn_expand2(BIGNUM *b, int words)
          247.   {
          248.       bn_check_top(b);

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

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

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

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

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

crypto/bn/bn_lib.c:225:13: Call
            223.           a = OPENSSL_secure_zalloc(words * sizeof(*a));
            224.       else
            225.           a = OPENSSL_zalloc(words * sizeof(*a));
                               ^
            226.       if (a == NULL) {
            227.           BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);

crypto/mem.c:228:1: Parameter `num`
              226.   }
              227.   
              228. > void *CRYPTO_zalloc(size_t num, const char *file, int line)
              229.   {
              230.       void *ret = CRYPTO_malloc(num, file, line);

crypto/mem.c:230:17: Call
              228.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
              229.   {
              230.       void *ret = CRYPTO_malloc(num, file, line);
                                     ^
              231.   
              232.       FAILTEST();

crypto/mem.c:201:9: Assignment
                199.   
                200.       if (num == 0)
                201.           return NULL;
                               ^
                202.   
                203.       FAILTEST();

crypto/mem.c:230:5: Assignment
              228.   void *CRYPTO_zalloc(size_t num, const char *file, int line)
              229.   {
              230.       void *ret = CRYPTO_malloc(num, file, line);
                         ^
              231.   
              232.       FAILTEST();

crypto/mem.c:235:5: Assignment
              233.       if (ret != NULL)
              234.           memset(ret, 0, num);
              235.       return ret;
                         ^
              236.   }
              237.   

crypto/bn/bn_lib.c:225:9: Assignment
            223.           a = OPENSSL_secure_zalloc(words * sizeof(*a));
            224.       else
            225.           a = OPENSSL_zalloc(words * sizeof(*a));
                           ^
            226.       if (a == NULL) {
            227.           BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);

crypto/bn/bn_lib.c:233:9: Array access: Offset added: [8, +oo] Size: [0, 67108856] by call to `BN_mod_add` 
            231.       assert(b->top <= words);
            232.       if (b->top > 0)
            233.           memcpy(a, b->d, sizeof(*a) * b->top);
                           ^
            234.   
            235.       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\nint SM2_sig_verify(const EC_KEY *key, const ECDSA_SIG *sig, 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    if (ctx == NULL)\n        goto done;\n    pt = EC_POINT_new(group);\n    if (pt == NULL)\n        goto done;\n    BN_CTX_start(ctx);\n    t = BN_CTX_get(ctx);\n    x1 = BN_CTX_get(ctx);\n    if (x1 == NULL)\n        goto done;\n    ECDSA_SIG_get0(sig, &r, &s);\n    if (BN_cmp(r, BN_value_one()) < 0)\n        goto done;\n    if (BN_cmp(s, BN_value_one()) < 0)\n        goto done;\n    if (BN_cmp(order, r) <= 0)\n        goto done;\n    if (BN_cmp(order, s) <= 0)\n        goto done;\n    if (BN_mod_add(t, r, s, order, ctx) == 0)\n        goto done;\n    if (BN_is_zero(t) == 1)\n        goto done;\n    if (EC_POINT_mul(group, pt, s, EC_KEY_get0_public_key(key), t, ctx) == 0)\n        goto done;\n    if (EC_POINT_get_affine_coordinates_GFp(group, pt, x1, NULL, ctx) == 0)\n        goto done;\n    if (BN_mod_add(t, e, x1, order, ctx) == 0)\n        goto done;\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}', 'int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,\n                 const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)\n{\n    const EC_POINT *points[1];\n    const BIGNUM *scalars[1];\n    points[0] = point;\n    scalars[0] = p_scalar;\n    return EC_POINTs_mul(group, r, g_scalar,\n                         (point != NULL\n                          && p_scalar != NULL), points, scalars, ctx);\n}', 'int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n                  size_t num, const EC_POINT *points[],\n                  const BIGNUM *scalars[], BN_CTX *ctx)\n{\n    if (group->meth->mul == 0)\n        return ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);\n    return group->meth->mul(group, r, scalar, num, points, scalars, ctx);\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 a_neg = a->neg, ret;\n    bn_check_top(a);\n    bn_check_top(b);\n    if (a_neg ^ b->neg) {\n        if (a_neg) {\n            const BIGNUM *tmp;\n            tmp = a;\n            a = b;\n            b = tmp;\n        }\n        if (BN_ucmp(a, b) < 0) {\n            if (!BN_usub(r, b, a))\n                return 0;\n            r->neg = 1;\n        } else {\n            if (!BN_usub(r, a, b))\n                return 0;\n            r->neg = 0;\n        }\n        return 1;\n    }\n    ret = BN_uadd(r, a, b);\n    r->neg = a_neg;\n    bn_check_top(r);\n    return ret;\n}', 'int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)\n{\n    int max, min, dif;\n    const BN_ULONG *ap, *bp;\n    BN_ULONG *rp, carry, t1, t2;\n    bn_check_top(a);\n    bn_check_top(b);\n    if (a->top < b->top) {\n        const BIGNUM *tmp;\n        tmp = a;\n        a = b;\n        b = tmp;\n    }\n    max = a->top;\n    min = b->top;\n    dif = max - min;\n    if (bn_wexpand(r, max + 1) == NULL)\n        return 0;\n    r->top = max;\n    ap = a->d;\n    bp = b->d;\n    rp = r->d;\n    carry = bn_add_words(rp, ap, bp, min);\n    rp += min;\n    ap += min;\n    while (dif) {\n        dif--;\n        t1 = *(ap++);\n        t2 = (t1 + carry) & BN_MASK2;\n        *(rp++) = t2;\n        carry &= (t2 == 0);\n    }\n    *rp = carry;\n    r->top += carry;\n    r->neg = 0;\n    bn_check_top(r);\n    return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\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}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    FAILTEST();\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    INCREMENT(malloc_count);\n    if (malloc_impl != NULL && malloc_impl != CRYPTO_malloc)\n        return malloc_impl(num, file, line);\n    if (num == 0)\n        return NULL;\n    FAILTEST();\n    if (allow_customize) {\n        allow_customize = 0;\n    }\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    (void)(file); (void)(line);\n    ret = malloc(num);\n#endif\n    return ret;\n}']