From e5b34e30ae5602fa4954e3118d6aaf1074c5acaf Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Tue, 4 Oct 2016 09:20:03 +0200 Subject: [PATCH] Code review update Code review update --- server/modules/include/blr.h | 9 ++++++++- server/modules/routing/binlog/blr_file.c | 2 +- server/modules/routing/binlog/blr_slave.c | 19 ++++++++----------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/server/modules/include/blr.h b/server/modules/include/blr.h index dac910159..6a352116f 100644 --- a/server/modules/include/blr.h +++ b/server/modules/include/blr.h @@ -601,7 +601,14 @@ typedef struct binlog_encryption_ctx * BLRM_FDE_EVENT_TYPES_OFFSET is the offset in FDE event content that points to * the number of events the master server supports. */ -#define BLRM_FDE_EVENT_TYPES_OFFSET (2 + 50 + 4 + 1) +#define BLR_FDE_EVENT_BINLOG_VERSION 2 +#define BLR_FDE_EVENT_SERVER_VERSION 50 +#define BLR_FDE_EVENT_BINLOG_TIME 4 +#define BLR_FDE_EVENT_BINLOG_EVENT_HDR_LEN 1 +#define BLRM_FDE_EVENT_TYPES_OFFSET (BLR_FDE_EVENT_BINLOG_VERSION + \ + BLR_FDE_EVENT_SERVER_VERSION + \ + BLR_FDE_EVENT_BINLOG_TIME + \ + BLR_FDE_EVENT_BINLOG_EVENT_HDR_LEN) #define BLRM_CRYPTO_SCHEME_LENGTH 1 #define BLRM_KEY_VERSION_LENGTH 4 #define BLRM_IV_LENGTH AES_BLOCK_SIZE diff --git a/server/modules/routing/binlog/blr_file.c b/server/modules/routing/binlog/blr_file.c index c7bec9440..f05576e1a 100644 --- a/server/modules/routing/binlog/blr_file.c +++ b/server/modules/routing/binlog/blr_file.c @@ -474,7 +474,7 @@ blr_write_binlog_record(ROUTER_INSTANCE *router, REP_HEADER *hdr, uint32_t size, uint8_t *buf_ptr = buf + 4; /* 16 bytes after buf + 4 are owerwritten by XORed with IV */ /* Only 15 bytes are involved */ - for (int i=0; i < (AES_BLOCK_SIZE - 1); i++) + for (int i = 0; i < (AES_BLOCK_SIZE - 1); i++) { buf_ptr[i]= buf_ptr[i] ^ iv[i]; } diff --git a/server/modules/routing/binlog/blr_slave.c b/server/modules/routing/binlog/blr_slave.c index 655f29cf8..2201771cd 100644 --- a/server/modules/routing/binlog/blr_slave.c +++ b/server/modules/routing/binlog/blr_slave.c @@ -2328,16 +2328,7 @@ blr_slave_catchup(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, bool large) int events_before = slave->stats.n_events; /* Set file encryption context from slave pointer */ - spinlock_acquire(&slave->catch_lock); - if (slave->encryption_ctx) - { - file->encryption_ctx = slave->encryption_ctx; - } - else - { - file->encryption_ctx = NULL; - } - spinlock_release(&slave->catch_lock); + file->encryption_ctx = slave->encryption_ctx; while (burst-- && burst_size > 0 && (record = blr_read_binlog(router, file, slave->binlog_pos, &hdr, read_errmsg)) != NULL) @@ -5716,7 +5707,6 @@ bool blr_notify_waiting_slave(ROUTER_SLAVE *slave) static int blr_slave_read_ste(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, uint32_t fde_end_pos) { - BLFILE *file; REP_HEADER hdr; GWBUF *record, *head; uint8_t *ptr; @@ -5727,6 +5717,7 @@ blr_slave_read_ste(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, uint32_t fde_en memset(&hdr, 0, BINLOG_EVENT_HDR_LEN); + BLFILE *file; if ((file = blr_open_binlog(router, slave->binlogfile)) == NULL) { return 0; @@ -5754,10 +5745,16 @@ blr_slave_read_ste(ROUTER_INSTANCE *router, ROUTER_SLAVE *slave, uint32_t fde_en { uint8_t *record_ptr = GWBUF_DATA(record); SLAVE_ENCRYPTION_CTX *new_encryption_ctx = MXS_CALLOC(1, sizeof(SLAVE_ENCRYPTION_CTX)); + + if (!new_encryption_ctx) + { + return 0; + } record_ptr += BINLOG_EVENT_HDR_LEN; new_encryption_ctx->binlog_crypto_scheme = record_ptr[0]; // 1 Byte memcpy(&new_encryption_ctx->binlog_key_version, record_ptr + 1, BLRM_KEY_VERSION_LENGTH); memcpy(new_encryption_ctx->nonce, record_ptr + 1 + BLRM_KEY_VERSION_LENGTH, BLRM_NONCE_LENGTH); + /* Set the pos of first encrypted event */ new_encryption_ctx->first_enc_event_pos = fde_end_pos + hdr.event_size;