Bug #30164 Using client side macro inside server side comments generates broken queries
Submitted: 31 Jul 2007 23:31 Modified: 29 Oct 2007 19:56
Reporter: Marc ALFF Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S2 (Serious)
Version:4.1 bk, 5.0 bk, 5.1 bk OS:Any
Assigned to: Alexey Kopytov CPU Architecture:Any

[31 Jul 2007 23:31] Marc ALFF
Description:
Using queries like :
  /*!\C cp932 */; select 1;

confuses the client, which emits broken queries to the server.

It happens that the server accept them (which is wrong, see Bug#28779).

Also note that this syntax is used by the binary log, as in for example:

/*!\C latin1 *//*!*/;
SET @@session.character_set_client=8, @@session.collation_connection=8, @@session.collation_server=8/*!*/;

How to repeat:
--exec $MYSQL --default-character-set=utf8 test -e "/*!\C cp932 */; select 1; "

see the master.log file, it contains invalid queries.

Time                 Id Command    Argument
070801  2:25:07       1 Connect     root@localhost on test
                      2 Connect     root@localhost on test
                      2 Query       select @@version_comment limit 1
                      2 Query       SET NAMES cp932

That's wrong :
                      2 Query       /*! select 1

                      2 Quit
                      1 Quit
                      3 Connect     root@localhost on
                      3 Query       SHOW VARIABLES LIKE 'pid_file'
                      3 Shutdown

Suggested fix:
Because old binary logs must be readable, this syntax must be supported.
The command line client must understand it, and generate *well formed* queries
to the server. This is a pre-requisite for fixing Bug#28779
[1 Aug 2007 7:48] Sveta Smirnova
Thank you for the report.

verified as described. All versions are affected.
[21 Aug 2007 17:03] Timothy Smith
I think the most direct approach is to accept simple forms of this syntax, but to restrict it to single commands.  This should keep compatibility with mysqlbinlog, and older dumps which might be sitting on tape somewhere.  The restriction is reasonable, and since it appears that the more complex forms have never worked properly, this should not cause any problems.
[24 Aug 2007 14:11] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/33027

ChangeSet@1.2517, 2007-08-24 18:11:41+04:00, kaa@polly.local +3 -0
  Bug #30164: Using client side macro inside server side comments generates broken queries
  
  Problem:
  
  In cases when a client-side macro appears inside a server-side comment, the add_line() function in mysql.cc discarded all characters until the next delimiter to remove macro arguments from the query string. This resulted in broken queries being sent to the server when the next delimiter character appeared past the comment's boundaries, because the comment closing sequence ('*/') was discarded.
  
  Fix:
  
  If a client-side macro appears inside a server-side comment, discard all characters in the comment after the macro (that is, until the end of the comment rather than the next delimiter).
  This is a minimal fix to allow only simple cases used by the mysqlbinlog utility. Limitations that are worth documenting:
  
  - Nested server-side and/or client-side comments are not supported by mysql.cc
  - Using client-side macros in multi-line server-side comments is not supported
  - All characters after a client-side macro in a server-side comment will be omitted from the query string (and thus, will not be sent to server).
[30 Aug 2007 8:55] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/33427

ChangeSet@1.2506, 2007-08-30 12:53:24+04:00, kaa@polly.(none) +3 -0
  Bug #30164: Using client side macro inside server side comments generates broken queries
    
  Problem:
    
  In cases when a client-side macro appears inside a server-side comment, the add_line() function in mysql.cc discarded all characters until the next delimiter to remove macro arguments from the query string. This resulted in broken queries being sent to the server when the next delimiter character appeared past the comment's boundaries, because the comment closing sequence ('*/') was discarded.
    
  Fix:
    
  If a client-side macro appears inside a server-side comment, discard all characters in the comment after the macro (that is, until the end of the comment rather than the next delimiter).
  This is a minimal fix to allow only simple cases used by the mysqlbinlog utility. Limitations that are worth documenting:
    
  - Nested server-side and/or client-side comments are not supported by mysql.cc
  - Using client-side macros in multi-line server-side comments is not supported
  - All characters after a client-side macro in a server-side comment will be omitted from the query string (and thus, will not be sent to server).
[30 Aug 2007 13:26] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/33437

ChangeSet@1.2507, 2007-08-30 17:21:43+04:00, kaa@polly.(none) +1 -0
  Use double quotes instead of single ones which make the test fail on Windows. This is for bug #30164.
[7 Sep 2007 8:09] Bugs System
Pushed into 5.1.23-beta
[7 Sep 2007 8:10] Bugs System
Pushed into 5.0.50
[29 Oct 2007 19:56] Paul DuBois
Noted in 5.0.50, 5.1.23 changelogs.

Short-format mysql commands embedded within /*! ... */ comments were
parsed incorrectly by mysql, which discarded the rest of the comment
including the terminating */ characters. The result was a malformed
(unclosed) comment. Now mysql does not discard the */ characters.