]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Do not allocate TlsDetails until throwing isSslv2Record() returns.
authorAlex Rousskov <rousskov@measurement-factory.com>
Fri, 22 Apr 2016 04:51:24 +0000 (22:51 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Fri, 22 Apr 2016 04:51:24 +0000 (22:51 -0600)
If isSslv2Record() throws InsufficientInput, then we must re-parse these
first few bytes later. Nil details triggers that parsing.

src/security/Handshake.cc
src/security/Handshake.h

index c02d58817da0a7c98f0a56459f065c83b240f2d8..393095c94c44e6406d72960d586ce496e89330ed 100644 (file)
@@ -154,27 +154,21 @@ Security::HandshakeParser::parseVersion2Record()
     parseDone = true;
 }
 
+/// RFC 5246. Appendix E.2. Compatibility with SSL 2.0
+/// And draft-hickman-netscape-ssl-00. Section 4.1 SSL Record Header Format
 bool
-Security::HandshakeParser::isSslv2Record()
+Security::HandshakeParser::isSslv2Record(const SBuf &raw) const
 {
-    uint16_t head = tkRecords.uint16(".head(Record+Length)");
-    uint16_t length = head & 0x7FFF;
-    uint8_t type = tkRecords.uint8(".type");
-    tkRecords.rollback();
-    if ((head & 0x8000) == 0 || length == 0 || type != 0x01)
-        return false;
-    // It is an SSLv2 Client Hello Message
-    return true;
+    BinaryTokenizer tk(raw, true);
+    const uint16_t head = tk.uint16("V2Hello.msg_length+");
+    const uint8_t type = tk.uint8("V2Hello.msg_type");
+    const uint16_t length = head & 0x7FFF;
+    return (head & 0x8000) && length && type == 1;
 }
 
 void
 Security::HandshakeParser::parseRecord()
 {
-    if (details == NULL) {
-        details = new TlsDetails;
-        expectingModernRecords = !isSslv2Record();
-    }
-
     if (expectingModernRecords)
         parseModernRecord();
     else
@@ -436,6 +430,11 @@ bool
 Security::HandshakeParser::parseHello(const SBuf &data)
 {
     try {
+        if (!details) {
+            expectingModernRecords = !isSslv2Record(data);
+            details = new TlsDetails; // after expectingModernRecords is known
+        }
+
         // data contains everything read so far, but we may read more later
         tkRecords.reinput(data, true);
         tkRecords.rollback();
index 813f388a9decaaa25b66bb8c203110096b473f11..1cad34746014c5def71aa0f745ef50723283c97b 100644 (file)
@@ -199,8 +199,7 @@ public:
     bool parseError; ///< Set to tru by parse on parse error.
 
 private:
-
-    bool isSslv2Record();
+    bool isSslv2Record(const SBuf &raw) const;
     void parseRecord();
     void parseModernRecord();
     void parseVersion2Record();