Skip to content

Commit c0cb80e

Browse files
committed
tls_wrap: slice buffer properly in ClearOut
Fix incorrect slicing of cleartext buffer in `TLSWrap::ClearOut`. Fix: #4161 PR-URL: #4184 Reviewed-By: Brian White <[email protected]>
1 parent 49440b7 commit c0cb80e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/tls_wrap.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -409,17 +409,19 @@ void TLSWrap::ClearOut() {
409409
if (read <= 0)
410410
break;
411411

412+
char* current = out;
412413
while (read > 0) {
413414
int avail = read;
414415

415416
uv_buf_t buf;
416417
OnAlloc(avail, &buf);
417418
if (static_cast<int>(buf.len) < avail)
418419
avail = buf.len;
419-
memcpy(buf.base, out, avail);
420+
memcpy(buf.base, current, avail);
420421
OnRead(avail, &buf);
421422

422423
read -= avail;
424+
current += avail;
423425
}
424426
}
425427

test/parallel/test-tls-inception.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ var net = require('net');
1515
var options, a, b, portA, portB;
1616
var gotHello = false;
1717

18+
var body = new Buffer(4000).fill('A');
19+
1820
options = {
1921
key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')),
2022
cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'))
@@ -38,7 +40,7 @@ a = tls.createServer(options, function(socket) {
3840

3941
// the "target" server
4042
b = tls.createServer(options, function(socket) {
41-
socket.end('hello');
43+
socket.end(body);
4244
});
4345

4446
process.on('exit', function() {
@@ -59,11 +61,13 @@ a.listen(common.PORT, function() {
5961
rejectUnauthorized: false
6062
});
6163
ssl.setEncoding('utf8');
64+
var buf = '';
6265
ssl.once('data', function(data) {
63-
assert.equal('hello', data);
66+
buf += data;
6467
gotHello = true;
6568
});
6669
ssl.on('end', function() {
70+
assert.equal(buf, body);
6771
ssl.end();
6872
a.close();
6973
b.close();

0 commit comments

Comments
 (0)