Avoid undefined behaviour in PACKET_buf_init

Change the sanity check in PACKET_buf_init to check for excessive length
buffers, which should catch the interesting cases where len has been cast
from a negative value whilst avoiding any undefined behaviour.

RT#4094

Reviewed-by: Richard Levitte <levitte@openssl.org>
This commit is contained in:
Matt Caswell 2015-10-21 10:00:24 +01:00
parent 788d72ba02
commit 3fde6c9276

View file

@ -111,7 +111,7 @@ __owur static inline int PACKET_buf_init(PACKET *pkt, unsigned char *buf,
size_t len)
{
/* Sanity check for negative values. */
if (buf + len < buf)
if (len > (size_t)(SIZE_MAX / 2))
return 0;
pkt->curr = buf;