@@ -260,21 +260,23 @@ EXP_FUNC void STDCALL ssl_free(SSL *ssl)
260
260
*/
261
261
EXP_FUNC int STDCALL ssl_read (SSL * ssl , uint8_t * * in_data )
262
262
{
263
- int ret = basic_read (ssl , in_data );
263
+ int ret = SSL_OK ;
264
+ do {
265
+ ret = basic_read (ssl , in_data );
264
266
265
- /* check for return code so we can send an alert */
266
- if (ret < SSL_OK && ret != SSL_CLOSE_NOTIFY )
267
- {
268
- if (ret != SSL_ERROR_CONN_LOST )
267
+ /* check for return code so we can send an alert */
268
+ if (ret < SSL_OK && ret != SSL_CLOSE_NOTIFY )
269
269
{
270
- send_alert (ssl , ret );
271
- #ifndef CONFIG_SSL_SKELETON_MODE
272
- /* something nasty happened, so get rid of this session */
273
- kill_ssl_session (ssl -> ssl_ctx -> ssl_sessions , ssl );
274
- #endif
270
+ if (ret != SSL_ERROR_CONN_LOST )
271
+ {
272
+ send_alert (ssl , ret );
273
+ #ifndef CONFIG_SSL_SKELETON_MODE
274
+ /* something nasty happened, so get rid of this session */
275
+ kill_ssl_session (ssl -> ssl_ctx -> ssl_sessions , ssl );
276
+ #endif
277
+ }
275
278
}
276
- }
277
-
279
+ } while (IS_SET_SSL_FLAG (SSL_READ_BLOCKING ) && (ssl -> got_bytes < ssl -> need_bytes ) && ret == 0 && !IS_SET_SSL_FLAG (SSL_NEED_RECORD ));
278
280
return ret ;
279
281
}
280
282
@@ -558,6 +560,9 @@ SSL *ssl_new(SSL_CTX *ssl_ctx, int client_fd)
558
560
559
561
/* a bit hacky but saves a few bytes of memory */
560
562
ssl -> flag |= ssl_ctx -> options ;
563
+ if (IS_SET_SSL_FLAG (SSL_CONNECT_IN_PARTS ) && IS_SET_SSL_FLAG (SSL_READ_BLOCKING )) {
564
+ CLR_SSL_FLAG (SSL_READ_BLOCKING );
565
+ }
561
566
SSL_CTX_LOCK (ssl_ctx -> mutex );
562
567
563
568
if (ssl_ctx -> head == NULL )
@@ -1293,6 +1298,14 @@ int basic_read(SSL *ssl, uint8_t **in_data)
1293
1298
ssl -> need_bytes = (buf [3 ] << 8 ) + buf [4 ];
1294
1299
1295
1300
/* do we violate the spec with the message size? */
1301
+ if (ssl -> need_bytes > RT_MAX_PLAIN_LENGTH + RT_EXTRA - BM_RECORD_OFFSET )
1302
+ {
1303
+ printf ("ssl->need_bytes=%d violates spec\r\n" , ssl -> need_bytes , RT_MAX_PLAIN_LENGTH + RT_EXTRA - BM_RECORD_OFFSET );
1304
+ ret = SSL_ERROR_INVALID_PROT_MSG ;
1305
+ goto error ;
1306
+ }
1307
+
1308
+ /* is the allocated buffer large enough to handle all the data? if not, increase its size*/
1296
1309
if (ssl -> need_bytes > ssl -> max_plain_length + RT_EXTRA - BM_RECORD_OFFSET )
1297
1310
{
1298
1311
printf ("ssl->need_bytes=%d > %d\r\n" , ssl -> need_bytes , ssl -> max_plain_length + RT_EXTRA - BM_RECORD_OFFSET );
0 commit comments