apps/s_client.c:244: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 67108856] by call to `BN_mod_exp`.
Showing all 28 steps of the trace


apps/s_client.c:231:1: Parameter `N->top`
229.   # define SRP_NUMBER_ITERATIONS_FOR_PRIME 64
230.   
231. > static int srp_Verify_N_and_g(const BIGNUM *N, const BIGNUM *g)
232.   {
233.       BN_CTX *bn_ctx = BN_CTX_new();

apps/s_client.c:237:53: Call
235.       BIGNUM *r = BN_new();
236.       int ret =
237.           g != NULL && N != NULL && bn_ctx != NULL && BN_is_odd(N) &&
                                                           ^
238.           BN_is_prime_ex(N, SRP_NUMBER_ITERATIONS_FOR_PRIME, bn_ctx, NULL) == 1 &&
239.           p != NULL && BN_rshift1(p, N) &&

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

apps/s_client.c:238:9: Call
236.       int ret =
237.           g != NULL && N != NULL && bn_ctx != NULL && BN_is_odd(N) &&
238.           BN_is_prime_ex(N, SRP_NUMBER_ITERATIONS_FOR_PRIME, bn_ctx, NULL) == 1 &&
               ^
239.           p != NULL && BN_rshift1(p, N) &&
240.           /* p = (N-1)/2 */

crypto/bn/bn_prime.c:147:1: Parameter `a->top`
  145.   }
  146.   
  147. > int BN_is_prime_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,
  148.                      BN_GENCB *cb)
  149.   {

crypto/bn/bn_prime.c:150:12: Call
  148.                      BN_GENCB *cb)
  149.   {
  150.       return BN_is_prime_fasttest_ex(a, checks, ctx_passed, 0, cb);
                    ^
  151.   }
  152.   

crypto/bn/bn_prime.c:153:1: Parameter `a->top`
    151.   }
    152.   
    153. > int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,
    154.                               int do_trial_division, BN_GENCB *cb)
    155.   {

crypto/bn/bn_prime.c:162:9: Call
    160.       BN_MONT_CTX *mont = NULL;
    161.   
    162.       if (BN_cmp(a, BN_value_one()) <= 0)
                   ^
    163.           return 0;
    164.   

crypto/bn/bn_lib.c:577:1: Parameter `a->top`
      575.   }
      576.   
      577. > int BN_cmp(const BIGNUM *a, const BIGNUM *b)
      578.   {
      579.       int i;

apps/s_client.c:239:22: Call
237.           g != NULL && N != NULL && bn_ctx != NULL && BN_is_odd(N) &&
238.           BN_is_prime_ex(N, SRP_NUMBER_ITERATIONS_FOR_PRIME, bn_ctx, NULL) == 1 &&
239.           p != NULL && BN_rshift1(p, N) &&
                            ^
240.           /* p = (N-1)/2 */
241.           BN_is_prime_ex(p, SRP_NUMBER_ITERATIONS_FOR_PRIME, bn_ctx, NULL) == 1 &&

crypto/bn/bn_shift.c:54:9: Call
  52.       bn_check_top(a);
  53.   
  54.       if (BN_is_zero(a)) {
                ^
  55.           BN_zero(r);
  56.           return (1);

crypto/bn/bn_lib.c:852:1: Parameter `a->top`
    850.   }
    851.   
    852. > int BN_is_zero(const BIGNUM *a)
    853.   {
    854.       return a->top == 0;

apps/s_client.c:244:9: Call
242.           r != NULL &&
243.           /* verify g^((N-1)/2) == -1 (mod N) */
244.           BN_mod_exp(r, g, p, N, bn_ctx) &&
               ^
245.           BN_add_word(r, 1) && BN_cmp(r, N) == 0;
246.   

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

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

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

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

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

crypto/bn/bn_exp.c:204:13: Call
    202.               goto err;
    203.       } else {
    204.           if (BN_RECP_CTX_set(&recp, m, ctx) <= 0)
                       ^
    205.               goto err;
    206.       }

crypto/bn/bn_recp.c:44:1: Parameter `d->top`
      42.   }
      43.   
      44. > int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx)
      45.   {
      46.       if (!BN_copy(&(recp->N), d))

crypto/bn/bn_recp.c:46:10: Call
      44.   int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx)
      45.   {
      46.       if (!BN_copy(&(recp->N), d))
                     ^
      47.           return 0;
      48.       BN_zero(&(recp->Nr));

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:948:1: Parameter `*a->d`
          946.   }
          947.   
          948. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
          949.   {
          950.       return (words <= a->dmax) ? a : bn_expand2(a, words);

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

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);
    a->top = b->top;
    a->neg = b->neg;
    bn_check_top(a);
    return a;
}
['static int srp_Verify_N_and_g(const BIGNUM *N, const BIGNUM *g)\n{\n    BN_CTX *bn_ctx = BN_CTX_new();\n    BIGNUM *p = BN_new();\n    BIGNUM *r = BN_new();\n    int ret =\n        g != NULL && N != NULL && bn_ctx != NULL && BN_is_odd(N) &&\n        BN_is_prime_ex(N, SRP_NUMBER_ITERATIONS_FOR_PRIME, bn_ctx, NULL) == 1 &&\n        p != NULL && BN_rshift1(p, N) &&\n        BN_is_prime_ex(p, SRP_NUMBER_ITERATIONS_FOR_PRIME, bn_ctx, NULL) == 1 &&\n        r != NULL &&\n        BN_mod_exp(r, g, p, N, bn_ctx) &&\n        BN_add_word(r, 1) && BN_cmp(r, N) == 0;\n    BN_free(r);\n    BN_free(p);\n    BN_CTX_free(bn_ctx);\n    return ret;\n}', 'int BN_is_odd(const BIGNUM *a)\n{\n    return (a->top > 0) && (a->d[0] & 1);\n}', 'int BN_is_prime_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,\n                   BN_GENCB *cb)\n{\n    return BN_is_prime_fasttest_ex(a, checks, ctx_passed, 0, cb);\n}', 'int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,\n                            int do_trial_division, BN_GENCB *cb)\n{\n    int i, j, ret = -1;\n    int k;\n    BN_CTX *ctx = NULL;\n    BIGNUM *A1, *A1_odd, *check;\n    BN_MONT_CTX *mont = NULL;\n    if (BN_cmp(a, BN_value_one()) <= 0)\n        return 0;\n    if (checks == BN_prime_checks)\n        checks = BN_prime_checks_for_size(BN_num_bits(a));\n    if (!BN_is_odd(a))\n        return BN_is_word(a, 2);\n    if (do_trial_division) {\n        for (i = 1; i < NUMPRIMES; i++) {\n            BN_ULONG mod = BN_mod_word(a, primes[i]);\n            if (mod == (BN_ULONG)-1)\n                goto err;\n            if (mod == 0)\n                return BN_is_word(a, primes[i]);\n        }\n        if (!BN_GENCB_call(cb, 1, -1))\n            goto err;\n    }\n    if (ctx_passed != NULL)\n        ctx = ctx_passed;\n    else if ((ctx = BN_CTX_new()) == NULL)\n        goto err;\n    BN_CTX_start(ctx);\n    A1 = BN_CTX_get(ctx);\n    A1_odd = BN_CTX_get(ctx);\n    check = BN_CTX_get(ctx);\n    if (check == NULL)\n        goto err;\n    if (!BN_copy(A1, a))\n        goto err;\n    if (!BN_sub_word(A1, 1))\n        goto err;\n    if (BN_is_zero(A1)) {\n        ret = 0;\n        goto err;\n    }\n    k = 1;\n    while (!BN_is_bit_set(A1, k))\n        k++;\n    if (!BN_rshift(A1_odd, A1, k))\n        goto err;\n    mont = BN_MONT_CTX_new();\n    if (mont == NULL)\n        goto err;\n    if (!BN_MONT_CTX_set(mont, a, ctx))\n        goto err;\n    for (i = 0; i < checks; i++) {\n        if (!BN_pseudo_rand_range(check, A1))\n            goto err;\n        if (!BN_add_word(check, 1))\n            goto err;\n        j = witness(check, a, A1, A1_odd, k, ctx, mont);\n        if (j == -1)\n            goto err;\n        if (j) {\n            ret = 0;\n            goto err;\n        }\n        if (!BN_GENCB_call(cb, 1, i))\n            goto err;\n    }\n    ret = 1;\n err:\n    if (ctx != NULL) {\n        BN_CTX_end(ctx);\n        if (ctx_passed == NULL)\n            BN_CTX_free(ctx);\n    }\n    BN_MONT_CTX_free(mont);\n    return (ret);\n}', 'int BN_cmp(const BIGNUM *a, const BIGNUM *b)\n{\n    int i;\n    int gt, lt;\n    BN_ULONG t1, t2;\n    if ((a == NULL) || (b == NULL)) {\n        if (a != NULL)\n            return (-1);\n        else if (b != NULL)\n            return (1);\n        else\n            return (0);\n    }\n    bn_check_top(a);\n    bn_check_top(b);\n    if (a->neg != b->neg) {\n        if (a->neg)\n            return (-1);\n        else\n            return (1);\n    }\n    if (a->neg == 0) {\n        gt = 1;\n        lt = -1;\n    } else {\n        gt = -1;\n        lt = 1;\n    }\n    if (a->top > b->top)\n        return (gt);\n    if (a->top < b->top)\n        return (lt);\n    for (i = a->top - 1; i >= 0; i--) {\n        t1 = a->d[i];\n        t2 = b->d[i];\n        if (t1 > t2)\n            return (gt);\n        if (t1 < t2)\n            return (lt);\n    }\n    return (0);\n}', 'int BN_rshift1(BIGNUM *r, const BIGNUM *a)\n{\n    BN_ULONG *ap, *rp, t, c;\n    int i, j;\n    bn_check_top(r);\n    bn_check_top(a);\n    if (BN_is_zero(a)) {\n        BN_zero(r);\n        return (1);\n    }\n    i = a->top;\n    ap = a->d;\n    j = i - (ap[i - 1] == 1);\n    if (a != r) {\n        if (bn_wexpand(r, j) == NULL)\n            return (0);\n        r->neg = a->neg;\n    }\n    rp = r->d;\n    t = ap[--i];\n    c = (t & 1) ? BN_TBIT : 0;\n    if (t >>= 1)\n        rp[i] = t;\n    while (i > 0) {\n        t = ap[--i];\n        rp[i] = ((t >> 1) & BN_MASK2) | c;\n        c = (t & 1) ? BN_TBIT : 0;\n    }\n    r->top = j;\n    if (!r->top)\n        r->neg = 0;\n    bn_check_top(r);\n    return (1);\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n    return a->top == 0;\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_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 (!aa || !val[0])\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}', 'int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx)\n{\n    if (!BN_copy(&(recp->N), d))\n        return 0;\n    BN_zero(&(recp->Nr));\n    recp->num_bits = BN_num_bits(d);\n    recp->shift = 0;\n    return (1);\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    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}']