ssl/tls_srp.c:294: error: BUFFER_OVERRUN_L3
  Offset: [31, +oo] Size: [0, 8388607] by call to `SRP_Calc_server_key`.
Showing all 22 steps of the trace


ssl/tls_srp.c:284:1: Parameter `s->srp_ctx.A->top`
282.   }
283.   
284. > int srp_generate_server_master_secret(SSL *s)
285.   {
286.       BIGNUM *K = NULL, *u = NULL;

ssl/tls_srp.c:290:10: Call
288.       unsigned char *tmp = NULL;
289.   
290.       if (!SRP_Verify_A_mod_N(s->srp_ctx.A, s->srp_ctx.N))
                ^
291.           goto err;
292.       if ((u = SRP_Calc_u(s->srp_ctx.A, s->srp_ctx.B, s->srp_ctx.N)) == NULL)

crypto/srp/srp_lib.c:273:1: Parameter `A->top`
  271.   }
  272.   
  273. > int SRP_Verify_A_mod_N(BIGNUM *A, BIGNUM *N)
  274.   {
  275.       /* Checks if A % N == 0 */

crypto/srp/srp_lib.c:276:12: Call
  274.   {
  275.       /* Checks if A % N == 0 */
  276.       return SRP_Verify_B_mod_N(A, N);
                    ^
  277.   }
  278.   

crypto/srp/srp_lib.c:252:1: Parameter `B->top`
    250.   }
    251.   
    252. > int SRP_Verify_B_mod_N(BIGNUM *B, BIGNUM *N)
    253.   {
    254.       BIGNUM *r;

ssl/tls_srp.c:292:14: Call
290.       if (!SRP_Verify_A_mod_N(s->srp_ctx.A, s->srp_ctx.N))
291.           goto err;
292.       if ((u = SRP_Calc_u(s->srp_ctx.A, s->srp_ctx.B, s->srp_ctx.N)) == NULL)
                    ^
293.           goto err;
294.       if ((K = SRP_Calc_server_key(s->srp_ctx.A, s->srp_ctx.v, u, s->srp_ctx.b,

crypto/srp/srp_lib.c:55:1: Parameter `A->top`
  53.   }
  54.   
  55. > BIGNUM *SRP_Calc_u(BIGNUM *A, BIGNUM *B, BIGNUM *N)
  56.   {
  57.       /* k = SHA1(PAD(A) || PAD(B) ) -- tls-srp draft 8 */

ssl/tls_srp.c:294:14: Call
292.       if ((u = SRP_Calc_u(s->srp_ctx.A, s->srp_ctx.B, s->srp_ctx.N)) == NULL)
293.           goto err;
294.       if ((K = SRP_Calc_server_key(s->srp_ctx.A, s->srp_ctx.v, u, s->srp_ctx.b,
                    ^
295.                                    s->srp_ctx.N)) == NULL)
296.           goto err;

crypto/srp/srp_lib.c:98:1: Parameter `A->top`
  96.   }
  97.   
  98. > BIGNUM *SRP_Calc_server_key(BIGNUM *A, BIGNUM *v, BIGNUM *u, BIGNUM *b,
  99.                               BIGNUM *N)
  100.   {

crypto/srp/srp_lib.c:114:10: Call
  112.       if (!BN_mod_exp(tmp, v, u, N, bn_ctx))
  113.           goto err;
  114.       if (!BN_mod_mul(tmp, A, tmp, N, bn_ctx))
                  ^
  115.           goto err;
  116.   

crypto/bn/bn_mod.c:73:1: Parameter `a->top`
    71.   
    72.   /* slow but works */
    73. > int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
    74.                  BN_CTX *ctx)
    75.   {

crypto/bn/bn_mod.c:87:14: Call
    85.           goto err;
    86.       if (a == b) {
    87.           if (!BN_sqr(t, a, ctx))
                       ^
    88.               goto err;
    89.       } else {

crypto/bn/bn_sqr.c:17:1: Parameter `a->top`
      15.    * I've just gone over this and it is now %20 faster on x86 - eay - 27 Jun 96
      16.    */
      17. > int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
      18.   {
      19.       int max, al;

crypto/bn/bn_sqr.c:25:5: Assignment
      23.       bn_check_top(a);
      24.   
      25.       al = a->top;
                ^
      26.       if (al <= 0) {
      27.           r->top = 0;

crypto/bn/bn_sqr.c:74:17: Call
      72.                   if (bn_wexpand(tmp, max) == NULL)
      73.                       goto err;
      74.                   bn_sqr_normal(rr->d, a->d, al, tmp->d);
                            ^
      75.               }
      76.           }

crypto/bn/bn_sqr.c:104:1: <Offset trace>
102.   
103.   /* tmp must have 2*n words */
104. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
105.   {
106.       int i, j, max;

crypto/bn/bn_sqr.c:104:1: Parameter `n`
        102.   
        103.   /* tmp must have 2*n words */
        104. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
        105.   {
        106.       int i, j, max;

crypto/bn/bn_sqr.c:110:5: Assignment
        108.       BN_ULONG *rp;
        109.   
        110.       max = n * 2;
                   ^
        111.       ap = a;
        112.       rp = r;

crypto/bn/bn_sqr.c:104:1: <Length trace>
102.   
103.   /* tmp must have 2*n words */
104. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
105.   {
106.       int i, j, max;

crypto/bn/bn_sqr.c:104:1: Parameter `*r`
        102.   
        103.   /* tmp must have 2*n words */
        104. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
        105.   {
        106.       int i, j, max;

crypto/bn/bn_sqr.c:112:5: Assignment
        110.       max = n * 2;
        111.       ap = a;
        112.       rp = r;
                   ^
        113.       rp[0] = rp[max - 1] = 0;
        114.       rp++;

crypto/bn/bn_sqr.c:113:13: Array access: Offset: [31, +oo] Size: [0, 8388607] by call to `SRP_Calc_server_key` 
        111.       ap = a;
        112.       rp = r;
        113.       rp[0] = rp[max - 1] = 0;
                           ^
        114.       rp++;
        115.       j = n;

void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
{
    int i, j, max;
    const BN_ULONG *ap;
    BN_ULONG *rp;
    max = n * 2;
    ap = a;
    rp = r;
    rp[0] = rp[max - 1] = 0;
    rp++;
    j = n;
    if (--j > 0) {
        ap++;
        rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
        rp += 2;
    }
    for (i = n - 2; i > 0; i--) {
        j--;
        ap++;
        rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);
        rp += 2;
    }
    bn_add_words(r, r, r, max);
    bn_sqr_words(tmp, a, n);
    bn_add_words(r, r, tmp, max);
}
['int srp_generate_server_master_secret(SSL *s)\n{\n    BIGNUM *K = NULL, *u = NULL;\n    int ret = -1, tmp_len = 0;\n    unsigned char *tmp = NULL;\n    if (!SRP_Verify_A_mod_N(s->srp_ctx.A, s->srp_ctx.N))\n        goto err;\n    if ((u = SRP_Calc_u(s->srp_ctx.A, s->srp_ctx.B, s->srp_ctx.N)) == NULL)\n        goto err;\n    if ((K = SRP_Calc_server_key(s->srp_ctx.A, s->srp_ctx.v, u, s->srp_ctx.b,\n                                 s->srp_ctx.N)) == NULL)\n        goto err;\n    tmp_len = BN_num_bytes(K);\n    if ((tmp = OPENSSL_malloc(tmp_len)) == NULL)\n        goto err;\n    BN_bn2bin(K, tmp);\n    ret = ssl_generate_master_secret(s, tmp, tmp_len, 1);\n err:\n    BN_clear_free(K);\n    BN_clear_free(u);\n    return ret;\n}', 'int SRP_Verify_A_mod_N(BIGNUM *A, BIGNUM *N)\n{\n    return SRP_Verify_B_mod_N(A, N);\n}', 'int SRP_Verify_B_mod_N(BIGNUM *B, BIGNUM *N)\n{\n    BIGNUM *r;\n    BN_CTX *bn_ctx;\n    int ret = 0;\n    if (B == NULL || N == NULL || (bn_ctx = BN_CTX_new()) == NULL)\n        return 0;\n    if ((r = BN_new()) == NULL)\n        goto err;\n    if (!BN_nnmod(r, B, N, bn_ctx))\n        goto err;\n    ret = !BN_is_zero(r);\n err:\n    BN_CTX_free(bn_ctx);\n    BN_free(r);\n    return ret;\n}', 'BIGNUM *SRP_Calc_u(BIGNUM *A, BIGNUM *B, BIGNUM *N)\n{\n    BIGNUM *u = NULL;\n    unsigned char cu[SHA_DIGEST_LENGTH];\n    unsigned char *cAB = NULL;\n    EVP_MD_CTX *ctxt = NULL;\n    int longN;\n    if ((A == NULL) || (B == NULL) || (N == NULL))\n        return NULL;\n    if (BN_ucmp(A, N) >= 0 || BN_ucmp(B, N) >= 0)\n        return NULL;\n    longN = BN_num_bytes(N);\n    ctxt = EVP_MD_CTX_new();\n    if (ctxt == NULL)\n        return NULL;\n    if ((cAB = OPENSSL_malloc(2 * longN)) == NULL)\n        goto err;\n    memset(cAB, 0, longN);\n    EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL);\n    EVP_DigestUpdate(ctxt, cAB + BN_bn2bin(A, cAB + longN), longN);\n    EVP_DigestUpdate(ctxt, cAB + BN_bn2bin(B, cAB + longN), longN);\n    OPENSSL_free(cAB);\n    EVP_DigestFinal_ex(ctxt, cu, NULL);\n    if ((u = BN_bin2bn(cu, sizeof(cu), NULL)) == NULL)\n        goto err;\n    if (BN_is_zero(u)) {\n        BN_free(u);\n        u = NULL;\n    }\n err:\n    EVP_MD_CTX_free(ctxt);\n    return u;\n}', 'BIGNUM *SRP_Calc_server_key(BIGNUM *A, BIGNUM *v, BIGNUM *u, BIGNUM *b,\n                            BIGNUM *N)\n{\n    BIGNUM *tmp = NULL, *S = NULL;\n    BN_CTX *bn_ctx;\n    if (u == NULL || A == NULL || v == NULL || b == NULL || N == NULL)\n        return NULL;\n    if ((bn_ctx = BN_CTX_new()) == NULL || (tmp = BN_new()) == NULL)\n        goto err;\n    if (!BN_mod_exp(tmp, v, u, N, bn_ctx))\n        goto err;\n    if (!BN_mod_mul(tmp, A, tmp, N, bn_ctx))\n        goto err;\n    S = BN_new();\n    if (S != NULL && !BN_mod_exp(S, tmp, b, N, bn_ctx)) {\n        BN_free(S);\n        S = NULL;\n    }\n err:\n    BN_CTX_free(bn_ctx);\n    BN_clear_free(tmp);\n    return S;\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_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n    int i, j, max;\n    const BN_ULONG *ap;\n    BN_ULONG *rp;\n    max = n * 2;\n    ap = a;\n    rp = r;\n    rp[0] = rp[max - 1] = 0;\n    rp++;\n    j = n;\n    if (--j > 0) {\n        ap++;\n        rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n        rp += 2;\n    }\n    for (i = n - 2; i > 0; i--) {\n        j--;\n        ap++;\n        rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n        rp += 2;\n    }\n    bn_add_words(r, r, r, max);\n    bn_sqr_words(tmp, a, n);\n    bn_add_words(r, r, tmp, max);\n}']