From 5a1a9ba98e2949268027d73d78497e4a154bcfa0 Mon Sep 17 00:00:00 2001 From: Vlad Grigorescu Date: Thu, 5 Mar 2020 12:18:31 -0600 Subject: [PATCH] Add support to MySQL for deprecation of EOF packets. From the docs: "As of MySQL 5.7.5, OK packes are also used to indicate EOF, and EOF packets are deprecated." The client sets a capability flag (CLIENT_DEPRECATE_EOF) to indicate that it expects an OK instead of an EOF after the resultset rows. --- .../protocol/mysql/mysql-protocol.pac | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/analyzer/protocol/mysql/mysql-protocol.pac b/src/analyzer/protocol/mysql/mysql-protocol.pac index f4e01c352a..f78a5c68e4 100644 --- a/src/analyzer/protocol/mysql/mysql-protocol.pac +++ b/src/analyzer/protocol/mysql/mysql-protocol.pac @@ -151,6 +151,11 @@ enum Expected { EXPECT_AUTH_SWITCH, }; +enum Client_Capabilities { + # Expects an OK (instead of EOF) after the resultset rows of a Text Resultset. + CLIENT_DEPRECATE_EOF = 0x01000000, +}; + type NUL_String = RE/[^\0]*\0/; # MySQL PDU @@ -230,6 +235,8 @@ type Handshake_Response_Packet_v10 = record { pad : padding[23]; username : NUL_String; password : bytestring &restofdata; +} &let { + deprecate_eof: bool = $context.connection.set_deprecate_eof(cap_flags & CLIENT_DEPRECATE_EOF); }; type Handshake_Response_Packet_v9 = record { @@ -315,8 +322,9 @@ type ColumnDefinitionOrEOF(pkt_len: uint32) = record { }; -type EOF1 = record { - eof: EOF_Packet; +type EOF1 = case $context.connection.get_deprecate_eof() of { + false -> eof: EOF_Packet; + true -> ok: OK_Packet; } &let { update_result_seen: bool = $context.connection.set_results_seen(0); update_expectation: bool = $context.connection.set_next_expected(EXPECT_RESULTSET); @@ -403,6 +411,7 @@ refine connection MySQL_Conn += { uint32 col_count_; uint32 remaining_cols_; uint32 results_seen_; + bool deprecate_eof_; %} %init{ @@ -412,6 +421,7 @@ refine connection MySQL_Conn += { col_count_ = 0; remaining_cols_ = 0; results_seen_ = 0; + deprecate_eof_ = false; %} function get_version(): uint8 @@ -436,6 +446,17 @@ refine connection MySQL_Conn += { return true; %} + function get_deprecate_eof(): bool + %{ + return deprecate_eof_; + %} + + function set_deprecate_eof(d: bool): bool + %{ + deprecate_eof_ = d; + return true; + %} + function get_expectation(): Expected %{ return expected_;