ssl/statem/statem_clnt.c:1423: error: BUFFER_OVERRUN_L3
  Offset: [3, +oo] (⇐ [0, +oo] + 3) Size: [0, 8388607] by call to `BN_bin2bn`.
Showing all 13 steps of the trace


ssl/statem/statem_clnt.c:1422:9: Call
1420.       }
1421.   
1422.       p = BN_bin2bn(PACKET_data(&prime), PACKET_remaining(&prime), NULL);
                ^
1423.       g = BN_bin2bn(PACKET_data(&generator), PACKET_remaining(&generator),
1424.                     NULL);

crypto/bn/bn_lib.c:475:1: Parameter `*ret->d`
  473.   }
  474.   
  475. > BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
  476.   {
  477.       unsigned int i, m;

ssl/statem/statem_clnt.c:1423:9: Call
1421.   
1422.       p = BN_bin2bn(PACKET_data(&prime), PACKET_remaining(&prime), NULL);
1423.       g = BN_bin2bn(PACKET_data(&generator), PACKET_remaining(&generator),
                ^
1424.                     NULL);
1425.       bnpub_key = BN_bin2bn(PACKET_data(&pub_key), PACKET_remaining(&pub_key),

crypto/bn/bn_lib.c:475:1: Parameter `*ret->d`
  473.   }
  474.   
  475. > BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
  476.   {
  477.       unsigned int i, m;

crypto/bn/bn_lib.c:497:9: Call
  495.       i = ((n - 1) / BN_BYTES) + 1;
  496.       m = ((n - 1) % (BN_BYTES));
  497.       if (bn_wexpand(ret, (int)i) == NULL) {
                 ^
  498.           BN_free(bn);
  499.           return NULL;

crypto/bn/bn_lib.c:1016:1: Parameter `*a->d`
    1014.   }
    1015.   
    1016. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
    1017.   {
    1018.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:1018:37: Call
    1016.   BIGNUM *bn_wexpand(BIGNUM *a, int words)
    1017.   {
    1018.       return (words <= a->dmax) ? a : bn_expand2(a, words);
                                                ^
    1019.   }
    1020.   

crypto/bn/bn_lib.c:323:1: Parameter `*b->d`
      321.    */
      322.   
      323. > BIGNUM *bn_expand2(BIGNUM *b, int words)
      324.   {
      325.       bn_check_top(b);

crypto/bn/bn_lib.c:328:23: Call
      326.   
      327.       if (words > b->dmax) {
      328.           BN_ULONG *a = bn_expand_internal(b, words);
                                   ^
      329.           if (!a)
      330.               return NULL;

crypto/bn/bn_lib.c:246:1: <Length trace>
244.   /* This is used by bn_expand2() */
245.   /* The caller MUST check that words > b->dmax before calling this */
246. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
247.   {
248.       BN_ULONG *A, *a = NULL;

crypto/bn/bn_lib.c:246:1: Parameter `*b->d`
        244.   /* This is used by bn_expand2() */
        245.   /* The caller MUST check that words > b->dmax before calling this */
        246. > static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
        247.   {
        248.       BN_ULONG *A, *a = NULL;

crypto/bn/bn_lib.c:272:5: Assignment
        270.   
        271.   #if 1
        272.       B = b->d;
                   ^
        273.       /* Check if the previous number needs to be copied */
        274.       if (B != NULL) {

crypto/bn/bn_lib.c:289:18: Array access: Offset: [3, +oo] (⇐ [0, +oo] + 3) Size: [0, 8388607] by call to `BN_bin2bn` 
        287.               a1 = B[1];
        288.               a2 = B[2];
        289.               a3 = B[3];
                                ^
        290.               A[0] = a0;
        291.               A[1] = a1;

static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
{
    BN_ULONG *A, *a = NULL;
    const BN_ULONG *B;
    int i;
    bn_check_top(b);
    if (words > (INT_MAX / (4 * BN_BITS2))) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);
        return NULL;
    }
    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
        return (NULL);
    }
    if (BN_get_flags(b,BN_FLG_SECURE))
        a = A = OPENSSL_secure_zalloc(words * sizeof(*a));
    else
        a = A = OPENSSL_zalloc(words * sizeof(*a));
    if (A == NULL) {
        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);
        return (NULL);
    }
#if 1
    B = b->d;
    if (B != NULL) {
        for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {
            BN_ULONG a0, a1, a2, a3;
            a0 = B[0];
            a1 = B[1];
            a2 = B[2];
            a3 = B[3];
            A[0] = a0;
            A[1] = a1;
            A[2] = a2;
            A[3] = a3;
        }
        switch (b->top & 3) {
        case 3:
            A[2] = B[2];
        case 2:
            A[1] = B[1];
        case 1:
            A[0] = B[0];
        case 0:
            ;
        }
    }
#else
    memset(A, 0, sizeof(*A) * words);
    memcpy(A, b->d, sizeof(b->d[0]) * b->top);
#endif
    return (a);
}
['static int tls_process_ske_dhe(SSL *s, PACKET *pkt, EVP_PKEY **pkey, int *al)\n{\n#ifndef OPENSSL_NO_DH\n    PACKET prime, generator, pub_key;\n    EVP_PKEY *peer_tmp = NULL;\n    DH *dh = NULL;\n    BIGNUM *p = NULL, *g = NULL, *bnpub_key = NULL;\n    if (!PACKET_get_length_prefixed_2(pkt, &prime)\n        || !PACKET_get_length_prefixed_2(pkt, &generator)\n        || !PACKET_get_length_prefixed_2(pkt, &pub_key)) {\n        *al = SSL_AD_DECODE_ERROR;\n        SSLerr(SSL_F_TLS_PROCESS_SKE_DHE, SSL_R_LENGTH_MISMATCH);\n        return 0;\n    }\n    peer_tmp = EVP_PKEY_new();\n    dh = DH_new();\n    if (peer_tmp == NULL || dh == NULL) {\n        *al = SSL_AD_INTERNAL_ERROR;\n        SSLerr(SSL_F_TLS_PROCESS_SKE_DHE, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    p = BN_bin2bn(PACKET_data(&prime), PACKET_remaining(&prime), NULL);\n    g = BN_bin2bn(PACKET_data(&generator), PACKET_remaining(&generator),\n                  NULL);\n    bnpub_key = BN_bin2bn(PACKET_data(&pub_key), PACKET_remaining(&pub_key),\n                          NULL);\n    if (p == NULL || g == NULL || bnpub_key == NULL) {\n        *al = SSL_AD_INTERNAL_ERROR;\n        SSLerr(SSL_F_TLS_PROCESS_SKE_DHE, ERR_R_BN_LIB);\n        goto err;\n    }\n    if (BN_is_zero(p) || BN_is_zero(g) || BN_is_zero(bnpub_key)) {\n        *al = SSL_AD_DECODE_ERROR;\n        SSLerr(SSL_F_TLS_PROCESS_SKE_DHE, SSL_R_BAD_DH_VALUE);\n        goto err;\n    }\n    if (!DH_set0_pqg(dh, p, NULL, g)) {\n        *al = SSL_AD_INTERNAL_ERROR;\n        SSLerr(SSL_F_TLS_PROCESS_SKE_DHE, ERR_R_BN_LIB);\n        goto err;\n    }\n    p = g = NULL;\n    if (!DH_set0_key(dh, bnpub_key, NULL)) {\n        *al = SSL_AD_INTERNAL_ERROR;\n        SSLerr(SSL_F_TLS_PROCESS_SKE_DHE, ERR_R_BN_LIB);\n        goto err;\n    }\n    bnpub_key = NULL;\n    if (!ssl_security(s, SSL_SECOP_TMP_DH, DH_security_bits(dh), 0, dh)) {\n        *al = SSL_AD_HANDSHAKE_FAILURE;\n        SSLerr(SSL_F_TLS_PROCESS_SKE_DHE, SSL_R_DH_KEY_TOO_SMALL);\n        goto err;\n    }\n    if (EVP_PKEY_assign_DH(peer_tmp, dh) == 0) {\n        *al = SSL_AD_INTERNAL_ERROR;\n        SSLerr(SSL_F_TLS_PROCESS_SKE_DHE, ERR_R_EVP_LIB);\n        goto err;\n    }\n    s->s3->peer_tmp = peer_tmp;\n    if (s->s3->tmp.new_cipher->algorithm_auth & (SSL_aRSA|SSL_aDSS))\n        *pkey = X509_get0_pubkey(s->session->peer);\n    return 1;\n err:\n    BN_free(p);\n    BN_free(g);\n    BN_free(bnpub_key);\n    DH_free(dh);\n    EVP_PKEY_free(peer_tmp);\n    return 0;\n#else\n    SSLerr(SSL_F_TLS_PROCESS_SKE_DHE, ERR_R_INTERNAL_ERROR);\n    *al = SSL_AD_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}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\n}', 'BIGNUM *bn_expand2(BIGNUM *b, int words)\n{\n    bn_check_top(b);\n    if (words > b->dmax) {\n        BN_ULONG *a = bn_expand_internal(b, words);\n        if (!a)\n            return NULL;\n        if (b->d) {\n            OPENSSL_cleanse(b->d, b->dmax * sizeof(b->d[0]));\n            bn_free_d(b);\n        }\n        b->d = a;\n        b->dmax = words;\n    }\n    bn_check_top(b);\n    return b;\n}', 'static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)\n{\n    BN_ULONG *A, *a = NULL;\n    const BN_ULONG *B;\n    int i;\n    bn_check_top(b);\n    if (words > (INT_MAX / (4 * BN_BITS2))) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_BIGNUM_TOO_LONG);\n        return NULL;\n    }\n    if (BN_get_flags(b, BN_FLG_STATIC_DATA)) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);\n        return (NULL);\n    }\n    if (BN_get_flags(b,BN_FLG_SECURE))\n        a = A = OPENSSL_secure_zalloc(words * sizeof(*a));\n    else\n        a = A = OPENSSL_zalloc(words * sizeof(*a));\n    if (A == NULL) {\n        BNerr(BN_F_BN_EXPAND_INTERNAL, ERR_R_MALLOC_FAILURE);\n        return (NULL);\n    }\n#if 1\n    B = b->d;\n    if (B != NULL) {\n        for (i = b->top >> 2; i > 0; i--, A += 4, B += 4) {\n            BN_ULONG a0, a1, a2, a3;\n            a0 = B[0];\n            a1 = B[1];\n            a2 = B[2];\n            a3 = B[3];\n            A[0] = a0;\n            A[1] = a1;\n            A[2] = a2;\n            A[3] = a3;\n        }\n        switch (b->top & 3) {\n        case 3:\n            A[2] = B[2];\n        case 2:\n            A[1] = B[1];\n        case 1:\n            A[0] = B[0];\n        case 0:\n            ;\n        }\n    }\n#else\n    memset(A, 0, sizeof(*A) * words);\n    memcpy(A, b->d, sizeof(b->d[0]) * b->top);\n#endif\n    return (a);\n}']