ssl/statem/extensions_srvr.c:1616: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - [`pkt->written`, `pkt->written` + 19]):unsigned64 by call to `WPACKET_reserve_bytes`.
Showing all 8 steps of the trace


ssl/statem/extensions_srvr.c:1615:17: Call
1613.               || !WPACKET_put_bytes_u8(pkt, s->s3->peer_tmp == NULL)
1614.               || !WPACKET_put_bytes_u32(pkt, (unsigned int)time(NULL))
1615.               || !WPACKET_start_sub_packet_u16(pkt)
                        ^
1616.               || !WPACKET_reserve_bytes(pkt, EVP_MAX_MD_SIZE, &hashval1)) {
1617.           SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_STOC_COOKIE,

ssl/packet.c:270:1: Parameter `pkt->buf->length`
  268.   }
  269.   
  270. > int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)
  271.   {
  272.       WPACKET_SUB *sub;

ssl/statem/extensions_srvr.c:1616:17: Call
1614.               || !WPACKET_put_bytes_u32(pkt, (unsigned int)time(NULL))
1615.               || !WPACKET_start_sub_packet_u16(pkt)
1616.               || !WPACKET_reserve_bytes(pkt, EVP_MAX_MD_SIZE, &hashval1)) {
                        ^
1617.           SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_STOC_COOKIE,
1618.                    ERR_R_INTERNAL_ERROR);

ssl/packet.c:39:1: <LHS trace>
37.                        ? (p)->staticbuf : (unsigned char *)(p)->buf->data)
38.   
39. > int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)
40.   {
41.       /* Internal API, so should not fail */

ssl/packet.c:39:1: Parameter `pkt->buf->length`
  37.                        ? (p)->staticbuf : (unsigned char *)(p)->buf->data)
  38.   
  39. > int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)
  40.   {
  41.       /* Internal API, so should not fail */

ssl/packet.c:39:1: <RHS trace>
37.                        ? (p)->staticbuf : (unsigned char *)(p)->buf->data)
38.   
39. > int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)
40.   {
41.       /* Internal API, so should not fail */

ssl/packet.c:39:1: Parameter `len`
  37.                        ? (p)->staticbuf : (unsigned char *)(p)->buf->data)
  38.   
  39. > int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)
  40.   {
  41.       /* Internal API, so should not fail */

ssl/packet.c:48:36: Binary operation: ([0, +oo] - [pkt->written, pkt->written + 19]):unsigned64 by call to `WPACKET_reserve_bytes` 
  46.           return 0;
  47.   
  48.       if (pkt->staticbuf == NULL && (pkt->buf->length - pkt->written < len)) {
                                           ^
  49.           size_t newlen;
  50.           size_t reflen;

int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)
{
    if (!ossl_assert(pkt->subs != NULL && len != 0))
        return 0;
    if (pkt->maxsize - pkt->written < len)
        return 0;
    if (pkt->staticbuf == NULL && (pkt->buf->length - pkt->written < len)) {
        size_t newlen;
        size_t reflen;
        reflen = (len > pkt->buf->length) ? len : pkt->buf->length;
        if (reflen > SIZE_MAX / 2) {
            newlen = SIZE_MAX;
        } else {
            newlen = reflen * 2;
            if (newlen < DEFAULT_BUF_SIZE)
                newlen = DEFAULT_BUF_SIZE;
        }
        if (BUF_MEM_grow(pkt->buf, newlen) == 0)
            return 0;
    }
    if (allocbytes != NULL)
        *allocbytes = WPACKET_get_curr(pkt);
    return 1;
}
['EXT_RETURN tls_construct_stoc_cookie(SSL *s, WPACKET *pkt, unsigned int context,\n                                     X509 *x, size_t chainidx)\n{\n    unsigned char *hashval1, *hashval2, *appcookie1, *appcookie2, *cookie;\n    unsigned char *hmac, *hmac2;\n    size_t startlen, ciphlen, totcookielen, hashlen, hmaclen;\n    unsigned int appcookielen;\n    EVP_MD_CTX *hctx;\n    EVP_PKEY *pkey;\n    int ret = EXT_RETURN_FAIL;\n    if (s->ctx->app_gen_cookie_cb == NULL\n            || (s->s3->flags & TLS1_FLAGS_STATELESS) == 0)\n        return EXT_RETURN_NOT_SENT;\n    if (!WPACKET_put_bytes_u16(pkt, TLSEXT_TYPE_cookie)\n            || !WPACKET_start_sub_packet_u16(pkt)\n            || !WPACKET_start_sub_packet_u16(pkt)\n            || !WPACKET_get_total_written(pkt, &startlen)\n            || !WPACKET_reserve_bytes(pkt, MAX_COOKIE_SIZE, &cookie)\n            || !WPACKET_put_bytes_u16(pkt, COOKIE_STATE_FORMAT_VERSION)\n            || !WPACKET_put_bytes_u16(pkt, TLS1_3_VERSION)\n            || !WPACKET_put_bytes_u16(pkt, s->s3->group_id)\n            || !s->method->put_cipher_by_char(s->s3->tmp.new_cipher, pkt,\n                                              &ciphlen)\n            || !WPACKET_put_bytes_u8(pkt, s->s3->peer_tmp == NULL)\n            || !WPACKET_put_bytes_u32(pkt, (unsigned int)time(NULL))\n            || !WPACKET_start_sub_packet_u16(pkt)\n            || !WPACKET_reserve_bytes(pkt, EVP_MAX_MD_SIZE, &hashval1)) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_STOC_COOKIE,\n                 ERR_R_INTERNAL_ERROR);\n        return EXT_RETURN_FAIL;\n    }\n    if (!ssl3_digest_cached_records(s, 0)\n            || !ssl_handshake_hash(s, hashval1, EVP_MAX_MD_SIZE, &hashlen)) {\n        return EXT_RETURN_FAIL;\n    }\n    if (!WPACKET_allocate_bytes(pkt, hashlen, &hashval2)\n            || !ossl_assert(hashval1 == hashval2)\n            || !WPACKET_close(pkt)\n            || !WPACKET_start_sub_packet_u8(pkt)\n            || !WPACKET_reserve_bytes(pkt, SSL_COOKIE_LENGTH, &appcookie1)) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_STOC_COOKIE,\n                 ERR_R_INTERNAL_ERROR);\n        return EXT_RETURN_FAIL;\n    }\n    if (s->ctx->app_gen_cookie_cb(s, appcookie1, &appcookielen) == 0) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_STOC_COOKIE,\n                 SSL_R_COOKIE_GEN_CALLBACK_FAILURE);\n        return EXT_RETURN_FAIL;\n    }\n    if (!WPACKET_allocate_bytes(pkt, appcookielen, &appcookie2)\n            || !ossl_assert(appcookie1 == appcookie2)\n            || !WPACKET_close(pkt)\n            || !WPACKET_get_total_written(pkt, &totcookielen)\n            || !WPACKET_reserve_bytes(pkt, SHA256_DIGEST_LENGTH, &hmac)) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_STOC_COOKIE,\n                 ERR_R_INTERNAL_ERROR);\n        return EXT_RETURN_FAIL;\n    }\n    hmaclen = SHA256_DIGEST_LENGTH;\n    totcookielen -= startlen;\n    if (!ossl_assert(totcookielen <= MAX_COOKIE_SIZE - SHA256_DIGEST_LENGTH)) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_STOC_COOKIE,\n                 ERR_R_INTERNAL_ERROR);\n        return EXT_RETURN_FAIL;\n    }\n    hctx = EVP_MD_CTX_create();\n    pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL,\n                                s->session_ctx->ext.cookie_hmac_key,\n                                sizeof(s->session_ctx->ext.cookie_hmac_key));\n    if (hctx == NULL || pkey == NULL) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_STOC_COOKIE,\n                 ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    if (EVP_DigestSignInit(hctx, NULL, EVP_sha256(), NULL, pkey) <= 0\n            || EVP_DigestSign(hctx, hmac, &hmaclen, cookie,\n                              totcookielen) <= 0) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_STOC_COOKIE,\n                 ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    if (!ossl_assert(totcookielen + hmaclen <= MAX_COOKIE_SIZE)) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_STOC_COOKIE,\n                 ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    if (!WPACKET_allocate_bytes(pkt, hmaclen, &hmac2)\n            || !ossl_assert(hmac == hmac2)\n            || !ossl_assert(cookie == hmac - totcookielen)\n            || !WPACKET_close(pkt)\n            || !WPACKET_close(pkt)) {\n        SSLfatal(s, SSL_AD_INTERNAL_ERROR, SSL_F_TLS_CONSTRUCT_STOC_COOKIE,\n                 ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    ret = EXT_RETURN_SENT;\n err:\n    EVP_MD_CTX_free(hctx);\n    EVP_PKEY_free(pkey);\n    return ret;\n}', 'int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes)\n{\n    WPACKET_SUB *sub;\n    unsigned char *lenchars;\n    if (!ossl_assert(pkt->subs != NULL))\n        return 0;\n    sub = OPENSSL_zalloc(sizeof(*sub));\n    if (sub == NULL)\n        return 0;\n    sub->parent = pkt->subs;\n    pkt->subs = sub;\n    sub->pwritten = pkt->written + lenbytes;\n    sub->lenbytes = lenbytes;\n    if (lenbytes == 0) {\n        sub->packet_len = 0;\n        return 1;\n    }\n    if (!WPACKET_allocate_bytes(pkt, lenbytes, &lenchars))\n        return 0;\n    sub->packet_len = lenchars - GETBUF(pkt);\n    return 1;\n}', 'int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes)\n{\n    if (!ossl_assert(pkt->subs != NULL && len != 0))\n        return 0;\n    if (pkt->maxsize - pkt->written < len)\n        return 0;\n    if (pkt->staticbuf == NULL && (pkt->buf->length - pkt->written < len)) {\n        size_t newlen;\n        size_t reflen;\n        reflen = (len > pkt->buf->length) ? len : pkt->buf->length;\n        if (reflen > SIZE_MAX / 2) {\n            newlen = SIZE_MAX;\n        } else {\n            newlen = reflen * 2;\n            if (newlen < DEFAULT_BUF_SIZE)\n                newlen = DEFAULT_BUF_SIZE;\n        }\n        if (BUF_MEM_grow(pkt->buf, newlen) == 0)\n            return 0;\n    }\n    if (allocbytes != NULL)\n        *allocbytes = WPACKET_get_curr(pkt);\n    return 1;\n}']