summaryrefslogtreecommitdiff
path: root/src/node_crypto_clienthello.cc
diff options
context:
space:
mode:
authorGireesh Punathil <gpunathi@in.ibm.com>2018-09-22 03:43:34 -0400
committerGireesh Punathil <gpunathi@in.ibm.com>2018-09-28 00:34:54 -0400
commit406e3ad212995614168eb4baa514353edac2dcf8 (patch)
tree2b98f82d12022030b65efb0ed18015b0cacb64b5 /src/node_crypto_clienthello.cc
parentd228c4dd278501f688cb633b81ff5bb386c16348 (diff)
downloadandroid-node-v8-406e3ad212995614168eb4baa514353edac2dcf8.tar.gz
android-node-v8-406e3ad212995614168eb4baa514353edac2dcf8.tar.bz2
android-node-v8-406e3ad212995614168eb4baa514353edac2dcf8.zip
src: refactor crypto code with RAII cleanup
use more idiomatic expressions with RAII primitives, instead of old style goto PR-URL: https://github.com/nodejs/node/pull/23014 Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'src/node_crypto_clienthello.cc')
-rw-r--r--src/node_crypto_clienthello.cc18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/node_crypto_clienthello.cc b/src/node_crypto_clienthello.cc
index d4d222f838..4df0d93482 100644
--- a/src/node_crypto_clienthello.cc
+++ b/src/node_crypto_clienthello.cc
@@ -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)
@@ -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;
}
}
@@ -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();
}