Skip to content

Commit 385a097

Browse files
authored
Merge pull request #7638 from gasbytes/patch
added check if the buf is at least RECORD_HEADER_SZ
2 parents 897d55f + 88527a3 commit 385a097

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/quic.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static word32 add_rec_header(byte* output, word32 length, byte type)
188188
return RECORD_HEADER_SZ;
189189
}
190190

191-
static word32 quic_record_transfer(QuicRecord* qr, byte* buf, word32 sz)
191+
static sword32 quic_record_transfer(QuicRecord* qr, byte* buf, word32 sz)
192192
{
193193
word32 len = qr->end - qr->start;
194194
word32 offset = 0;
@@ -197,6 +197,12 @@ static word32 quic_record_transfer(QuicRecord* qr, byte* buf, word32 sz)
197197
if (len <= 0) {
198198
return 0;
199199
}
200+
201+
/* We check if the buf is at least RECORD_HEADER_SZ */
202+
if (sz < RECORD_HEADER_SZ) {
203+
return -1;
204+
}
205+
200206
if (qr->rec_hdr_remain == 0) {
201207
/* start a new TLS record */
202208
rlen = (qr->len <= (word32)MAX_RECORD_SIZE) ?
@@ -218,7 +224,7 @@ static word32 quic_record_transfer(QuicRecord* qr, byte* buf, word32 sz)
218224
qr->start += len;
219225
qr->rec_hdr_remain -= len;
220226
}
221-
return len + offset;
227+
return (sword32)(len + offset);
222228
}
223229

224230

@@ -766,14 +772,19 @@ int wolfSSL_provide_quic_data(WOLFSSL* ssl, WOLFSSL_ENCRYPTION_LEVEL level,
766772
/* Called internally when SSL wants a certain amount of input. */
767773
int wolfSSL_quic_receive(WOLFSSL* ssl, byte* buf, word32 sz)
768774
{
769-
word32 n = 0;
775+
sword32 n = 0;
770776
int transferred = 0;
771777

772778
WOLFSSL_ENTER("wolfSSL_quic_receive");
773779
while (sz > 0) {
774780
n = 0;
775781
if (ssl->quic.input_head) {
776782
n = quic_record_transfer(ssl->quic.input_head, buf, sz);
783+
784+
/* record too small to be fit into a RecordLayerHeader struct. */
785+
if (n == -1) {
786+
return -1;
787+
}
777788
if (quic_record_done(ssl->quic.input_head)) {
778789
QuicRecord* qr = ssl->quic.input_head;
779790
ssl->quic.input_head = qr->next;
@@ -791,7 +802,7 @@ int wolfSSL_quic_receive(WOLFSSL* ssl, byte* buf, word32 sz)
791802
ssl->error = transferred = WANT_READ;
792803
goto cleanup;
793804
}
794-
sz -= n;
805+
sz -= (word32)n;
795806
buf += n;
796807
transferred += (int)n;
797808
}

0 commit comments

Comments
 (0)