Bug #13012 SP: REPAIR/BACKUP/RESTORE TABLE crashes the server
Submitted: 6 Sep 2005 12:33 Modified: 7 Dec 2005 15:32
Reporter: Alexander Nozdrin Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S3 (Non-critical)
Version:5.0 BK source OS:Linux (SuSE 9.1)
Assigned to: Sergei Golubchik CPU Architecture:Any

[6 Sep 2005 12:33] Alexander Nozdrin
Description:
The following statements are allowed in stored procedures/functions and cause the crash:
  - REPAIR TABLE
  - BACKUP TABLE
  - RESTORE TABLE

How to repeat:
mysql> delimiter //
mysql> CREATE TABLE t1(c1 INT)//
Query OK, 0 rows affected (0.01 sec)
mysql> CREATE FUNCTION f5() RETURNS INT BEGIN REPAIR TABLE t1; RETURN 1; END//
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT f5() //
ERROR 2027 (HY000): Malformed packet

mysql> DROP FUNCTION IF EXISTS f5//
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE FUNCTION f5() RETURNS INT BEGIN BACKUP TABLE t1 TO '/tmp'; RETURN 1; END//
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT f5()//
ERROR 2027 (HY000): Malformed packet

mysql> DROP FUNCTION IF EXISTS f5//
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE FUNCTION f5() RETURNS INT BEGIN RESTORE TABLE t1 FROM '/tmp'; RETURN 1; END//
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT f5()//
ERROR 2027 (HY000): Malformed packet

Suggested fix:
These statements should be forbidden from use in stored procedures/functions.
[6 Sep 2005 12:51] MySQL Verification Team
Thank you for the bug report.

miguel@hegel:~/dbs/5.0> bin/mysql -uroot test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 5.0.13-beta-debug

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

mysql> delimiter //
mysql> CREATE TABLE t1(c1 INT)//
Query OK, 0 rows affected (0.06 sec)

mysql> CREATE FUNCTION f5() RETURNS INT BEGIN REPAIR TABLE t1; RETURN 1; END//
Query OK, 0 rows affected (0.02 sec)

mysql> SELECT f5() //
ERROR 2027 (HY000): Malformed packet
mysql> DROP FUNCTION IF EXISTS f5//
Packets out of order (Found: 5, expected 1)
ERROR 2013 (HY000): Lost connection to MySQL server during query
mysql> 

050906  9:47:50 [Note] /home/miguel/dbs/5.0/libexec/mysqld: ready for connections.
Version: '5.0.13-beta-debug'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
[New Thread 1132456880 (LWP 6573)]
mysqld: protocol.cc:833: virtual bool Protocol_simple::store_long(long long int): Assertion `field_types == 0 || field_types[field_pos] == MYSQL_TYPE_INT24 || field_types[field_pos] == MYSQL_TYPE_LONG' failed.

Program received signal SIGABRT, Aborted.
[Switching to Thread 1132456880 (LWP 6573)]
0xffffe410 in ?? ()
(gdb)
[21 Nov 2005 19:27] Konstantin Osipov
Serg, for 5.0, as discussed, we will disable these commands.
I will review the patch.
[2 Dec 2005 15:10] Konstantin Osipov
Approved by email, with small notes.
In 5.0 we will disable these statements in Stored Procedures.
A worklog task WL#3000 to fix them has been created and tentatively scheduled for 5.1.
[2 Dec 2005 21:59] 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/internals/32984
[2 Dec 2005 22:13] Konstantin Osipov
Serg, finally we reached some agreement.
I will review your patch, and I hope that before 5.0.17.
Meanwhile, I hope you don't mind if Alik pushes his patch ASAP -- it's better to return an error than 'Packets out of order', and I'm not at all sure that your patch is correct (see my comments to WL#3000, LLD).
[2 Dec 2005 22:41] Konstantin Osipov
Reviewed by email, a problem with the submitted patch has been discovered.
[3 Dec 2005 14:02] 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/internals/32994
[7 Dec 2005 12:45] 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/internals/33125
[7 Dec 2005 15:32] Paul DuBois
Noted in 5.0.17 changelog.

I've also added the three statements to the list
of prohibited statements in the "restrictions"
chapter.