Bug #16829 Firing trigger crashes the server
Submitted: 27 Jan 2006 7:55 Modified: 10 Feb 2006 21:01
Reporter: Kai Voigt Email Updates:
Status: Closed Impact on me:
Category:MySQL Server Severity:S1 (Critical)
Version:5.0.18/5.0.19 BK OS:Mac OS X (MacOSX, WinNT, Linux)
Assigned to: Dmitry Lenev

[27 Jan 2006 7:55] Kai Voigt
Putting an BEFORE INSERT TRIGGER on a simple table that is having "RETURN NULL" inside, crashes the server when being fired.

How to repeat:
root@localhost [test]> CREATE TABLE data (Id INT, Value CHAR(32));
Query OK, 0 rows affected (0.01 sec)

root@localhost [test]> DELIMITER //
root@localhost [test]> CREATE TRIGGER data_before_insert BEFORE INSERT ON data FOR EACH ROW if NEW.Id < 0 THEN RETURN NULL; END IF; //
Query OK, 0 rows affected (0.01 sec)

root@localhost [test]> DELIMITER ;
root@localhost [test]> INSERT INTO data VALUES (-1, "negativ");
ERROR 2013 (HY000): Lost connection to MySQL server during query
[27 Jan 2006 11:16] Miguel Solorzano
Thank you for the bug report.

030427  9:14:49 [Note] /home/miguel/dbs/5.0/libexec/mysqld: ready for connections.
Version: '5.0.19-debug'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
[New Thread 1131862960 (LWP 5600)]
mysqld: sp_rcontext.cc:155: bool sp_rcontext::set_return_value(THD*, Item*): Assertion `m_return_value_fld' failed.

Program received signal SIGABRT, Aborted.
[Switching to Thread 1131862960 (LWP 5600)]
0xffffe410 in __kernel_vsyscall ()
(gdb) bt full
#0  0xffffe410 in __kernel_vsyscall ()
No symbol table info available.
#1  0x4021d541 in raise () from /lib/tls/libc.so.6
No symbol table info available.
#2  0x4021edbb in abort () from /lib/tls/libc.so.6
No symbol table info available.
#3  0x40216925 in __assert_fail () from /lib/tls/libc.so.6
[28 Jan 2006 9:50] 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:

[9 Feb 2006 9:58] Dmitry Lenev
Fixed in versions 5.0.19 and 5.1.7.

RETURN statement is disallowed in triggers. One should use LEAVE statement to immideately leave trigger instead. Since RETURN statement was not working before this change (it was causing crashes) we don't take away any functionality.
[10 Feb 2006 21:01] Paul Dubois
Noted in 5.0.19, 5.1.7 changelogs.

          A <literal>RETURN</literal> statement within a trigger caused
          a server crash. <literal>RETURN</literal> now is disallowed
          within triggers. To exit immediately, use
          <literal>LEAVE</literal>. (Bug #16829)