Bug #54580 plugin with a name starting like an existing option causes wrong parsing
Submitted: 17 Jun 2010 10:54 Modified: 17 Jun 2010 14:36
Reporter: Giuseppe Maxia Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Parser Severity:S3 (Non-critical)
Version:5.1.49-bzr OS:Any
Assigned to: CPU Architecture:Any
Tags: Options, parser, plugin

[17 Jun 2010 10:54] Giuseppe Maxia
Description:
When a plugin name starts with the name of an existing option, the parser mistakenly tries to use that plugin from options in the my.cnf file.

For example, if your plugin is called "user_example", the server will try to assign to it the contents of the "user" option in your my.cnf

For example:
mysql> INSTALL PLUGIN user_example SONAME 'ha_example.so'; 
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> show warnings;
+---------+------+--------------------------------------------------------------+
| Level   | Code | Message                                                      |
+---------+------+--------------------------------------------------------------+
| Warning | 1123 | Can't initialize function 'user_example'; Plugin is disabled |
+---------+------+--------------------------------------------------------------+
1 row in set (0.00 sec)

and, in the error log:

100617 12:18:03 [ERROR] /PATH/TO/libexec/mysqld: ambiguous option '--user=mysql' (user-example, user-example-ulong-var)
100617 12:18:03 [ERROR] Parsing options for plugin 'user_example' failed.

Notice that, after the failure, if you restart the server, the plugin works as expected. But users will not know that they need to reinstall, as the error is not with the plugin, but with the parser.

How to repeat:
1. Get the source for the latest MySQL 5.1.
2. in ./storage/example/ha_example.cc, change line 897 ("EXAMPLE") to "user_example"
3. compile and install
4. add to your my.cnf the lines
   [mysqld]
   user=mysql
   # change the user according to your installation
5. install the plugin

mysql> INSTALL PLUGIN user_example SONAME 'ha_example.so'; 
 
6. inspect the error log

Suggested fix:
Make sure the parser does not pick a partial match when installing a plugin.
[17 Jun 2010 14:36] Valeriy Kravchuk
Verified just as described with recent 5.1.49 from bzr on Mac OS X:

valeriy-kravchuks-macbook-pro:5.1 openxs$ bin/mysqld_safe --user=openxs &
[1] 56075
valeriy-kravchuks-macbook-pro:5.1 openxs$ 100617 17:32:17 mysqld_safe Logging to '/Users/openxs/dbs/5.1/var/macbook-pro.err'.
100617 17:32:17 mysqld_safe Starting mysqld daemon with databases from /Users/openxs/dbs/5.1/var

valeriy-kravchuks-macbook-pro:5.1 openxs$ bin/mysql -uroot testWelcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.49-debug Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> INSTALL PLUGIN user_example SONAME 'ha_example.so'; 
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> show warnings\G
*************************** 1. row ***************************
  Level: Warning
   Code: 1123
Message: Can't initialize function 'user_example'; Plugin is disabled
1 row in set (0.00 sec)

mysql> exit
Bye
valeriy-kravchuks-macbook-pro:5.1 openxs$ tail -150 var/macbook-pro.err 
...
100617 17:32:17 mysqld_safe Starting mysqld daemon with databases from /Users/openxs/dbs/5.1/var
100617 17:32:17 [Warning] Setting lower_case_table_names=2 because file system for /Users/openxs/dbs/5.1/var/ is case insensitive
100617 17:32:17 [Note] Plugin 'FEDERATED' is disabled.
100617 17:32:17 [Note] Plugin 'ndbcluster' is disabled.
100617 17:32:17  InnoDB: Started; log sequence number 0 9660187
100617 17:32:17 [Note] Event Scheduler: Loaded 0 events
100617 17:32:17 [Note] /Users/openxs/dbs/5.1/libexec/mysqld: ready for connections.
Version: '5.1.49-debug'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
100617 17:32:35 [ERROR] /Users/openxs/dbs/5.1/libexec/mysqld: ambiguous option '--user=openxs' (user-example, user-example-ulong-var)
100617 17:32:35 [ERROR] Parsing options for plugin 'user_example' failed.