Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/sniffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3285,6 +3285,9 @@ static int ProcessKeyShare(KeyShareInfo* info, const byte* input, int len,
XMEMSET(info, 0, sizeof(KeyShareInfo));

/* Named group and public key */
if (idx + OPAQUE16_LEN > len) {
return WOLFSSL_FATAL_ERROR;
}
info->named_group = (word16)((input[idx] << 8) | input[idx+1]);
idx += OPAQUE16_LEN;
info->key_len = 0;
Expand Down
71 changes: 60 additions & 11 deletions src/wolfio.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ int BioReceiveInternal(WOLFSSL_BIO* biord, WOLFSSL_BIO* biowr, char* buf,

recvd = wolfSSL_BIO_read(biord, buf, sz);
if (recvd <= 0) {
if (/* ssl->biowr->wrIdx is checked for Bind9 */
if (biowr != NULL &&
/* ssl->biowr->wrIdx is checked for Bind9 */
wolfSSL_BIO_method_type(biowr) == WOLFSSL_BIO_BIO &&
wolfSSL_BIO_wpending(biowr) != 0 &&
/* Not sure this pending check is necessary but let's double
Expand Down Expand Up @@ -1152,20 +1153,42 @@ int EmbedGenerateCookie(WOLFSSL* ssl, byte *buf, int sz, void *ctx)
static int linuxkm_send(struct socket *socket, void *buf, int size,
unsigned int flags)
{
size_t len;
int ret;
struct kvec vec = { .iov_base = buf, .iov_len = size };
struct kvec vec;
struct msghdr msg = { .msg_flags = flags };
ret = kernel_sendmsg(socket, &msg, &vec, 1, size);

if (size < 0)
return -EINVAL;
if (size == 0)
return 0;

len = (size_t)size;
vec.iov_base = buf;
vec.iov_len = len;

ret = kernel_sendmsg(socket, &msg, &vec, 1, len);
return ret;
}

static int linuxkm_recv(struct socket *socket, void *buf, int size,
unsigned int flags)
{
size_t len;
int ret;
struct kvec vec = { .iov_base = buf, .iov_len = size };
struct kvec vec;
struct msghdr msg = { .msg_flags = flags };
ret = kernel_recvmsg(socket, &msg, &vec, 1, size, msg.msg_flags);

if (size < 0)
return -EINVAL;
if (size == 0)
return 0;

len = (size_t)size;
vec.iov_base = buf;
vec.iov_len = len;

ret = kernel_recvmsg(socket, &msg, &vec, 1, len, msg.msg_flags);
return ret;
}
#endif /* WOLFSSL_LINUXKM */
Expand Down Expand Up @@ -1669,12 +1692,17 @@ int wolfIO_DecodeUrl(const char* url, int urlSz, char* outName, char* outPath,
return result;
}

#ifndef WOLFIO_HTTP_MAX_BODY
/* Upper bound on an HTTP body that will be buffered in memory. */
#define WOLFIO_HTTP_MAX_BODY (32 * 1024 * 1024)
#endif

static int wolfIO_HttpProcessResponseBuf(WolfSSLGenericIORecvCb ioCb,
void* ioCbCtx, byte **recvBuf, int* recvBufSz, int chunkSz, char* start,
int len, int dynType, void* heap)
{
byte* newRecvBuf = NULL;
int newRecvSz = *recvBufSz + chunkSz;
int newRecvSz;
int pos = 0;

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

if (chunkSz > WOLFIO_HTTP_MAX_BODY) {
WOLFSSL_MSG("wolfIO_HttpProcessResponseBuf chunk too large");
return BUFFER_ERROR;
}

if (*recvBufSz < 0 || *recvBufSz > WOLFIO_HTTP_MAX_BODY - chunkSz) {
WOLFSSL_MSG("wolfIO_HttpProcessResponseBuf aggregate body too large");
return BUFFER_ERROR;
}

if (len > chunkSz) {
WOLFSSL_MSG("wolfIO_HttpProcessResponseBuf len exceeds chunk size");
return WOLFSSL_FATAL_ERROR;
}

newRecvSz = *recvBufSz + chunkSz;

if (newRecvSz <= 0) {
WOLFSSL_MSG("wolfIO_HttpProcessResponseBuf new receive size overflow");
return MEMORY_E;
Expand Down Expand Up @@ -2700,11 +2745,15 @@ int MicriumReceiveFrom(WOLFSSL *ssl, char *buf, int sz, void *ctx)
}
}
else {
if (dtlsCtx->peer.sz > 0
&& peerSz != (NET_SOCK_ADDR_LEN)dtlsCtx->peer.sz
&& XMEMCMP(&peer, dtlsCtx->peer.sa, peerSz) != 0) {
WOLFSSL_MSG("\tIgnored packet from invalid peer");
return WOLFSSL_CBIO_ERR_WANT_READ;
if (dtlsCtx->peer.sz > 0) {
NET_SOCK_ADDR_LEN expectedPeerSz =
(NET_SOCK_ADDR_LEN)dtlsCtx->peer.sz;
if (dtlsCtx->peer.sa == NULL ||
peerSz != expectedPeerSz ||
XMEMCMP(&peer, dtlsCtx->peer.sa, expectedPeerSz) != 0) {
WOLFSSL_MSG("\tIgnored packet from invalid peer");
return WOLFSSL_CBIO_ERR_WANT_READ;
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions wolfcrypt/src/rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -2237,6 +2237,11 @@ static int wc_RsaFunctionSync(const byte* in, word32 inLen, byte* out,
ERROR_OUT(BAD_FUNC_ARG);
}

if (inLen != keyLen) {
WOLFSSL_MSG("Expected that inLen equals RSA key length");
ERROR_OUT(BAD_FUNC_ARG);
}

if ((keyBuf = (byte*)XMALLOC(keyLen * 2, key->heap, DYNAMIC_TYPE_KEY))
== NULL) {
ERROR_OUT(MEMORY_E);
Expand Down
Loading