diff --git a/src/app-layer-ssl.c b/src/app-layer-ssl.c index dd23d0b46b..573ff8b74e 100644 --- a/src/app-layer-ssl.c +++ b/src/app-layer-ssl.c @@ -1412,6 +1412,12 @@ static uint32_t GetCertsLen(SSLStateConnp *curr_connp, const uint8_t *input, } } +// For certificates whose size is bigger than this, +// we do not allocate all the required memory straight away, +// to avoid DOS by RAM exhaustion, but we will allocate +// this memory once a consequent part of the certificate has been seen. +#define SSL_CERT_MAX_FIRST_ALLOC 65536 // 0x10000 + /** \internal * \brief setup or grow the `trec` space in the connp */ @@ -1425,6 +1431,10 @@ static int EnsureRecordSpace(SSLStateConnp *curr_connp, const uint8_t * const in SCLogDebug("cert_len unknown still, create small buffer to start"); certs_len = 256; } + // Limit in a first time allocation for very large certificates + if (certs_len > SSL_CERT_MAX_FIRST_ALLOC && certs_len > curr_connp->trec_pos + input_len) { + certs_len = SSL_CERT_MAX_FIRST_ALLOC; + } if (curr_connp->trec == NULL) { curr_connp->trec_len = certs_len;