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

src: refactor crypto code with RAII cleanup #23014

Merged
merged 1 commit into from
Sep 28, 2018
Merged
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
18 changes: 11 additions & 7 deletions src/node_crypto_clienthello.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ bool ClientHelloParser::ParseRecordHeader(const uint8_t* data, size_t avail) {

void ClientHelloParser::ParseHeader(const uint8_t* data, size_t avail) {
ClientHello hello;
bool failed = true;

OnScopeLeave cleanup([&]() {
if (failed)
End();
});

// >= 5 + frame size bytes for frame parsing
if (body_offset_ + frame_len_ > avail)
Expand All @@ -88,23 +94,23 @@ void ClientHelloParser::ParseHeader(const uint8_t* data, size_t avail) {
if (data[body_offset_ + 4] != 0x03 ||
data[body_offset_ + 5] < 0x01 ||
data[body_offset_ + 5] > 0x03) {
goto fail;
return;
}

if (data[body_offset_] == kClientHello) {
if (state_ == kTLSHeader) {
if (!ParseTLSClientHello(data, avail))
goto fail;
return;
} else {
// We couldn't get here, but whatever
goto fail;
return;
}

// Check if we overflowed (do not reply with any private data)
if (session_id_ == nullptr ||
session_size_ > 32 ||
session_id_ + session_size_ > data + avail) {
goto fail;
return;
}
}

Expand All @@ -116,10 +122,8 @@ void ClientHelloParser::ParseHeader(const uint8_t* data, size_t avail) {
hello.servername_ = servername_;
hello.servername_size_ = static_cast<uint8_t>(servername_size_);
onhello_cb_(cb_arg_, hello);
failed = false;
return;

fail:
End();
}


Expand Down