Skip to content

Commit 7bdc160

Browse files
author
Seppo Takalo
committed
Merge pull request #21 from ARMmbed/limit_read_loop
Limit the number of mbed_ssl_read() in while loop.
2 parents 0e87ec8 + 9752d7c commit 7bdc160

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

source/coap_security_handler.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,12 +498,15 @@ int coap_security_send_close_alert(coap_security_t *sec)
498498

499499
int coap_security_handler_read(coap_security_t *sec, unsigned char* buffer, size_t len){
500500
int ret=-1;
501+
int max_loops = 100;
501502

502503
if( sec && buffer ){
503504
memset( buffer, 0, len );
504-
do ret = mbedtls_ssl_read( &sec->_ssl, buffer, len );
505-
while( ret == MBEDTLS_ERR_SSL_WANT_READ ||
506-
ret == MBEDTLS_ERR_SSL_WANT_WRITE );
505+
do {
506+
ret = mbedtls_ssl_read( &sec->_ssl, buffer, len );
507+
} while( (ret == MBEDTLS_ERR_SSL_WANT_READ ||
508+
ret == MBEDTLS_ERR_SSL_WANT_WRITE)
509+
&& --max_loops);
507510
}
508511
return ret; //bytes read
509512
}

0 commit comments

Comments
 (0)