test/srptest.c:45: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 536870848] by call to `SRP_create_verifier_BN`.
Showing all 16 steps of the trace


test/srptest.c:45:10: Call
43.   
44.       /* Set up server's password entry */
45.       if (!TEST_true(SRP_create_verifier_BN(username, server_pass,
               ^
46.                                             &s, &v, GN->N, GN->g)))
47.           goto end;

crypto/srp/srp_vfy.c:533:1: Parameter `N->top`
  531.    * BIGNUMS.
  532.    */
  533. > int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,
  534.                              BIGNUM **verifier, const BIGNUM *N,
  535.                              const BIGNUM *g)

crypto/srp/srp_vfy.c:564:10: Call
  562.           goto err;
  563.   
  564.       if (!BN_mod_exp(*verifier, g, x, N, bn_ctx)) {
                  ^
  565.           BN_clear_free(*verifier);
  566.           goto err;

crypto/bn/bn_exp.c:88:1: Parameter `m->top`
    86.   }
    87.   
    88. > int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
    89.                  BN_CTX *ctx)
    90.   {

crypto/bn/bn_exp.c:133:9: Call
    131.   
    132.   #ifdef MONT_MUL_MOD
    133.       if (BN_is_odd(m)) {
                   ^
    134.   # ifdef MONT_EXP_WORD
    135.           if (a->top == 1 && !a->neg

crypto/bn/bn_lib.c:870:1: Parameter `a->top`
      868.   }
      869.   
      870. > int BN_is_odd(const BIGNUM *a)
      871.   {
      872.       return (a->top > 0) && (a->d[0] & 1);

crypto/bn/bn_exp.c:146:15: Call
    144.   #ifdef RECP_MUL_MOD
    145.       {
    146.           ret = BN_mod_exp_recp(r, a, p, m, ctx);
                         ^
    147.       }
    148.   #else

crypto/bn/bn_exp.c:158:1: Parameter `m->top`
      156.   }
      157.   
      158. > int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
      159.                       const BIGNUM *m, BN_CTX *ctx)
      160.   {

crypto/bn/bn_exp.c:195:14: Call
      193.       if (m->neg) {
      194.           /* ignore sign of 'm' */
      195.           if (!BN_copy(aa, m))
                          ^
      196.               goto err;
      197.           aa->neg = 0;

crypto/bn/bn_lib.c:323:1: <Offset trace>
321.   }
322.   
323. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
324.   {
325.       bn_check_top(b);

crypto/bn/bn_lib.c:323:1: Parameter `b->top`
        321.   }
        322.   
        323. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
        324.   {
        325.       bn_check_top(b);

crypto/bn/bn_lib.c:323:1: <Length trace>
321.   }
322.   
323. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
324.   {
325.       bn_check_top(b);

crypto/bn/bn_lib.c:323:1: Parameter `*a->d`
        321.   }
        322.   
        323. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
        324.   {
        325.       bn_check_top(b);

crypto/bn/bn_lib.c:329:9: Call
        327.       if (a == b)
        328.           return a;
        329.       if (bn_wexpand(a, b->top) == NULL)
                       ^
        330.           return NULL;
        331.   

crypto/bn/bn_lib.c:951:1: Parameter `*a->d`
          949.   }
          950.   
          951. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
          952.   {
          953.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:333:9: Array access: Offset added: [8, +oo] Size: [0, 536870848] by call to `SRP_create_verifier_BN` 
        331.   
        332.       if (b->top > 0)
        333.           memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
                       ^
        334.   
        335.       if (BN_get_flags(b, BN_FLG_CONSTTIME) != 0)

BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
{
    bn_check_top(b);
    if (a == b)
        return a;
    if (bn_wexpand(a, b->top) == NULL)
        return NULL;
    if (b->top > 0)
        memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
    if (BN_get_flags(b, BN_FLG_CONSTTIME) != 0)
        BN_set_flags(a, BN_FLG_CONSTTIME);
    a->top = b->top;
    a->neg = b->neg;
    bn_check_top(a);
    return a;
}
['static int run_srp(const char *username, const char *client_pass,\n                   const char *server_pass)\n{\n    int ret = 0;\n    BIGNUM *s = NULL;\n    BIGNUM *v = NULL;\n    BIGNUM *a = NULL;\n    BIGNUM *b = NULL;\n    BIGNUM *u = NULL;\n    BIGNUM *x = NULL;\n    BIGNUM *Apub = NULL;\n    BIGNUM *Bpub = NULL;\n    BIGNUM *Kclient = NULL;\n    BIGNUM *Kserver = NULL;\n    unsigned char rand_tmp[RANDOM_SIZE];\n    const SRP_gN *GN;\n    if (!TEST_ptr(GN = SRP_get_default_gN("1024")))\n        return 0;\n    if (!TEST_true(SRP_create_verifier_BN(username, server_pass,\n                                          &s, &v, GN->N, GN->g)))\n        goto end;\n    test_output_bignum("N", GN->N);\n    test_output_bignum("g", GN->g);\n    test_output_bignum("Salt", s);\n    test_output_bignum("Verifier", v);\n    RAND_bytes(rand_tmp, sizeof(rand_tmp));\n    b = BN_bin2bn(rand_tmp, sizeof(rand_tmp), NULL);\n    if (!TEST_BN_ne_zero(b))\n        goto end;\n    test_output_bignum("b", b);\n    Bpub = SRP_Calc_B(b, GN->N, GN->g, v);\n    test_output_bignum("B", Bpub);\n    if (!TEST_true(SRP_Verify_B_mod_N(Bpub, GN->N)))\n        goto end;\n    RAND_bytes(rand_tmp, sizeof(rand_tmp));\n    a = BN_bin2bn(rand_tmp, sizeof(rand_tmp), NULL);\n    if (!TEST_BN_ne_zero(a))\n        goto end;\n    test_output_bignum("a", a);\n    Apub = SRP_Calc_A(a, GN->N, GN->g);\n    test_output_bignum("A", Apub);\n    if (!TEST_true(SRP_Verify_A_mod_N(Apub, GN->N)))\n        goto end;\n    u = SRP_Calc_u(Apub, Bpub, GN->N);\n    x = SRP_Calc_x(s, username, client_pass);\n    Kclient = SRP_Calc_client_key(GN->N, Bpub, GN->g, x, a, u);\n    test_output_bignum("Client\'s key", Kclient);\n    Kserver = SRP_Calc_server_key(Apub, v, u, b, GN->N);\n    test_output_bignum("Server\'s key", Kserver);\n    if (!TEST_BN_eq(Kclient, Kserver))\n        goto end;\n    ret = 1;\nend:\n    BN_clear_free(Kclient);\n    BN_clear_free(Kserver);\n    BN_clear_free(x);\n    BN_free(u);\n    BN_free(Apub);\n    BN_clear_free(a);\n    BN_free(Bpub);\n    BN_clear_free(b);\n    BN_free(s);\n    BN_clear_free(v);\n    return ret;\n}', 'int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,\n                           BIGNUM **verifier, const BIGNUM *N,\n                           const BIGNUM *g)\n{\n    int result = 0;\n    BIGNUM *x = NULL;\n    BN_CTX *bn_ctx = BN_CTX_new();\n    unsigned char tmp2[MAX_LEN];\n    BIGNUM *salttmp = NULL;\n    if ((user == NULL) ||\n        (pass == NULL) ||\n        (salt == NULL) ||\n        (verifier == NULL) || (N == NULL) || (g == NULL) || (bn_ctx == NULL))\n        goto err;\n    if (*salt == NULL) {\n        if (RAND_bytes(tmp2, SRP_RANDOM_SALT_LEN) <= 0)\n            goto err;\n        salttmp = BN_bin2bn(tmp2, SRP_RANDOM_SALT_LEN, NULL);\n    } else {\n        salttmp = *salt;\n    }\n    x = SRP_Calc_x(salttmp, user, pass);\n    *verifier = BN_new();\n    if (*verifier == NULL)\n        goto err;\n    if (!BN_mod_exp(*verifier, g, x, N, bn_ctx)) {\n        BN_clear_free(*verifier);\n        goto err;\n    }\n    result = 1;\n    *salt = salttmp;\n err:\n    if (salt != NULL && *salt != salttmp)\n        BN_clear_free(salttmp);\n    BN_clear_free(x);\n    BN_CTX_free(bn_ctx);\n    return result;\n}', 'int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,\n               BN_CTX *ctx)\n{\n    int ret;\n    bn_check_top(a);\n    bn_check_top(p);\n    bn_check_top(m);\n#define MONT_MUL_MOD\n#define MONT_EXP_WORD\n#define RECP_MUL_MOD\n#ifdef MONT_MUL_MOD\n    if (BN_is_odd(m)) {\n# ifdef MONT_EXP_WORD\n        if (a->top == 1 && !a->neg\n            && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)) {\n            BN_ULONG A = a->d[0];\n            ret = BN_mod_exp_mont_word(r, A, p, m, ctx, NULL);\n        } else\n# endif\n            ret = BN_mod_exp_mont(r, a, p, m, ctx, NULL);\n    } else\n#endif\n#ifdef RECP_MUL_MOD\n    {\n        ret = BN_mod_exp_recp(r, a, p, m, ctx);\n    }\n#else\n    {\n        ret = BN_mod_exp_simple(r, a, p, m, ctx);\n    }\n#endif\n    bn_check_top(r);\n    return (ret);\n}', 'int BN_is_odd(const BIGNUM *a)\n{\n    return (a->top > 0) && (a->d[0] & 1);\n}', 'int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,\n                    const BIGNUM *m, BN_CTX *ctx)\n{\n    int i, j, bits, ret = 0, wstart, wend, window, wvalue;\n    int start = 1;\n    BIGNUM *aa;\n    BIGNUM *val[TABLE_SIZE];\n    BN_RECP_CTX recp;\n    if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) {\n        BNerr(BN_F_BN_MOD_EXP_RECP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n        return 0;\n    }\n    bits = BN_num_bits(p);\n    if (bits == 0) {\n        if (BN_is_one(m)) {\n            ret = 1;\n            BN_zero(r);\n        } else {\n            ret = BN_one(r);\n        }\n        return ret;\n    }\n    BN_CTX_start(ctx);\n    aa = BN_CTX_get(ctx);\n    val[0] = BN_CTX_get(ctx);\n    if (val[0] == NULL)\n        goto err;\n    BN_RECP_CTX_init(&recp);\n    if (m->neg) {\n        if (!BN_copy(aa, m))\n            goto err;\n        aa->neg = 0;\n        if (BN_RECP_CTX_set(&recp, aa, ctx) <= 0)\n            goto err;\n    } else {\n        if (BN_RECP_CTX_set(&recp, m, ctx) <= 0)\n            goto err;\n    }\n    if (!BN_nnmod(val[0], a, m, ctx))\n        goto err;\n    if (BN_is_zero(val[0])) {\n        BN_zero(r);\n        ret = 1;\n        goto err;\n    }\n    window = BN_window_bits_for_exponent_size(bits);\n    if (window > 1) {\n        if (!BN_mod_mul_reciprocal(aa, val[0], val[0], &recp, ctx))\n            goto err;\n        j = 1 << (window - 1);\n        for (i = 1; i < j; i++) {\n            if (((val[i] = BN_CTX_get(ctx)) == NULL) ||\n                !BN_mod_mul_reciprocal(val[i], val[i - 1], aa, &recp, ctx))\n                goto err;\n        }\n    }\n    start = 1;\n    wvalue = 0;\n    wstart = bits - 1;\n    wend = 0;\n    if (!BN_one(r))\n        goto err;\n    for (;;) {\n        if (BN_is_bit_set(p, wstart) == 0) {\n            if (!start)\n                if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n                    goto err;\n            if (wstart == 0)\n                break;\n            wstart--;\n            continue;\n        }\n        j = wstart;\n        wvalue = 1;\n        wend = 0;\n        for (i = 1; i < window; i++) {\n            if (wstart - i < 0)\n                break;\n            if (BN_is_bit_set(p, wstart - i)) {\n                wvalue <<= (i - wend);\n                wvalue |= 1;\n                wend = i;\n            }\n        }\n        j = wend + 1;\n        if (!start)\n            for (i = 0; i < j; i++) {\n                if (!BN_mod_mul_reciprocal(r, r, r, &recp, ctx))\n                    goto err;\n            }\n        if (!BN_mod_mul_reciprocal(r, r, val[wvalue >> 1], &recp, ctx))\n            goto err;\n        wstart -= wend + 1;\n        wvalue = 0;\n        start = 0;\n        if (wstart < 0)\n            break;\n    }\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    BN_RECP_CTX_free(&recp);\n    bn_check_top(r);\n    return (ret);\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n    bn_check_top(b);\n    if (a == b)\n        return a;\n    if (bn_wexpand(a, b->top) == NULL)\n        return NULL;\n    if (b->top > 0)\n        memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n    if (BN_get_flags(b, BN_FLG_CONSTTIME) != 0)\n        BN_set_flags(a, BN_FLG_CONSTTIME);\n    a->top = b->top;\n    a->neg = b->neg;\n    bn_check_top(a);\n    return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']