Skip to content

Commit 936e350

Browse files
Merge pull request #9325 from LinuxJedi/zp-fixes
Fix things found with ZeroPath
2 parents 1134d24 + 90e0857 commit 936e350

3 files changed

Lines changed: 68 additions & 11 deletions

File tree

src/sniffer.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3285,6 +3285,9 @@ static int ProcessKeyShare(KeyShareInfo* info, const byte* input, int len,
32853285
XMEMSET(info, 0, sizeof(KeyShareInfo));
32863286

32873287
/* Named group and public key */
3288+
if (idx + OPAQUE16_LEN > len) {
3289+
return WOLFSSL_FATAL_ERROR;
3290+
}
32883291
info->named_group = (word16)((input[idx] << 8) | input[idx+1]);
32893292
idx += OPAQUE16_LEN;
32903293
info->key_len = 0;

src/wolfio.c

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ int BioReceiveInternal(WOLFSSL_BIO* biord, WOLFSSL_BIO* biowr, char* buf,
289289

290290
recvd = wolfSSL_BIO_read(biord, buf, sz);
291291
if (recvd <= 0) {
292-
if (/* ssl->biowr->wrIdx is checked for Bind9 */
292+
if (biowr != NULL &&
293+
/* ssl->biowr->wrIdx is checked for Bind9 */
293294
wolfSSL_BIO_method_type(biowr) == WOLFSSL_BIO_BIO &&
294295
wolfSSL_BIO_wpending(biowr) != 0 &&
295296
/* Not sure this pending check is necessary but let's double
@@ -1152,20 +1153,42 @@ int EmbedGenerateCookie(WOLFSSL* ssl, byte *buf, int sz, void *ctx)
11521153
static int linuxkm_send(struct socket *socket, void *buf, int size,
11531154
unsigned int flags)
11541155
{
1156+
size_t len;
11551157
int ret;
1156-
struct kvec vec = { .iov_base = buf, .iov_len = size };
1158+
struct kvec vec;
11571159
struct msghdr msg = { .msg_flags = flags };
1158-
ret = kernel_sendmsg(socket, &msg, &vec, 1, size);
1160+
1161+
if (size < 0)
1162+
return -EINVAL;
1163+
if (size == 0)
1164+
return 0;
1165+
1166+
len = (size_t)size;
1167+
vec.iov_base = buf;
1168+
vec.iov_len = len;
1169+
1170+
ret = kernel_sendmsg(socket, &msg, &vec, 1, len);
11591171
return ret;
11601172
}
11611173

11621174
static int linuxkm_recv(struct socket *socket, void *buf, int size,
11631175
unsigned int flags)
11641176
{
1177+
size_t len;
11651178
int ret;
1166-
struct kvec vec = { .iov_base = buf, .iov_len = size };
1179+
struct kvec vec;
11671180
struct msghdr msg = { .msg_flags = flags };
1168-
ret = kernel_recvmsg(socket, &msg, &vec, 1, size, msg.msg_flags);
1181+
1182+
if (size < 0)
1183+
return -EINVAL;
1184+
if (size == 0)
1185+
return 0;
1186+
1187+
len = (size_t)size;
1188+
vec.iov_base = buf;
1189+
vec.iov_len = len;
1190+
1191+
ret = kernel_recvmsg(socket, &msg, &vec, 1, len, msg.msg_flags);
11691192
return ret;
11701193
}
11711194
#endif /* WOLFSSL_LINUXKM */
@@ -1669,12 +1692,17 @@ int wolfIO_DecodeUrl(const char* url, int urlSz, char* outName, char* outPath,
16691692
return result;
16701693
}
16711694

1695+
#ifndef WOLFIO_HTTP_MAX_BODY
1696+
/* Upper bound on an HTTP body that will be buffered in memory. */
1697+
#define WOLFIO_HTTP_MAX_BODY (32 * 1024 * 1024)
1698+
#endif
1699+
16721700
static int wolfIO_HttpProcessResponseBuf(WolfSSLGenericIORecvCb ioCb,
16731701
void* ioCbCtx, byte **recvBuf, int* recvBufSz, int chunkSz, char* start,
16741702
int len, int dynType, void* heap)
16751703
{
16761704
byte* newRecvBuf = NULL;
1677-
int newRecvSz = *recvBufSz + chunkSz;
1705+
int newRecvSz;
16781706
int pos = 0;
16791707

16801708
WOLFSSL_MSG("Processing HTTP response");
@@ -1690,6 +1718,23 @@ static int wolfIO_HttpProcessResponseBuf(WolfSSLGenericIORecvCb ioCb,
16901718
return MEMORY_E;
16911719
}
16921720

1721+
if (chunkSz > WOLFIO_HTTP_MAX_BODY) {
1722+
WOLFSSL_MSG("wolfIO_HttpProcessResponseBuf chunk too large");
1723+
return BUFFER_ERROR;
1724+
}
1725+
1726+
if (*recvBufSz < 0 || *recvBufSz > WOLFIO_HTTP_MAX_BODY - chunkSz) {
1727+
WOLFSSL_MSG("wolfIO_HttpProcessResponseBuf aggregate body too large");
1728+
return BUFFER_ERROR;
1729+
}
1730+
1731+
if (len > chunkSz) {
1732+
WOLFSSL_MSG("wolfIO_HttpProcessResponseBuf len exceeds chunk size");
1733+
return WOLFSSL_FATAL_ERROR;
1734+
}
1735+
1736+
newRecvSz = *recvBufSz + chunkSz;
1737+
16931738
if (newRecvSz <= 0) {
16941739
WOLFSSL_MSG("wolfIO_HttpProcessResponseBuf new receive size overflow");
16951740
return MEMORY_E;
@@ -2700,11 +2745,15 @@ int MicriumReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx)
27002745
}
27012746
}
27022747
else {
2703-
if (dtlsCtx->peer.sz > 0
2704-
&& peerSz != (NET_SOCK_ADDR_LEN)dtlsCtx->peer.sz
2705-
&& XMEMCMP(&peer, dtlsCtx->peer.sa, peerSz) != 0) {
2706-
WOLFSSL_MSG("\tIgnored packet from invalid peer");
2707-
return WOLFSSL_CBIO_ERR_WANT_READ;
2748+
if (dtlsCtx->peer.sz > 0) {
2749+
NET_SOCK_ADDR_LEN expectedPeerSz =
2750+
(NET_SOCK_ADDR_LEN)dtlsCtx->peer.sz;
2751+
if (dtlsCtx->peer.sa == NULL ||
2752+
peerSz != expectedPeerSz ||
2753+
XMEMCMP(&peer, dtlsCtx->peer.sa, expectedPeerSz) != 0) {
2754+
WOLFSSL_MSG("\tIgnored packet from invalid peer");
2755+
return WOLFSSL_CBIO_ERR_WANT_READ;
2756+
}
27082757
}
27092758
}
27102759

wolfcrypt/src/rsa.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,6 +2237,11 @@ static int wc_RsaFunctionSync(const byte* in, word32 inLen, byte* out,
22372237
ERROR_OUT(BAD_FUNC_ARG);
22382238
}
22392239

2240+
if (inLen != keyLen) {
2241+
WOLFSSL_MSG("Expected that inLen equals RSA key length");
2242+
ERROR_OUT(BAD_FUNC_ARG);
2243+
}
2244+
22402245
if ((keyBuf = (byte*)XMALLOC(keyLen * 2, key->heap, DYNAMIC_TYPE_KEY))
22412246
== NULL) {
22422247
ERROR_OUT(MEMORY_E);

0 commit comments

Comments
 (0)