aboutsummaryrefslogtreecommitdiff
path: root/src/tls/tls_drv.c
diff options
context:
space:
mode:
authorAlexey Shchepin <alexey@process-one.net>2012-03-07 16:19:59 +0200
committerAlexey Shchepin <alexey@process-one.net>2012-03-07 16:19:59 +0200
commit0b423eb28756e88895ecb7dcf7cbf71d7cbf1571 (patch)
tree89e9703b9ebec1dd8b3cb4711c0ecfa58997dcbb /src/tls/tls_drv.c
parentAvoid quadratic behavior in reading SSL data (diff)
Don't ignore Length parameter in tls:recv
Diffstat (limited to 'src/tls/tls_drv.c')
-rw-r--r--src/tls/tls_drv.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/tls/tls_drv.c b/src/tls/tls_drv.c
index 40295d7a3..60a51174d 100644
--- a/src/tls/tls_drv.c
+++ b/src/tls/tls_drv.c
@@ -434,13 +434,22 @@ static ErlDrvSSizeT tls_drv_control(ErlDrvData handle,
"SSL_do_handshake failed");
}
if (SSL_is_init_finished(d->ssl)) {
+ size_t req_size = 0;
+ if (len == 4)
+ {
+ req_size =
+ (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
+ }
size = BUF_SIZE + 1;
rlen = 1;
b = driver_alloc_binary(size);
b->orig_bytes[0] = 0;
- while ((res = SSL_read(d->ssl,
- b->orig_bytes + rlen, BUF_SIZE)) > 0)
+ while ((req_size == 0 || rlen < req_size + 1) &&
+ (res = SSL_read(d->ssl,
+ b->orig_bytes + rlen,
+ (req_size == 0 || req_size + 1 >= size) ?
+ size - rlen : req_size + 1 - rlen)) > 0)
{
//printf("%d bytes of decrypted data read from state machine\r\n",res);
rlen += res;