Bug #50801 CHANGE MASTER accepts bogus variables
Submitted: 1 Feb 2010 19:47 Modified: 4 Feb 2012 10:34
Reporter: Kris Buytaert (Candidate Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Replication Severity:S1 (Critical)
Version:5.1.43 OS:Linux (CentOS 5.4)
Assigned to: Sven Sandberg CPU Architecture:Any
Tags: CHANGE MASTER, replication

[1 Feb 2010 19:47] Kris Buytaert
Description:
echo 'CHANGE MASTER TO MASTER_LOG_FILE='\''XMS-1-bin.000049'\'', MASTER_LOG_POS=106, MASTER_USER='\''noneof'\'',MASTER_PASSWORD='\''yourbusiness'\'',MASTER_HOST='\''172.16.0.1
172.16.0.101
172.16.0.102'\'''
++ /usr/bin/mysql -u no -pReally -h 172.16.0.2

~                                                                               
~
Apparently MySQL Accepts this change master and turns it into : 

mysql> show slave status\G 
*************************** 1. row ***************************
               Slave_IO_State: 
                  Master_Host: 172.16.0.1
172.16.0.101
172.16.0.102
                  Master_User: repli
                  Master_Port: 3306
                Connect_Retry: 60
  

How to repeat:
echo 'CHANGE MASTER TO MASTER_LOG_FILE='\''XMS-1-bin.000049'\'', MASTER_LOG_POS=106, MASTER_USER='\''noneof'\'',MASTER_PASSWORD='\''yourbusiness'\'',MASTER_HOST='\''172.16.0.1
172.16.0.101
172.16.0.102'\'''
++ /usr/bin/mysql -u no -pReally -h 172.16.0.2

~                                                                               
~

mysql> show slave status\G 
*************************** 1. row ***************************
               Slave_IO_State: 
                  Master_Host: 172.16.0.1
172.16.0.101
172.16.0.102
                  Master_User: repli
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: XMS-1-bin.000049
          Read_Master_Log_Pos: 106
               Relay_Log_File: XMS-2-relay.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: XMS-1-bin.000049
             Slave_IO_Running: No
            Slave_SQL_Running: No
              Replicate_Do_DB: xpol
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 106
              Relay_Log_Space: 106
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
  Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
1 row in set (0.00 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.0.1
172.16.0.101
172.16.0.102
                  Master_User: repli
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: XMS-1-bin.000049
          Read_Master_Log_Pos: 106
               Relay_Log_File: XMS-2-relay.000002
                Relay_Log_Pos: 251
        Relay_Master_Log_File: XMS-1-bin.000049
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: xpol
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 106
              Relay_Log_Space: 402
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
            Master_SSL_Cipher:
               Master_SSL_Key:
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
1 row in set (0.00 sec)

Restarting mysql however turns it in something worse 

mysql> show slave status\G 
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    6
Current database: *** NONE ***

*************************** 1. row ***************************
               Slave_IO_State: Connecting to master
                  Master_Host: 172.16.0.1
                  Master_User: 172.16.0.101
                  Master_Port: 0
                Connect_Retry: 0
              Master_Log_File: XMS-1-bin.000049
          Read_Master_Log_Pos: 106
               Relay_Log_File: XMS-2-relay.000003
                Relay_Log_Pos: 4
        Relay_Master_Log_File: XMS-1-bin.000049
             Slave_IO_Running: No
            Slave_SQL_Running: Yes
              Replicate_Do_DB: xpol
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 106
              Relay_Log_Space: 106
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: Yes
           Master_SSL_CA_File: 60
           Master_SSL_CA_Path: 0
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 2003
                Last_IO_Error: error connecting to master '172.16.0.101@172.16.0.1:0' - retry-time: 0  retries: 86400
               Last_SQL_Errno: 0
               Last_SQL_Error: 
1 row in set (0.00 sec)

As you can see the Master_Host and Master_User entries have wrapped .. 

Suggested fix:
Adding a multiple line MASTER_HOST values should cause an error.
After a restart, the values should be identical,
[1 Feb 2010 22:21] Sveta Smirnova
Thank you for the report.

Verified as described.
[4 Feb 2010 22:34] Davi Arnaut
FWIW, there is no overflow. It's just that the code that reads the info files stops at newline.
[4 Feb 2012 10:34] Jon Stephens
Thank you for your bug report. This issue has been committed to our source repository of that product and will be incorporated into the next release.

If necessary, you can access the source repository and build the latest available version, including the bug fix. More information about accessing the source trees is available at

    http://dev.mysql.com/doc/en/installing-source.html
[4 Feb 2012 10:35] Jon Stephens
Fixed in 5.6. Documented as follows in the 5.6.5 changelog:

        The CHANGE MASTER TO statement was not checked for invalid
        characters in parameter values such as MASTER_HOST and
        MASTER_USER. In addition, when the server was restarted, a value
        containing certain characters was trimmed, causing the loss of
        its original value. Now such values are validated, and in cases
        where the value contains invalid characters, including linefeed
        (\n) characters, the statement fails with an error
        (ER_MASTER_INFO).

Also noted the change in the description of CHANGE MASTER TO in the 5.6 Manual.

Closed.