Skip to content

Commit 5b4be7d

Browse files
committed
Reserve 16k fragment buffer only when it is actually required.
This change reduces memory pressure when server response size fits into 6k buffer allocated by default.
1 parent b33ef68 commit 5b4be7d

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

ssl/tls1.c

+15-11
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,7 @@ EXP_FUNC void STDCALL ssl_free(SSL *ssl)
259259
*/
260260
EXP_FUNC int STDCALL ssl_read(SSL *ssl, uint8_t **in_data)
261261
{
262-
int ret = increase_bm_data_size(ssl);
263-
if (ret != SSL_OK) {
264-
return ret;
265-
}
266-
ret = basic_read(ssl, in_data);
262+
int ret = basic_read(ssl, in_data);
267263

268264
/* check for return code so we can send an alert */
269265
if (ret < SSL_OK && ret != SSL_CLOSE_NOTIFY)
@@ -287,10 +283,6 @@ EXP_FUNC int STDCALL ssl_read(SSL *ssl, uint8_t **in_data)
287283
EXP_FUNC int STDCALL ssl_write(SSL *ssl, const uint8_t *out_data, int out_len)
288284
{
289285
int n = out_len, nw, i, tot = 0;
290-
int ret = increase_bm_data_size(ssl);
291-
if (ret != SSL_OK) {
292-
return ret;
293-
}
294286
/* maximum size of a TLS packet is around 16kB, so fragment */
295287
do
296288
{
@@ -1293,9 +1285,21 @@ int basic_read(SSL *ssl, uint8_t **in_data)
12931285
/* do we violate the spec with the message size? */
12941286
if (ssl->need_bytes > ssl->max_plain_length+RT_EXTRA-BM_RECORD_OFFSET)
12951287
{
1296-
ret = SSL_ERROR_INVALID_PROT_MSG;
12971288
printf("ssl->need_bytes=%d > %d\r\n", ssl->need_bytes, ssl->max_plain_length+RT_EXTRA-BM_RECORD_OFFSET);
1298-
goto error;
1289+
if (ssl->can_increase_data_size)
1290+
{
1291+
ret = increase_bm_data_size(ssl);
1292+
if (ret != SSL_OK)
1293+
{
1294+
ret = SSL_ERROR_INVALID_PROT_MSG;
1295+
goto error;
1296+
}
1297+
}
1298+
else
1299+
{
1300+
ret = SSL_ERROR_INVALID_PROT_MSG;
1301+
goto error;
1302+
}
12991303
}
13001304

13011305
CLR_SSL_FLAG(SSL_NEED_RECORD);

0 commit comments

Comments
 (0)