Bug #6081 executing mysql_create_db from PHP 5.02 ISAPI results in access violation
Submitted: 14 Oct 2004 5:50 Modified: 22 Oct 2004 19:13
Reporter: Casual Programmer Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1g OS:Windows (windows xp, sp2/Linux)
Assigned to: Dmitry Lenev CPU Architecture:Any

[14 Oct 2004 5:50] Casual Programmer
Description:
when executing the example from the php manual:

<?php
   $link = mysql_pconnect("localhost", "root", "mysqladmin")
       or die("Could not connect: " . mysql_error());

   if (mysql_create_db("my_db")) {
       print ("Database created successfully\n");
   } else {
       printf ("Error creating database: %s\n", mysql_error());
   }
?>

mysql crashes wit an access violation:

Ereignistyp:	Fehler
Ereignisquelle:	Application Error
Ereigniskategorie:	(100)
Ereigniskennung:	1000
Datum:		14.10.2004
Zeit:		07:25:00
Benutzer:		Nicht zutreffend
Computer:	WORKSTATION1
Beschreibung:
Fehlgeschlagene Anwendung mysqld-nt.exe, Version 0.0.0.0, fehlgeschlagenes Modul mysqld-nt.exe, Version 0.0.0.0, Fehleradresse 0x00081ba0.

Weitere Informationen über die Hilfe- und Supportdienste erhalten Sie unter http://go.microsoft.com/fwlink/events.asp.
Daten:
0000: 41 70 70 6c 69 63 61 74   Applicat
0008: 69 6f 6e 20 46 61 69 6c   ion Fail
0010: 75 72 65 20 20 6d 79 73   ure  mys
0018: 71 6c 64 2d 6e 74 2e 65   qld-nt.e
0020: 78 65 20 30 2e 30 2e 30   xe 0.0.0
0028: 2e 30 20 69 6e 20 6d 79   .0 in my
0030: 73 71 6c 64 2d 6e 74 2e   sqld-nt.
0038: 65 78 65 20 30 2e 30 2e   exe 0.0.
0040: 30 2e 30 20 61 74 20 6f   0.0 at o
0048: 66 66 73 65 74 20 30 30   ffset 00
0050: 30 38 31 62 61 30         081ba0  

After restarting mysql, it reports the new db as existent.

This is a "hard" error, always reproducible.

Using mysql_query("CREATE DATABASE") works fine, so this is not urgent.

Configuration is Windows XP, SP2, IIS 5.1, PHP 5.02 ISAPI, mySQL 4.1G

Casual

How to repeat:
Just run example code.

Suggested fix:
N/A
[14 Oct 2004 17:29] MySQL Verification Team
mysql_create_db is a deprecated function, so the client library needs to
be compiled according the below ifdef from libmysql.c:

#ifdef USE_OLD_FUNCTIONS
int  STDCALL
mysql_create_db(MYSQL *mysql, const char *db)
{
  DBUG_ENTER("mysql_createdb");
  DBUG_PRINT("enter",("db: %s",db));
  DBUG_RETURN(simple_command(mysql,COM_CREATE_DB,db, (ulong) strlen(db),0));
}

int  STDCALL
mysql_drop_db(MYSQL *mysql, const char *db)
{
  DBUG_ENTER("mysql_drop_db");
  DBUG_PRINT("enter",("db: %s",db));
  DBUG_RETURN(simple_command(mysql,COM_DROP_DB,db,(ulong) strlen(db),0));
}
#endif
[14 Oct 2004 18:16] Casual Programmer
Hi Miguel,

thanks for commenting. Actually I think deprecated code should be honored for backward compatibility and in no case should using deprecated code lead to the crash of the DB server. 

Also I have neither means nor intention to compile mySQL or PHP by myself.

I suggest, that both mySQL and PHP go ahead and supply binaries that are tolerant to deprecated or even plain erroneus code.

Casual
[14 Oct 2004 18:43] MySQL Verification Team
Sorry, I just understood that your application crashed..I will test
this if the server in fact crashs. Thank you for the warning.
[14 Oct 2004 23:48] Hartmut Holzgraefe
verified on linux using PHP 4 built against the bundled 3.23 client lib
[15 Oct 2004 0:58] MySQL Verification Team
How to repeat:

Compile the mysqlclient library and the application application with:

USE_OLD_FUNCTIONS

/sql/sql_db.cc
--245--

static bool write_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create)
{
  register File file;
  char buf[256]; // Should be enough for one option
  bool error=1;

  if (!create->default_table_charset)
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    create->default_table_charset= thd->variables.collation_server;

call stack:

mysqld.exe!write_db_opt(THD * thd=0x02eb9300, const char * path=0x0557fa74, st_ha_create_information * create=0x00000000)  Line 251 + 0x3	C++
mysqld.exe!mysql_create_db(THD * thd=0x02eb9300, char * db=0x00e68218, st_ha_create_information * create_info=0x00000000, int silent=0)  Line 437 + 0x14	C++
mysqld.exe!dispatch_command(enum_server_command command=COM_CREATE_DB, THD * thd=0x02eb9300, char * packet=0x02eba699, unsigned int packet_length=6)  Line 1570 + 0x37	C++
mysqld.exe!do_command(THD * thd=0x02eb9300)  Line 1271 + 0x31	C++
mysqld.exe!handle_one_connection(void * arg=0x02eb9300)  Line 1015 + 0x9	C++
mysqld.exe!pthread_start(void * param=0x00e6d600)  Line 63 + 0x7	C
mysqld.exe!_threadstart(void * ptd=0x00e6ff48)  Line 173 + 0xd	C
kernel32.dll!7c80b50b() 	
kernel32.dll!7c8399f3() 	
mysqld.exe!mysql_load(THD * thd=0x0072006f, sql_exchange * ex=0x0061006d, st_table_list * table_list=0x0053006c, List<Item> & fields={...}, enum_duplicates handle_duplicates=101, int read_file_from_client=7077991, thr_lock_type lock_type=6422639)  Line 163 + 0x16	C++
mysqld.exe!mysql_load(THD * thd=0xcc017501, sql_exchange * ex=0xd285d233, st_table_list * table_list=0xb0a1a775, List<Item> & fields={...}, enum_duplicates handle_duplicates=-1065024288, int read_file_from_client=12944655, thr_lock_type lock_type=74055680)  Line 163 + 0x16	C++
f88314c4()
[17 Oct 2004 10:01] Dmitry Lenev
ChangeSet
  1.2107 04/10/17 13:59:46 dlenev@brandersnatch.localdomain +2 -0
  Fix for bug #6081 "Call to deprecated mysql_create_db() function crashes
  server".
[22 Oct 2004 19:13] Dmitry Lenev
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

Fix will be in 4.1.7

Also the problem with erroneus call to mysql_create_db()/mysql_drop_db() stalling connection 
which was exposed during work on this bug was fixed in 4.0.