From c85f83fa2b1e9d5b51c062dd3427d0a1d58dbffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 23 Jan 2018 09:26:22 +0200 Subject: [PATCH] Fix strcpy overlap in binlogrouter The source and destination buffers could overlap which is why an intermediate buffer is required. --- server/modules/routing/binlogrouter/blr_file.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/modules/routing/binlogrouter/blr_file.c b/server/modules/routing/binlogrouter/blr_file.c index 3950faf83..746cb98a6 100644 --- a/server/modules/routing/binlogrouter/blr_file.c +++ b/server/modules/routing/binlogrouter/blr_file.c @@ -421,7 +421,12 @@ blr_file_create(ROUTER_INSTANCE *router, char *file) { close(router->binlog_fd); spinlock_acquire(&router->binlog_lock); - strcpy(router->binlog_name, file); + + /// Use an intermediate buffer in case the source and destination overlap + char new_binlog[strlen(file) + 1]; + strcpy(new_binlog, file); + strcpy(router->binlog_name, new_binlog); + router->binlog_fd = fd; router->current_pos = BINLOG_MAGIC_SIZE; /* Initial position after the magic number */ router->binlog_position = BINLOG_MAGIC_SIZE;