ssl/statem/statem_srvr.c:3257: error: BUFFER_OVERRUN_L3
  Offset: [16, +oo] (⇐ 1 + [15, +oo]) Size: [0, 8388607] by call to `srp_generate_server_master_secret`.
Showing all 31 steps of the trace


ssl/statem/statem_srvr.c:3239:25: Call
3237.           return 0;
3238.       }
3239.       if ((s->srp_ctx.A = BN_bin2bn(data, i, NULL)) == NULL) {
                                ^
3240.           SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CKE_SRP,
3241.                    ERR_R_BN_LIB);

crypto/bn/bn_lib.c:389:9: Assignment
  387.       n = len;
  388.       if (n == 0) {
  389.           ret->top = 0;
                 ^
  390.           return ret;
  391.       }

ssl/statem/statem_srvr.c:3257:10: Call
3255.       }
3256.   
3257.       if (!srp_generate_server_master_secret(s)) {
                 ^
3258.           /* SSLfatal() already called */
3259.           return 0;

ssl/tls_srp.c:249:1: Parameter `s->srp_ctx.A->top`
  247.   }
  248.   
  249. > int srp_generate_server_master_secret(SSL *s)
  250.   {
  251.       BIGNUM *K = NULL, *u = NULL;

ssl/tls_srp.c:255:10: Call
  253.       unsigned char *tmp = NULL;
  254.   
  255.       if (!SRP_Verify_A_mod_N(s->srp_ctx.A, s->srp_ctx.N))
                  ^
  256.           goto err;
  257.       if ((u = SRP_Calc_u(s->srp_ctx.A, s->srp_ctx.B, s->srp_ctx.N)) == NULL)

crypto/srp/srp_lib.c:237:1: Parameter `A->top`
    235.   }
    236.   
    237. > int SRP_Verify_A_mod_N(const BIGNUM *A, const BIGNUM *N)
    238.   {
    239.       /* Checks if A % N == 0 */

crypto/srp/srp_lib.c:240:12: Call
    238.   {
    239.       /* Checks if A % N == 0 */
    240.       return SRP_Verify_B_mod_N(A, N);
                      ^
    241.   }
    242.   

crypto/srp/srp_lib.c:216:1: Parameter `B->top`
      214.   }
      215.   
      216. > int SRP_Verify_B_mod_N(const BIGNUM *B, const BIGNUM *N)
      217.   {
      218.       BIGNUM *r;

ssl/tls_srp.c:257:14: Call
  255.       if (!SRP_Verify_A_mod_N(s->srp_ctx.A, s->srp_ctx.N))
  256.           goto err;
  257.       if ((u = SRP_Calc_u(s->srp_ctx.A, s->srp_ctx.B, s->srp_ctx.N)) == NULL)
                      ^
  258.           goto err;
  259.       if ((K = SRP_Calc_server_key(s->srp_ctx.A, s->srp_ctx.v, u, s->srp_ctx.b,

crypto/srp/srp_lib.c:51:1: Parameter `A->top`
    49.   }
    50.   
    51. > BIGNUM *SRP_Calc_u(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N)
    52.   {
    53.       /* k = SHA1(PAD(A) || PAD(B) ) -- tls-srp draft 8 */

crypto/srp/srp_lib.c:54:12: Call
    52.   {
    53.       /* k = SHA1(PAD(A) || PAD(B) ) -- tls-srp draft 8 */
    54.       return srp_Calc_xy(A, B, N);
                     ^
    55.   }
    56.   

crypto/srp/srp_lib.c:23:1: Parameter `x->top`
      21.   /* calculate = SHA1(PAD(x) || PAD(y)) */
      22.   
      23. > static BIGNUM *srp_Calc_xy(const BIGNUM *x, const BIGNUM *y, const BIGNUM *N)
      24.   {
      25.       unsigned char digest[SHA_DIGEST_LENGTH];

ssl/tls_srp.c:259:14: Call
  257.       if ((u = SRP_Calc_u(s->srp_ctx.A, s->srp_ctx.B, s->srp_ctx.N)) == NULL)
  258.           goto err;
  259.       if ((K = SRP_Calc_server_key(s->srp_ctx.A, s->srp_ctx.v, u, s->srp_ctx.b,
                      ^
  260.                                    s->srp_ctx.N)) == NULL)
  261.           goto err;

crypto/srp/srp_lib.c:57:1: Parameter `A->top`
    55.   }
    56.   
    57. > BIGNUM *SRP_Calc_server_key(const BIGNUM *A, const BIGNUM *v, const BIGNUM *u,
    58.                               const BIGNUM *b, const BIGNUM *N)
    59.   {

crypto/srp/srp_lib.c:73:10: Call
    71.       if (!BN_mod_exp(tmp, v, u, N, bn_ctx))
    72.           goto err;
    73.       if (!BN_mod_mul(tmp, A, tmp, N, bn_ctx))
                   ^
    74.           goto err;
    75.   

crypto/bn/bn_mod.c:193:1: Parameter `a->top`
      191.   
      192.   /* slow but works */
      193. > int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
      194.                  BN_CTX *ctx)
      195.   {

crypto/bn/bn_mod.c:207:14: Call
      205.           goto err;
      206.       if (a == b) {
      207.           if (!BN_sqr(t, a, ctx))
                          ^
      208.               goto err;
      209.       } else {

crypto/bn/bn_sqr.c:17:1: Parameter `*r->d`
        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 ret = bn_sqr_fixed_top(r, a, ctx);

crypto/bn/bn_sqr.c:19:15: Call
        17.   int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
        18.   {
        19.       int ret = bn_sqr_fixed_top(r, a, ctx);
                            ^
        20.   
        21.       bn_correct_top(r);

crypto/bn/bn_sqr.c:27:1: Parameter `a->top`
          25.   }
          26.   
          27. > int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
          28.   {
          29.       int max, al;

crypto/bn/bn_sqr.c:35:5: Assignment
          33.       bn_check_top(a);
          34.   
          35.       al = a->top;
                    ^
          36.       if (al <= 0) {
          37.           r->top = 0;

crypto/bn/bn_sqr.c:84:17: Call
          82.                   if (bn_wexpand(tmp, max) == NULL)
          83.                       goto err;
          84.                   bn_sqr_normal(rr->d, a->d, al, tmp->d);
                                ^
          85.               }
          86.           }

crypto/bn/bn_sqr.c:109:1: <Offset trace>
107.   
108.   /* tmp must have 2*n words */
109. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
110.   {
111.       int i, j, max;

crypto/bn/bn_sqr.c:109:1: Parameter `n`
            107.   
            108.   /* tmp must have 2*n words */
            109. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
            110.   {
            111.       int i, j, max;

crypto/bn/bn_sqr.c:120:5: Assignment
            118.       rp[0] = rp[max - 1] = 0;
            119.       rp++;
            120.       j = n;
                       ^
            121.   
            122.       if (--j > 0) {

crypto/bn/bn_sqr.c:122:9: Assignment
            120.       j = n;
            121.   
            122.       if (--j > 0) {
                           ^
            123.           ap++;
            124.           rp[j] = bn_mul_words(rp, ap, j, ap[-1]);

crypto/bn/bn_sqr.c:109:1: <Length trace>
107.   
108.   /* tmp must have 2*n words */
109. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
110.   {
111.       int i, j, max;

crypto/bn/bn_sqr.c:109:1: Parameter `*r`
            107.   
            108.   /* tmp must have 2*n words */
            109. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
            110.   {
            111.       int i, j, max;

crypto/bn/bn_sqr.c:117:5: Assignment
            115.       max = n * 2;
            116.       ap = a;
            117.       rp = r;
                       ^
            118.       rp[0] = rp[max - 1] = 0;
            119.       rp++;

crypto/bn/bn_sqr.c:119:5: Assignment
            117.       rp = r;
            118.       rp[0] = rp[max - 1] = 0;
            119.       rp++;
                       ^
            120.       j = n;
            121.   

crypto/bn/bn_sqr.c:124:9: Array access: Offset: [16, +oo] (⇐ 1 + [15, +oo]) Size: [0, 8388607] by call to `srp_generate_server_master_secret` 
            122.       if (--j > 0) {
            123.           ap++;
            124.           rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
                           ^
            125.           rp += 2;
            126.       }

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);
}
['static int tls_process_cke_srp(SSL *s, PACKET *pkt)\n{\n#ifndef OPENSSL_NO_SRP\n    unsigned int i;\n    const unsigned char *data;\n    if (!PACKET_get_net_2(pkt, &i)\n        || !PACKET_get_bytes(pkt, &data, i)) {\n        SSLfatal(s, SSL_AD_DECODE_ERROR, SSL_F_TLS_PROCESS_CKE_SRP,\n                 SSL_R_BAD_SRP_A_LENGTH);\n        return 0;\n    }\n    if ((s->srp_ctx.A = BN_bin2bn(data, i, NULL)) == NULL) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CKE_SRP,\n                 ERR_R_BN_LIB);\n        return 0;\n    }\n    if (BN_ucmp(s->srp_ctx.A, s->srp_ctx.N) >= 0 || BN_is_zero(s->srp_ctx.A)) {\n        SSLfatal(s, SSL_AD_ILLEGAL_PARAMETER, SSL_F_TLS_PROCESS_CKE_SRP,\n                 SSL_R_BAD_SRP_PARAMETERS);\n        return 0;\n    }\n    OPENSSL_free(s->session->srp_username);\n    s->session->srp_username = OPENSSL_strdup(s->srp_ctx.login);\n    if (s->session->srp_username == NULL) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CKE_SRP,\n                 ERR_R_MALLOC_FAILURE);\n        return 0;\n    }\n    if (!srp_generate_server_master_secret(s)) {\n        return 0;\n    }\n    return 1;\n#else\n    SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_PROCESS_CKE_SRP,\n             ERR_R_INTERNAL_ERROR);\n    return 0;\n#endif\n}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n    unsigned int i, m;\n    unsigned int n;\n    BN_ULONG l;\n    BIGNUM *bn = NULL;\n    if (ret == NULL)\n        ret = bn = BN_new();\n    if (ret == NULL)\n        return NULL;\n    bn_check_top(ret);\n    for ( ; len > 0 && *s == 0; s++, len--)\n        continue;\n    n = len;\n    if (n == 0) {\n        ret->top = 0;\n        return ret;\n    }\n    i = ((n - 1) / BN_BYTES) + 1;\n    m = ((n - 1) % (BN_BYTES));\n    if (bn_wexpand(ret, (int)i) == NULL) {\n        BN_free(bn);\n        return NULL;\n    }\n    ret->top = i;\n    ret->neg = 0;\n    l = 0;\n    while (n--) {\n        l = (l << 8L) | *(s++);\n        if (m-- == 0) {\n            ret->d[--i] = l;\n            l = 0;\n            m = BN_BYTES - 1;\n        }\n    }\n    bn_correct_top(ret);\n    return ret;\n}', '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        SSLfatal(s, SSL_AD_INTERNAL_ERROR,\n                 SSL_F_SRP_GENERATE_SERVER_MASTER_SECRET, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\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(const BIGNUM *A, const BIGNUM *N)\n{\n    return SRP_Verify_B_mod_N(A, N);\n}', 'int SRP_Verify_B_mod_N(const BIGNUM *B, const 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(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N)\n{\n    return srp_Calc_xy(A, B, N);\n}', 'static BIGNUM *srp_Calc_xy(const BIGNUM *x, const BIGNUM *y, const BIGNUM *N)\n{\n    unsigned char digest[SHA_DIGEST_LENGTH];\n    unsigned char *tmp = NULL;\n    int numN = BN_num_bytes(N);\n    BIGNUM *res = NULL;\n    if (x != N && BN_ucmp(x, N) >= 0)\n        return NULL;\n    if (y != N && BN_ucmp(y, N) >= 0)\n        return NULL;\n    if ((tmp = OPENSSL_malloc(numN * 2)) == NULL)\n        goto err;\n    if (BN_bn2binpad(x, tmp, numN) < 0\n        || BN_bn2binpad(y, tmp + numN, numN) < 0\n        || !EVP_Digest(tmp, numN * 2, digest, NULL, EVP_sha1(), NULL))\n        goto err;\n    res = BN_bin2bn(digest, sizeof(digest), NULL);\n err:\n    OPENSSL_free(tmp);\n    return res;\n}', 'BIGNUM *SRP_Calc_server_key(const BIGNUM *A, const BIGNUM *v, const BIGNUM *u,\n                            const BIGNUM *b, const 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 ret = bn_sqr_fixed_top(r, a, ctx);\n    bn_correct_top(r);\n    bn_check_top(r);\n    return ret;\n}', 'int bn_sqr_fixed_top(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 == NULL || tmp == NULL)\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    rr->top = max;\n    rr->flags |= BN_FLG_FIXED_TOP;\n    if (r != rr && BN_copy(r, rr) == NULL)\n        goto err;\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}']