Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls_wrap: slice buffer properly in ClearOut #4184

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,17 +409,19 @@ void TLSWrap::ClearOut() {
if (read <= 0)
break;

char* current = out;
while (read > 0) {
int avail = read;

uv_buf_t buf;
OnAlloc(avail, &buf);
if (static_cast<int>(buf.len) < avail)
avail = buf.len;
memcpy(buf.base, out, avail);
memcpy(buf.base, current, avail);
OnRead(avail, &buf);

read -= avail;
current += avail;
}
}

Expand Down
8 changes: 6 additions & 2 deletions test/parallel/test-tls-inception.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var net = require('net');
var options, a, b, portA, portB;
var gotHello = false;

var body = new Buffer(4000).fill('A');

options = {
key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')),
cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'))
Expand All @@ -38,7 +40,7 @@ a = tls.createServer(options, function(socket) {

// the "target" server
b = tls.createServer(options, function(socket) {
socket.end('hello');
socket.end(body);
});

process.on('exit', function() {
Expand All @@ -59,11 +61,13 @@ a.listen(common.PORT, function() {
rejectUnauthorized: false
});
ssl.setEncoding('utf8');
var buf = '';
ssl.once('data', function(data) {
assert.equal('hello', data);
buf += data;
gotHello = true;
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be on?
Also, is gotHello really necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arghh... It should be on indeed. @santigimeno would it be interesting to you to submit a PR with a fix for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotHello seems to be necessary, but could be replaced with common.mustCall in ssl.on('end', ...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I said about gotHello because would the test exit if no end event was received?
Yes, I can send a PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @santigimeno . Please don't forget to cc me on that PR ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@indutny PR: #4195. Thanks

ssl.on('end', function() {
assert.equal(buf, body);
ssl.end();
a.close();
b.close();
Expand Down