Fix strcpy overlap in binlogrouter

The source and destination buffers could overlap which is why an
intermediate buffer is required.
This commit is contained in:
Markus Mäkelä 2018-01-23 09:26:22 +02:00
parent c893e354a9
commit c85f83fa2b

View File

@ -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;