Skip to content

Commit 2596700

Browse files
committed
Bound buffered HTTP body size
Clamp per-chunk and aggregated HTTP response sizes before allocating in wolfIO_HttpProcessResponseBuf so untrusted Content-Length or chunk headers can’t overflow the arithmetic or force giant buffers.
1 parent be1428d commit 2596700

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/wolfio.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1670,12 +1670,17 @@ int wolfIO_DecodeUrl(const char* url, int urlSz, char* outName, char* outPath,
16701670
return result;
16711671
}
16721672

1673+
#ifndef WOLFIO_HTTP_MAX_BODY
1674+
/* Upper bound on an HTTP body that will be buffered in memory. */
1675+
#define WOLFIO_HTTP_MAX_BODY (32 * 1024 * 1024)
1676+
#endif
1677+
16731678
static int wolfIO_HttpProcessResponseBuf(WolfSSLGenericIORecvCb ioCb,
16741679
void* ioCbCtx, byte **recvBuf, int* recvBufSz, int chunkSz, char* start,
16751680
int len, int dynType, void* heap)
16761681
{
16771682
byte* newRecvBuf = NULL;
1678-
int newRecvSz = *recvBufSz + chunkSz;
1683+
int newRecvSz;
16791684
int pos = 0;
16801685

16811686
WOLFSSL_MSG("Processing HTTP response");
@@ -1691,6 +1696,23 @@ static int wolfIO_HttpProcessResponseBuf(WolfSSLGenericIORecvCb ioCb,
16911696
return MEMORY_E;
16921697
}
16931698

1699+
if (chunkSz > WOLFIO_HTTP_MAX_BODY) {
1700+
WOLFSSL_MSG("wolfIO_HttpProcessResponseBuf chunk too large");
1701+
return BUFFER_ERROR;
1702+
}
1703+
1704+
if (*recvBufSz < 0 || *recvBufSz > WOLFIO_HTTP_MAX_BODY - chunkSz) {
1705+
WOLFSSL_MSG("wolfIO_HttpProcessResponseBuf aggregate body too large");
1706+
return BUFFER_ERROR;
1707+
}
1708+
1709+
if (len > chunkSz) {
1710+
WOLFSSL_MSG("wolfIO_HttpProcessResponseBuf len exceeds chunk size");
1711+
return WOLFSSL_FATAL_ERROR;
1712+
}
1713+
1714+
newRecvSz = *recvBufSz + chunkSz;
1715+
16941716
if (newRecvSz <= 0) {
16951717
WOLFSSL_MSG("wolfIO_HttpProcessResponseBuf new receive size overflow");
16961718
return MEMORY_E;

0 commit comments

Comments
 (0)