Bug #38293 Libmysqld crash in mysql_library_init if language file missing
Submitted: 22 Jul 2008 19:20 Modified: 8 Dec 2008 23:39
Reporter: Anders Karlsson Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Embedded Library ( libmysqld ) Severity:S3 (Non-critical)
Version:5.1.26 OS:Windows
Assigned to: Alexey Botchkov CPU Architecture:Any

[22 Jul 2008 19:20] Anders Karlsson
Description:
Libmysqld is very picky with arguments and if something goes wrong, typically the application will crash. One such case is when the lnguage parameters isn't set or the errmsg.ysy file cannot be found. In this case, mysql_library_init() will crash and never return to the application, at least on Windows.

How to repeat:
Create a data directory C:\mydata and a directory for a the errmsg.sys file, C:\mydata\language. Then copy the errmsg.sys file to the C:\mydata\language directory.

Compile and run the following program with Visual Studio .NET 2003, linking with libmysqld debug DLL library.

If you run it as is, it will work fine. If you then undefine SHOW_ERROR so that the language parameter isn't passed to mysql_library_init(), the program will crash inside mysql_library_init().

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <windows.h>
#include <mysql.h>
 
MYSQL *mysql;

#undef SHOW_ERROR
#ifdef SHOW_ERROR
static char *server_options[] = { "mysql_test", "--datadir=C:/mydata", NULL };
#else
static char *server_options[] = { "mysql_test", "--datadir=C:/mydata", "--language=C:/mydata/language", NULL };
#endif

int num_elements = sizeof(server_options)/ sizeof(char *) - 1;
 
static char *server_groups[] = { "libmysqld_server", NULL };

int main(int argc, char* argv[])
	{
	int retval;

   retval = mysql_library_init(num_elements, server_options, (char **) server_groups);
   mysql = mysql_init(NULL);
   mysql_options(mysql, MYSQL_OPT_USE_EMBEDDED_CONNECTION, NULL);
 
   mysql_real_connect(mysql, NULL,NULL,NULL, "test", 0, NULL, 0);
 
   mysql_close(mysql);
   mysql_library_end();
 
   return 0;
   }
[22 Jul 2008 23:40] MySQL Verification Team
This can be verified with the examples compiled with the embedded server:

C:\dbs\5.1\bin>mysql_embedded.exe
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 0
Server version: 5.1.28-nt-embedded-debug Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show variables like "%dir%";
+----------------------------+----------------------------------+
| Variable_name              | Value                            |
+----------------------------+----------------------------------+
| basedir                    | C:\dbs\5.1\                      |
| character_sets_dir         | C:\dbs\5.1\share\charsets\       |
| datadir                    | C:\dbs\5.1\data\                 |
| innodb_data_home_dir       |                                  |
| innodb_log_group_home_dir  | C:\dbs\5.1\data\                 |
| innodb_max_dirty_pages_pct | 90                               |
| plugin_dir                 | C:\dbs\5.1\lib/plugin            |
| tmpdir                     | C:\DOCUME~1\miguel\CONFIG~1\Temp |
+----------------------------+----------------------------------+
8 rows in set (0.00 sec)

Then rename share directory and start it again, below the call stack:

ntdll.dll!7c91b1fa() 	
ntdll.dll!7c9115a6() 	
ntdll.dll!7c9115a6() 	
kernel32.dll!7c8308bf() 	
libmysqld.dll!pthread_cond_init(pthread_cond_t * cond=0x00917760, const pthread_condattr_t * attr=0x100415d2)  Line 48 + 0x10	C
ntdll.dll!7c901046() 	
libmysqld.dll!_my_thread_var()  Line 378	C
libmysqld.dll!code_state()  Line 341 + 0x5	C
libmysqld.dll!_db_pop_()  Line 770 + 0xb	C
libmysqld.dll!mysql_server_end()  Line 214	C
libmysqld.dll!init_embedded_server(int argc=0, char * * argv=0x005cb380, char * * groups=0x0048e70c)  Line 512	C++
libmysqld.dll!mysql_server_init(int argc=0, char * * argv=0x005cb380, char * * groups=0x0048e70c)  Line 173 + 0x11	C
mysql_embedded.exe!main(int argc=1, char * * argv=0x00382970)  Line 1127 + 0x16	C++
mysql_embedded.exe!mainCRTStartup()  Line 259 + 0x19	C
kernel32.dll!7c817067()
[23 Jul 2008 1:48] MySQL Verification Team
Thank you for the bug report. I was able to repeat only on Windows using the embedded examples binaries.
[3 Oct 2008 11:09] 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/55219

2725 Alexey Botchkov	2008-10-03
      Bug #38293
[3 Oct 2008 13:49] 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/55260

2725 Alexey Botchkov	2008-10-03
      Bug #38293 Libmysqld crash in mysql_library_init if language file missing
      
      test commit 2
[6 Oct 2008 8:17] 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/55404

2751 Alexey Botchkov	2008-10-06
      Bug#38293 Libmysqld crash in mysql_library_init if language file missing
          That's a Win-specific error.
          When we create libmysqld.dll we have many libraries like mysys, dbug,
          strings, etc linked into that dll, so the application built upon
          this library shouldn't link these libraries to itself, rather use
          those inside the dll.
      
          Fixed by redirecting calls into the libmysqld.dll
      
      per-file comments:
        dbug/dbug.c
      Bug#38293 Libmysqld crash in mysql_library_init if language file missing
          fake _db_something definitions added
      
        include/my_dbug.h
      Bug#38293 Libmysqld crash in mysql_library_init if language file missing
        fake _db_something declarations added
      
        libmysqld/examples/CMakeLists.txt
      Bug#38293 Libmysqld crash in mysql_library_init if language file missing
          superfluous libraries removed from linking
      
        libmysqld/libmysqld.def
      Bug#38293 Libmysqld crash in mysql_library_init if language file missing
          set of mysys functions added to the export section
[23 Oct 2008 21:37] Michael Widenius
Patch looks ok.
Before pushing, if possible, fix the new multi-line comment in
include/my_dbug.h to be one comment. In other words, change:

/*  ...  */
/*  ...  */

To

/*
  ....
  ....
*/
[19 Nov 2008 11: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/59199

2751 Alexey Botchkov	2008-11-19
      Bug#38293 Libmysqld crash in mysql_library_init if language file missing
          That's a Win-specific error.
          When we create libmysqld.dll we have many libraries like mysys, dbug,
          strings, etc linked into that dll, so the application built upon
          this library shouldn't link these libraries to itself, rather use
          those inside the dll.
      
          Fixed by redirecting calls into the libmysqld.dll
      
      per-file comments:
        dbug/dbug.c
      Bug#38293 Libmysqld crash in mysql_library_init if language file missing
          fake _db_something definitions added
      
        include/my_dbug.h
      Bug#38293 Libmysqld crash in mysql_library_init if language file missing
        fake _db_something declarations added
      
        libmysqld/examples/CMakeLists.txt
      Bug#38293 Libmysqld crash in mysql_library_init if language file missing
          superfluous libraries removed from linking
      
        libmysqld/libmysqld.def
      Bug#38293 Libmysqld crash in mysql_library_init if language file missing
          set of mysys functions added to the export section
[19 Nov 2008 13:05] 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/59220

2718 Alexey Botchkov	2008-11-19
      Bug#38293 Libmysqld crash in mysql_library_init if language file missing
         additional fix - the 'debug' keyword removed
[8 Dec 2008 10:21] Bugs System
Pushed into 5.1.31  (revid:holyfoot@mysql.com-20081119115131-ww8dgviqqsoqz9uk) (version source revid:patrick.crews@sun.com-20081126180318-v685u61mpgoc176x) (pib:5)
[8 Dec 2008 11:31] Bugs System
Pushed into 6.0.9-alpha  (revid:holyfoot@mysql.com-20081119115131-ww8dgviqqsoqz9uk) (version source revid:ingo.struewing@sun.com-20081121151447-dtf2ofz2ys0zqed1) (pib:5)
[8 Dec 2008 23:39] Paul DuBois
Noted in 5.1.31, 6.0.9 changelog.

On Windows, the embedded server would crash in mysql_library_init()
if the language file was missing.
[19 Jan 2009 11:22] Bugs System
Pushed into 5.1.31-ndb-6.2.17 (revid:tomas.ulin@sun.com-20090119095303-uwwvxiibtr38djii) (version source revid:tomas.ulin@sun.com-20090108105244-8opp3i85jw0uj5ib) (merge vers: 5.1.31-ndb-6.2.17) (pib:6)
[19 Jan 2009 13:00] Bugs System
Pushed into 5.1.31-ndb-6.3.21 (revid:tomas.ulin@sun.com-20090119104956-guxz190n2kh31fxl) (version source revid:tomas.ulin@sun.com-20090119104956-guxz190n2kh31fxl) (merge vers: 5.1.31-ndb-6.3.21) (pib:6)
[19 Jan 2009 16:06] Bugs System
Pushed into 5.1.31-ndb-6.4.1 (revid:tomas.ulin@sun.com-20090119144033-4aylstx5czzz88i5) (version source revid:tomas.ulin@sun.com-20090119144033-4aylstx5czzz88i5) (merge vers: 5.1.31-ndb-6.4.1) (pib:6)