Bug #59234 cmdline clients crash --defaults-extra-file with no .cnf or .ini extension
Submitted: 30 Dec 2010 16:37 Modified: 21 Apr 2011 0:54
Reporter: Alfredo Kojima Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.5.8 OS:Any
Assigned to: Nirbhay Choubey CPU Architecture:Any
Triage: Triaged: D1 (Critical)

[30 Dec 2010 16:37] Alfredo Kojima
Description:
If an invalid path is passed to --defaults-extra-file for mysqldump or mysql cmdline client, they crash with a bus error:

kojima@Woodstock wb52$ mysqldump --defaults-extra-file=x
Bus error
kojima@Woodstock wb52$ mysql --defaults-extra-file=x
Bus error
kojima@Woodstock wb52$ mysqldump --defaults-extra-file=/etc/my.cnf
Usage: mysqldump [OPTIONS] database [tables]
OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR     mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help

How to repeat:
Run mysql or mysqldump with a non-existing value to --defaults-extra-file
[30 Dec 2010 16:42] Alfredo Kojima
On further testing, the crash actually occurs when any path with an extension that is not .ini or .cnf is passed, regardless of the existence of the file:

kojima@Woodstock wb52$ /usr/local/mysql/bin/mysqldump --defaults-extra-file=bad.ini
Could not open required defaults file: /Users/kojima/Development/mysql-workbench-5.2/bad.ini
Fatal error in defaults handling. Program aborted
kojima@Woodstock wb52$ /usr/local/mysql/bin/mysqldump --defaults-extra-file=bad.cnf
Could not open required defaults file: /Users/kojima/Development/mysql-workbench-5.2/bad.cnf
Fatal error in defaults handling. Program aborted
kojima@Woodstock wb52$ /usr/local/mysql/bin/mysqldump --defaults-extra-file=bad
Bus error

kojima@Woodstock wb52$ cp /etc/my.cnf good.ini
kojima@Woodstock wb52$ cp /etc/my.cnf good.cnf
kojima@Woodstock wb52$ cp /etc/my.cnf good
kojima@Woodstock wb52$ /usr/local/mysql/bin/mysqldump --defaults-extra-file=good
Bus error
kojima@Woodstock wb52$ /usr/local/mysql/bin/mysqldump --defaults-extra-file=good.ini
Usage: mysqldump [OPTIONS] database [tables]
OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR     mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help
kojima@Woodstock wb52$ /usr/local/mysql/bin/mysqldump --defaults-extra-file=good.cnf
Usage: mysqldump [OPTIONS] database [tables]
OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR     mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help
[30 Dec 2010 16:49] Miguel Solorzano
Verified on Windows with 5.5.9 version too.
[30 Dec 2010 16:51] Miguel Solorzano
Call Stack:

mysqldump.exe!fn_format(char * to=0x0000000002735ba8, const char * name=0x0000000000000706, const char * dir=0x0000000002776920, const char * extension=0x000000000000003e, unsigned int flag=196)  Line 77 + 0x9 bytes	
mysqldump.exe!my_search_option_files(const char * conf_file=0x000000013f965028, int * argc=0x0000000000000008, char * * * argv=0x000000000019f940, unsigned int * args_used=0x000000000019f940, int (void *, const char *, const char *)* func=0x000000013f890af0, void * func_ctx=0x000000000019f7d0, const char * * default_directories=0x0000000002776710)  Line 227 + 0x42 bytes	
mysqldump.exe!my_load_defaults(const char * conf_file=0x000000000019f948, const char * * groups=0x0000000000000000, int * argc=0x000000000019f940, char * * * argv=0x0000000000000000, const char * * * default_directories=0x000000013fbe4ef0)  Line 552 + 0x47 bytes	
mysqldump.exe!load_defaults(const char * conf_file=0x01cba84966089ab0, const char * * groups=0x0000000000da7a64, int * argc=0x0000a9a141097bb0, char * * * argv=0x0064007200000000)  Line 454	
mysqldump.exe!get_options(int * argc=0x00780065002e0070, char * * * argv=0x0000000000000000)  Line 891 + 0x24 bytes	
mysqldump.exe!main(int argc=0, char * * argv=0x0000000000000000)  Line 5156 + 0xf bytes	
mysqldump.exe!__tmainCRTStartup()  Line 266 + 0x12 bytes	
kernel32.dll!BaseThreadInitThunk()  + 0xd bytes	
ntdll.dll!RtlUserThreadStart()  + 0x21 bytes
[24 Jan 2011 16: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/129467

3271 Nirbhay Choubey	2011-01-24
      Bug#59234 : cmdline clients crash --defaults-extra-file with
                  no .cnf or .ini extension.
      
      Standard mysql clients crash when they are started with
      defaults-extra-file command line option with file having
      no extension.
      
      Crash (or segfault) was noticed as 'NULL' was getting passed
      to the strlen function in case of filename with no extension.
      
      Fixed by passing a zero-sized string instead of NULL.
     @ mysql-test/r/mysqladmin.result
        Added a test case for bug#59234.
     @ mysql-test/t/mysqladmin.test
        Added a test case for bug#59234.
     @ mysys/default.c
        Bug#59234 : cmdline clients crash --defaults-extra-file with
                    no .cnf or .ini extension.
        
        When clients were started with defaults-extra-file option with
        file having no extension, strlen was getting called with NULL.
        Fixed by using a zero length string instead of NULL.
[9 Feb 2011 15:32] Valeriy Kravchuk
Bug #59401 was marked as a duplicate of this one.
[25 Feb 2011 17:34] Valeriy Kravchuk
Bug #60238 was marked as a duplicate of this one.
[25 Feb 2011 17:36] Valeriy Kravchuk
Bug #60255 was marked as a duplicate of this one.
[21 Apr 2011 0:54] Paul Dubois
Noted in 5.5.11, 5.6.3 changelogs.

An invalid pathname argument for the --defaults-extra-file option of 
MySQL programs caused a program crash.  

CHANGESET - http://lists.mysql.com/commits/133206