Bug #57108 mysqld crashes when I attempt to install plugin
Submitted: 29 Sep 2010 16:21 Modified: 17 Dec 2010 3:26
Reporter: Andrew Morgan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.5.6-rc OS:Linux (Fedora 13)
Assigned to: Mats Kindahl CPU Architecture:Any

[29 Sep 2010 16:21] Andrew Morgan
Description:
I am attempting to test asynchronous replication. I downloaded the "Linux - Generic 2.6 (x86, 32-bit), Compressed TAR Archive" and installed it.

I was successfully able to test replication to a second (virtual) machine.

My config file for the master is called master.cnf and is stored in /home/billy/mysql/master :

-rw-rw-r--. 1 billy billy  120 Sep 29 16:34 master.cnf

  [mysqld]
  server-id=1
  log-bin=master-bin.log
  datadir=/home/billy/mysql/master/data
  port=3306

When I attempted to install the plugin, I get an error and the mysqld crashes:

master> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
Could not open required defaults file: master.cnf
Fatal error in defaults handling. Program aborted
*** glibc detected *** mysqld: munmap_chunk(): invalid pointer: 0xbfc7e134 ***
======= Backtrace: =========
/lib/libc.so.6[0x1c11e1]
mysqld(my_free+0x1d)[0x857ae9d]
....

I will attach the full error.

How to repeat:
master> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
[29 Sep 2010 16:23] Andrew Morgan
Error text

Attachment: install_plugin_error.txt (text/plain), 7.46 KiB.

[29 Sep 2010 17:02] Andrew Morgan
I tried some more testing. It appears that this crash happens when the mysqld was started without giving the full path to the defaults file. 

i.e. When I start with "mysqld --defaults-file=master.cnf" the server takes these defaults and everything works fine until I try to install the plugin. When I start with "mysqld --defaults-file=/home/bill/mysql/master/master.cnf" the server takes these defaults and everything works fine - including when I install the plugin.
[30 Sep 2010 9:07] Zhenxing He
When the defaults file is a relative path, INSTALL PLUGIN command could cause the server to exit abnormally. The reason is that when server is starting, the working directory is set to the directory where the command is issued, while after server started, the working directory will be set to the directory of the data directory, which could be different from the directory where the server was started. And when using INSTALL PLUGIN to load a plugin, the server will call my_load_defaults() again to load the defaults file, which will result in file not found because of the change of working directory, and then server exits.
[21 Oct 2010 19:06] Paul DuBois
http://dev.mysql.com/doc/refman/5.1/en/option-files.html#option_general_defaults-file says:

"
--defaults-file=file_name

Use only the given option file. file_name is the full path name to the file. If the file does not exist or is otherwise inaccessible, the program will exit with an error.
"

So the option value according to the manual must be a full (absolute) path. It's a bit unfriendly that the server crashes, but the option as given is illegal.
[21 Oct 2010 19:16] 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/121562

3258 Mats Kindahl	2010-10-21
      BUG#57108: mysqld crashes when I attempt to install plugin
      
      If a relative path is supplied to option --defaults-file or
      --defaults-extra-file, the server will crash when executing
      an INSTALL PLUGIN command. The reason is that the defaults
      file is initially read relative the current working directory
      when the server is started, but when INSTALL PLUGIN is executed,
      the server has changed working directory to the data directory.
      
      The value given to --defaults-file and --defaults-extra-file
      have to be an absolute path, so this patch fixes the problem by
      adding a check that the path given to these options indeed is
      an absolute path, and throw an error and abort the start
      otherwise.
[22 Oct 2010 7:31] Mats Kindahl
By request from Sergei Golubchik and Alfranio Correia, a new patch will be created that will solve the problem by expanding the path supplied to --defaults-file and --defaults-extra-file to a full path using the working directory at the time the server is started as base.
[25 Oct 2010 20:03] 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/121865

3258 Mats Kindahl	2010-10-25
      BUG#57108: mysqld crashes when I attempt to install plugin
      
      If a relative path is supplied to option --defaults-file or
      --defaults-extra-file, the server will crash when executing
      an INSTALL PLUGIN command. The reason is that the defaults
      file is initially read relative the current working directory
      when the server is started, but when INSTALL PLUGIN is executed,
      the server has changed working directory to the data directory.
      Since there is no check that the call to my_load_defaults()
      inside mysql_install_plugin(), the subsequence call to
      free_defaults() will crash the server.
      
      This patch fixes the problem by:
      
      - Prepending the current working directory to the file name when
        a relative path is given to the --defaults-file or --defaults-
        extra-file option the first time my_load_defaults() is called,
        which is just after the server has started in main().
      
      - Adding a check of the return value of my_load_defaults() inside
        mysql_install_plugin() and aborting command (with an error) if
        an error is returned.
      
      To test that the relative files for the options --defaults-file and
      --defaults-extra-file is handled properly, mysql-test-run.pl is also
      changed to not add a --defaults-file option if one is provided in the
      tests *.opt file.
[4 Nov 2010 10:01] 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/122809

3258 Mats Kindahl	2010-11-04
      BUG#57108: mysqld crashes when I attempt to install plugin
      
      If a relative path is supplied to option --defaults-file or
      --defaults-extra-file, the server will crash when executing
      an INSTALL PLUGIN command. The reason is that the defaults
      file is initially read relative the current working directory
      when the server is started, but when INSTALL PLUGIN is executed,
      the server has changed working directory to the data directory.
      Since there is no check that the call to my_load_defaults()
      inside mysql_install_plugin(), the subsequence call to
      free_defaults() will crash the server.
      
      This patch fixes the problem by:
      
      - Prepending the current working directory to the file name when
        a relative path is given to the --defaults-file or --defaults-
        extra-file option the first time my_load_defaults() is called,
        which is just after the server has started in main().
      
      - Adding a check of the return value of my_load_defaults() inside
        mysql_install_plugin() and aborting command (with an error) if
        an error is returned.
      
      - It also adds a check of the return value for load_defaults in
        lib_sql.cc for the embedded server since that was missing.
      
      To test that the relative files for the options --defaults-file and
      --defaults-extra-file is handled properly, mysql-test-run.pl is also
      changed to not add a --defaults-file option if one is provided in the
      tests *.opt file.
[5 Nov 2010 15:13] 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/122978

3329 Mats Kindahl	2010-11-05 [merge]
      Merging patch for BUG#57108 into mysql-trunk-bugfixing.
[13 Nov 2010 15:17] Alexander Nozdrin
This patch introduced Bug#58173.
[13 Nov 2010 16:13] Bugs System
Pushed into mysql-trunk 5.6.99-m5 (revid:alexander.nozdrin@oracle.com-20101113155825-czmva9kg4n31anmu) (version source revid:alexander.nozdrin@oracle.com-20101113152450-2zzcm50e7i4j35v7) (merge vers: 5.6.1-m4) (pib:21)
[13 Nov 2010 16:36] Bugs System
Pushed into mysql-next-mr (revid:alexander.nozdrin@oracle.com-20101113160336-atmtmfb3mzm4pz4i) (version source revid:alexander.nozdrin@oracle.com-20101113152540-gxro4g0v29l27f5x) (pib:21)
[14 Dec 2010 20:08] Paul DuBois
Bug does not appear in any released 5.6.x version.

Setting report to Need Merge pending push to 5.5.x.
[16 Dec 2010 22:31] Bugs System
Pushed into mysql-5.5 5.5.9 (revid:jonathan.perkin@oracle.com-20101216101358-fyzr1epq95a3yett) (version source revid:jonathan.perkin@oracle.com-20101216101358-fyzr1epq95a3yett) (merge vers: 5.5.9) (pib:24)
[17 Dec 2010 3:26] Paul DuBois
Noted in 5.5.8 changelog.

If the file_name argument to the --defaults-file or
--defaults-extra-file option was not a full path name, it could be
interpreted incorrectly in some contexts and cause a server crash.
Now the file_name argument is intrepreted as relative to the current 
working directory if given as a relative path name rather than as a
full path name.
[11 Jan 2011 13:22] Bjørn Munch
The test added for this bug is broken, see Bug #59417