diff options
author | lloyd <[email protected]> | 2012-09-07 14:13:18 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2012-09-07 14:13:18 +0000 |
commit | 3f877fe296c1959fefa696094314c96f78bb9f7e (patch) | |
tree | a2004d39a05f06c4521086c9880bc8bf73c6e57e /src/tls/tls_record.cpp | |
parent | 70781697af4a4f6d94f04198b25a556d0a78ee81 (diff) |
In Channel move some checks to after we've verified needed == 0 to
avoid a conditional.
Clean up record checking in the reader.
Diffstat (limited to 'src/tls/tls_record.cpp')
-rw-r--r-- | src/tls/tls_record.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/tls/tls_record.cpp b/src/tls/tls_record.cpp index 4a031f626..5ecd226a4 100644 --- a/src/tls/tls_record.cpp +++ b/src/tls/tls_record.cpp @@ -344,20 +344,21 @@ size_t read_record(std::vector<byte>& readbuf, " from counterparty"); } - if(version.is_datagram_protocol()) + Protocol_Version record_version(readbuf[1], readbuf[2]); + + if(record_version.is_datagram_protocol()) msg_sequence = load_be<u64bit>(&readbuf[3], 0); const size_t record_len = make_u16bit(readbuf[header_size-2], readbuf[header_size-1]); - if(version.major_version()) + if(version.valid() && record_version != version) { - if(readbuf[1] != version.major_version() || - readbuf[2] != version.minor_version()) - { - throw TLS_Exception(Alert::PROTOCOL_VERSION, - "Got unexpected version from counterparty"); - } + throw TLS_Exception(Alert::PROTOCOL_VERSION, + "Got record with version " + + record_version.to_string() + + " expected " + + version.to_string()); } if(record_len > MAX_CIPHERTEXT_SIZE) |