Skip to content

Commit a472a8d

Browse files
committed
Handle partial handshake messages
1 parent 363cf3d commit a472a8d

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

ssl/ssl_locl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,7 @@ typedef struct cert_pkey_st CERT_PKEY;
10921092
struct quic_data_st {
10931093
struct quic_data_st *next;
10941094
OSSL_ENCRYPTION_LEVEL level;
1095+
size_t offset;
10951096
size_t length;
10961097
};
10971098
typedef struct quic_data_st QUIC_DATA;

ssl/ssl_quic.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,26 @@ int SSL_provide_quic_data(SSL *ssl, OSSL_ENCRYPTION_LEVEL level,
114114
QUIC_DATA *qd;
115115
const uint8_t *p = data + 1;
116116

117+
/* Check for an incomplete block */
118+
qd = ssl->quic_input_data_tail;
119+
if (qd != NULL) {
120+
l = ssl->quic_input_data_tail->length - ssl->quic_input_data_tail->offset;
121+
if (l != 0) {
122+
/* we still need to copy `l` bytes into the last data block */
123+
if (l > len)
124+
l = len;
125+
memcpy((char*)(qd+1) + qd->offset, data, l);
126+
qd->offset += l;
127+
len -= l;
128+
data += l;
129+
continue;
130+
}
131+
}
132+
117133
n2l3(p, l);
118134
l += SSL3_HM_HEADER_LENGTH;
119135

120-
if (l > len) {
121-
SSLerr(SSL_F_SSL_PROVIDE_QUIC_DATA, SSL_R_BAD_DATA_LENGTH);
122-
return 0;
123-
}
124-
125-
qd = OPENSSL_malloc(sizeof(QUIC_DATA) + l);
136+
qd = OPENSSL_zalloc(sizeof(QUIC_DATA) + l);
126137
if (qd == NULL) {
127138
SSLerr(SSL_F_SSL_PROVIDE_QUIC_DATA, SSL_R_INTERNAL_ERROR);
128139
return 0;
@@ -131,6 +142,11 @@ int SSL_provide_quic_data(SSL *ssl, OSSL_ENCRYPTION_LEVEL level,
131142
qd->next = NULL;
132143
qd->length = l;
133144
qd->level = level;
145+
/* partial data received? */
146+
if (l > len)
147+
l = len;
148+
qd->offset = l;
149+
134150
memcpy((void*)(qd + 1), data, l);
135151
if (ssl->quic_input_data_tail != NULL)
136152
ssl->quic_input_data_tail->next = qd;

0 commit comments

Comments
 (0)