engines/ccgost/gost2001.c:319: error: BUFFER_OVERRUN_L3
  Offset: [-1, +oo] Size: [1, +oo] by call to `BN_mod_mul`.
Showing all 17 steps of the trace


engines/ccgost/gost2001.c:274:5: Call
272.       }
273.   
274.       BN_CTX_start(ctx);
           ^
275.       order = BN_CTX_get(ctx);
276.       e = BN_CTX_get(ctx);

crypto/bn/bn_ctx.c:236:1: Parameter `ctx->stack.depth`
  234.   }
  235.   
  236. > void BN_CTX_start(BN_CTX *ctx)
  237.   {
  238.       CTXDBG_ENTRY("BN_CTX_start", ctx);

engines/ccgost/gost2001.c:319:13: Call
317.       v = BN_mod_inverse(v, e, order, ctx);
318.       if (!v
319.           || !BN_mod_mul(z1, sig->s, v, order, ctx)
                   ^
320.           || !BN_sub(tmp, order, sig->r)
321.           || !BN_mod_mul(z2, tmp, v, order, ctx)) {

crypto/bn/bn_mod.c:179:1: Parameter `ctx->stack.depth`
  177.   
  178.   /* slow but works */
  179. > int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
  180.                  BN_CTX *ctx)
  181.   {

crypto/bn/bn_mod.c:189:5: Call
  187.       bn_check_top(m);
  188.   
  189.       BN_CTX_start(ctx);
             ^
  190.       if ((t = BN_CTX_get(ctx)) == NULL)
  191.           goto err;

crypto/bn/bn_ctx.c:236:1: Parameter `ctx->stack.depth`
    234.   }
    235.   
    236. > void BN_CTX_start(BN_CTX *ctx)
    237.   {
    238.       CTXDBG_ENTRY("BN_CTX_start", ctx);

crypto/bn/bn_mod.c:193:14: Call
  191.           goto err;
  192.       if (a == b) {
  193.           if (!BN_sqr(t, a, ctx))
                      ^
  194.               goto err;
  195.       } else {

crypto/bn/bn_sqr.c:81:5: Call
    79.       }
    80.   
    81.       BN_CTX_start(ctx);
              ^
    82.       rr = (a != r) ? r : BN_CTX_get(ctx);
    83.       tmp = BN_CTX_get(ctx);

crypto/bn/bn_ctx.c:236:1: Parameter `*ctx->stack.indexes`
      234.   }
      235.   
      236. > void BN_CTX_start(BN_CTX *ctx)
      237.   {
      238.       CTXDBG_ENTRY("BN_CTX_start", ctx);

crypto/bn/bn_sqr.c:148:5: Call
    146.       bn_check_top(rr);
    147.       bn_check_top(tmp);
    148.       BN_CTX_end(ctx);
               ^
    149.       return (ret);
    150.   }

crypto/bn/bn_ctx.c:250:1: Parameter `*ctx->stack.indexes`
      248.   }
      249.   
      250. > void BN_CTX_end(BN_CTX *ctx)
      251.   {
      252.       CTXDBG_ENTRY("BN_CTX_end", ctx);

crypto/bn/bn_ctx.c:256:27: Call
      254.           ctx->err_stack--;
      255.       else {
      256.           unsigned int fp = BN_STACK_pop(&ctx->stack);
                                       ^
      257.           /* Does this stack frame have anything to release? */
      258.           if (fp < ctx->used)

crypto/bn/bn_ctx.c:326:1: <Offset trace>
324.   }
325.   
326. > static unsigned int BN_STACK_pop(BN_STACK *st)
327.   {
328.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:326:1: Parameter `st->depth`
        324.   }
        325.   
        326. > static unsigned int BN_STACK_pop(BN_STACK *st)
        327.   {
        328.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:326:1: <Length trace>
324.   }
325.   
326. > static unsigned int BN_STACK_pop(BN_STACK *st)
327.   {
328.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:326:1: Parameter `*st->indexes`
        324.   }
        325.   
        326. > static unsigned int BN_STACK_pop(BN_STACK *st)
        327.   {
        328.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:328:12: Array access: Offset: [-1, +oo] Size: [1, +oo] by call to `BN_mod_mul` 
        326.   static unsigned int BN_STACK_pop(BN_STACK *st)
        327.   {
        328.       return st->indexes[--(st->depth)];
                          ^
        329.   }
        330.   

static unsigned int BN_STACK_pop(BN_STACK *st)
{
    return st->indexes[--(st->depth)];
}
['int gost2001_do_verify(const unsigned char *dgst, int dgst_len,\n                       DSA_SIG *sig, EC_KEY *ec)\n{\n    BN_CTX *ctx = BN_CTX_new();\n    const EC_GROUP *group = EC_KEY_get0_group(ec);\n    BIGNUM *order;\n    BIGNUM *md = NULL, *e = NULL, *R = NULL, *v = NULL, *z1 = NULL, *z2 =\n        NULL;\n    BIGNUM *X = NULL, *tmp = NULL;\n    EC_POINT *C = NULL;\n    const EC_POINT *pub_key = NULL;\n    int ok = 0;\n    if (!ctx || !group) {\n        GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    BN_CTX_start(ctx);\n    order = BN_CTX_get(ctx);\n    e = BN_CTX_get(ctx);\n    z1 = BN_CTX_get(ctx);\n    z2 = BN_CTX_get(ctx);\n    tmp = BN_CTX_get(ctx);\n    X = BN_CTX_get(ctx);\n    R = BN_CTX_get(ctx);\n    v = BN_CTX_get(ctx);\n    if (!order || !e || !z1 || !z2 || !tmp || !X || !R || !v) {\n        GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    pub_key = EC_KEY_get0_public_key(ec);\n    if (!pub_key || !EC_GROUP_get_order(group, order, ctx)) {\n        GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    if (BN_is_zero(sig->s) || BN_is_zero(sig->r) ||\n        (BN_cmp(sig->s, order) >= 1) || (BN_cmp(sig->r, order) >= 1)) {\n        GOSTerr(GOST_F_GOST2001_DO_VERIFY,\n                GOST_R_SIGNATURE_PARTS_GREATER_THAN_Q);\n        goto err;\n    }\n    md = hashsum2bn(dgst);\n    if (!md || !BN_mod(e, md, order, ctx)) {\n        GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n#ifdef DEBUG_SIGN\n    fprintf(stderr, "digest as bignum: ");\n    BN_print_fp(stderr, md);\n    fprintf(stderr, "\\ndigest mod q: ");\n    BN_print_fp(stderr, e);\n#endif\n    if (BN_is_zero(e) && !BN_one(e)) {\n        GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    v = BN_mod_inverse(v, e, order, ctx);\n    if (!v\n        || !BN_mod_mul(z1, sig->s, v, order, ctx)\n        || !BN_sub(tmp, order, sig->r)\n        || !BN_mod_mul(z2, tmp, v, order, ctx)) {\n        GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n#ifdef DEBUG_SIGN\n    fprintf(stderr, "\\nInverted digest value: ");\n    BN_print_fp(stderr, v);\n    fprintf(stderr, "\\nz1: ");\n    BN_print_fp(stderr, z1);\n    fprintf(stderr, "\\nz2: ");\n    BN_print_fp(stderr, z2);\n#endif\n    C = EC_POINT_new(group);\n    if (!C) {\n        GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    if (!EC_POINT_mul(group, C, z1, pub_key, z2, ctx)) {\n        GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_EC_LIB);\n        goto err;\n    }\n    if (!EC_POINT_get_affine_coordinates_GFp(group, C, X, NULL, ctx)) {\n        GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_EC_LIB);\n        goto err;\n    }\n    if (!BN_mod(R, X, order, ctx)) {\n        GOSTerr(GOST_F_GOST2001_DO_VERIFY, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n#ifdef DEBUG_SIGN\n    fprintf(stderr, "\\nX=");\n    BN_print_fp(stderr, X);\n    fprintf(stderr, "\\nX mod q=");\n    BN_print_fp(stderr, R);\n    fprintf(stderr, "\\n");\n#endif\n    if (BN_cmp(R, sig->r) != 0) {\n        GOSTerr(GOST_F_GOST2001_DO_VERIFY, GOST_R_SIGNATURE_MISMATCH);\n    } else {\n        ok = 1;\n    }\n err:\n    EC_POINT_free(C);\n    if (ctx)\n        BN_CTX_end(ctx);\n    BN_CTX_free(ctx);\n    BN_free(md);\n    return ok;\n}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n    CTXDBG_ENTRY("BN_CTX_start", ctx);\n    if (ctx->err_stack || ctx->too_many)\n        ctx->err_stack++;\n    else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n        BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n        ctx->err_stack++;\n    }\n    CTXDBG_EXIT(ctx);\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n               BN_CTX *ctx)\n{\n    BIGNUM *t;\n    int ret = 0;\n    bn_check_top(a);\n    bn_check_top(b);\n    bn_check_top(m);\n    BN_CTX_start(ctx);\n    if ((t = BN_CTX_get(ctx)) == NULL)\n        goto err;\n    if (a == b) {\n        if (!BN_sqr(t, a, ctx))\n            goto err;\n    } else {\n        if (!BN_mul(t, a, b, ctx))\n            goto err;\n    }\n    if (!BN_nnmod(r, t, m, ctx))\n        goto err;\n    bn_check_top(r);\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return (ret);\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n    int max, al;\n    int ret = 0;\n    BIGNUM *tmp, *rr;\n    bn_check_top(a);\n    al = a->top;\n    if (al <= 0) {\n        r->top = 0;\n        r->neg = 0;\n        return 1;\n    }\n    BN_CTX_start(ctx);\n    rr = (a != r) ? r : BN_CTX_get(ctx);\n    tmp = BN_CTX_get(ctx);\n    if (!rr || !tmp)\n        goto err;\n    max = 2 * al;\n    if (bn_wexpand(rr, max) == NULL)\n        goto err;\n    if (al == 4) {\n#ifndef BN_SQR_COMBA\n        BN_ULONG t[8];\n        bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n        bn_sqr_comba4(rr->d, a->d);\n#endif\n    } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n        BN_ULONG t[16];\n        bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n        bn_sqr_comba8(rr->d, a->d);\n#endif\n    } else {\n#if defined(BN_RECURSION)\n        if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n            BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n            bn_sqr_normal(rr->d, a->d, al, t);\n        } else {\n            int j, k;\n            j = BN_num_bits_word((BN_ULONG)al);\n            j = 1 << (j - 1);\n            k = j + j;\n            if (al == j) {\n                if (bn_wexpand(tmp, k * 2) == NULL)\n                    goto err;\n                bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n            } else {\n                if (bn_wexpand(tmp, max) == NULL)\n                    goto err;\n                bn_sqr_normal(rr->d, a->d, al, tmp->d);\n            }\n        }\n#else\n        if (bn_wexpand(tmp, max) == NULL)\n            goto err;\n        bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n    }\n    rr->neg = 0;\n    if (a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))\n        rr->top = max - 1;\n    else\n        rr->top = max;\n    if (rr != r)\n        BN_copy(r, rr);\n    ret = 1;\n err:\n    bn_check_top(rr);\n    bn_check_top(tmp);\n    BN_CTX_end(ctx);\n    return (ret);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n    CTXDBG_ENTRY("BN_CTX_end", ctx);\n    if (ctx->err_stack)\n        ctx->err_stack--;\n    else {\n        unsigned int fp = BN_STACK_pop(&ctx->stack);\n        if (fp < ctx->used)\n            BN_POOL_release(&ctx->pool, ctx->used - fp);\n        ctx->used = fp;\n        ctx->too_many = 0;\n    }\n    CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n    return st->indexes[--(st->depth)];\n}']