From 502eba8b4f67852ae8af7e025d28cda730ff9722 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Tue, 22 Nov 2016 21:31:57 +0200 Subject: [PATCH] Fix OK packet generation The packet was generated with the wrong number of elements due to usage of sizeof on an integer where the correct type was an uint8_t. This only fixes the malformed packets but does not fix the root cause of the problem. The affected rows and last insert ID are length encoded integers which should be handled. The current code treats them as one byte fields. --- include/maxscale/protocol/mysql.h | 2 +- server/modules/protocol/MySQL/mysql_common.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/maxscale/protocol/mysql.h b/include/maxscale/protocol/mysql.h index daca421df..1f91d4730 100644 --- a/include/maxscale/protocol/mysql.h +++ b/include/maxscale/protocol/mysql.h @@ -394,7 +394,7 @@ bool gw_read_backend_handshake(DCB *dcb, GWBUF *buffer); mxs_auth_state_t gw_send_backend_auth(DCB *dcb); /** Write an OK packet to a DCB */ -int mxs_mysql_send_ok(DCB *dcb, int sequence, int affected_rows, const char* message); +int mxs_mysql_send_ok(DCB *dcb, int sequence, uint8_t affected_rows, const char* message); /** Check for OK packet */ bool mxs_mysql_is_ok_packet(GWBUF *buffer); diff --git a/server/modules/protocol/MySQL/mysql_common.c b/server/modules/protocol/MySQL/mysql_common.c index 9873b30ae..9dad9552a 100644 --- a/server/modules/protocol/MySQL/mysql_common.c +++ b/server/modules/protocol/MySQL/mysql_common.c @@ -1086,11 +1086,11 @@ bool gw_get_shared_session_auth_info(DCB* dcb, MYSQL_session* session) * @param dcb DCB where packet is written * @param sequence Packet sequence number * @param affected_rows Number of affected rows - * * @param message SQL message + * @param message SQL message * @return 1 on success, 0 on error * */ -int mxs_mysql_send_ok(DCB *dcb, int sequence, int affected_rows, const char* message) +int mxs_mysql_send_ok(DCB *dcb, int sequence, uint8_t affected_rows, const char* message) { uint8_t *outbuf = NULL; uint32_t mysql_payload_size = 0;