Bug #16887 Cursor causes server segfault
Submitted: 29 Jan 2006 23:40 Modified: 15 Mar 2006 14:45
Reporter: Ian Gulliver Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.1.5-alpha-max OS:Linux (Debian Etch)
Assigned to: Per-Erik Martin CPU Architecture:Any

[29 Jan 2006 23:40] Ian Gulliver
Description:
mysqld got signal 11;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.

key_buffer_size=8388600
read_buffer_size=131072
key_buffer_size=8388600
read_buffer_size=131072
max_used_connections=1
max_connections=100
threads_connected=1
It is possible that mysqld could use up to 
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_connections = 225791 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd=0x8b373b8
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
Cannot determine thread, fp=0xb5039368, backtrace may not be correct.
Stack range sanity check OK, backtrace follows: 
0x81941ec handle_segfault + 356
0xffffe420 _end + -140603792
0x828e7da _ZN9sp_cursor4openEP3THD + 66
0x828e7da _ZN9sp_cursor4openEP3THD + 66
0x828ba66 _ZN14sp_instr_copen9exec_coreEP3THDPj + 34
0x828aa12 _ZN13sp_lex_keeper23reset_lex_and_exec_coreEP3THDPjbP8sp_instr + 318
0x828b9e9 _ZN14sp_instr_copen7executeEP3THDPj + 73
0x82885bc _ZN7sp_head7executeEP3THD + 772
0x8289364 _ZN7sp_head17execute_procedureEP3THDP4ListI4ItemE + 972
0x81aee5f _Z21mysql_execute_commandP3THD + 19371
0x81b1356 _Z11mysql_parseP3THDPcj + 306
0x81a8e3a _Z16dispatch_command19enum_server_commandP3THDPcj + 1178
0x81a8965 _Z10do_commandP3THD + 129
0x81a7e6d handle_one_connection + 621
0xb7f1bcfd _end + -1349490867
0xb7e4213e _end + -1350382706
New value of fp=(nil) failed sanity check, terminating stack trace!
Please read http://dev.mysql.com/doc/mysql/en/Using_stack_trace.html and follow instructions on how to resolve the stack trace. Resolved
stack trace is much more helpful in diagnosing the problem, so please do
resolve it
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort...
thd->query at 0x8b56da0 = call parse_query_natural('foo bar')
thd->thread_id=1

How to repeat:
Relevant stored procedure is attached; sorry that I haven't been able to narrow down a more specific test case.
[29 Jan 2006 23:42] Ian Gulliver
Repeat SQL

Attachment: fulltext.sql.tmp (application/octet-stream, text), 2.00 KiB.

[3 Feb 2006 15:49] Per-Erik Martin
A slightly smaller test case:

create table t3 ( c varchar(1) )|

insert into t3 values
  (' '),('.'),(';'),(','),('-'),('_'),('('),(')'),('/'),('\\')|

create procedure bug16887()
begin
  declare i int default 10;

 again:
  while i > 0 do
  begin
    declare breakchar varchar(1);
    declare done int default 0;
    declare t3_cursor cursor for select c from t3;
    declare continue handler for not found set done = 1;

    set i = i - 1;
    select i;

    if i = 3 then
      iterate again;
    end if;

    open t3_cursor;

    loop
      fetch t3_cursor into breakchar;

      if done = 1 then
        begin
          close t3_cursor;
          iterate again;
        end;
      end if;
     end loop;
   end;
   end while;
end|

call bug16887()|
[15 Feb 2006 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/2638
[3 Mar 2006 18:42] Konstantin Osipov
Okayed to push the patch intact into 5.0.19.
Had some minor questions notes though, will ask to write a follow-up patch.
[7 Mar 2006 11:33] Per-Erik Martin
Pushed to 5.0.19 release tree, and 5.0.20 main tree.
[15 Mar 2006 14:45] Paul DuBois
Noted in 5.0.19, 5.1.8 changelogs.

Cursors in stored routines could cause a server crash. (Bug #16887)
[24 Apr 2006 7:06] Harish Pandia
Is this bug closed? We are planning to implement many functionalities in Stored Procedures and functions and hence will use cursor explicitly. Does this bug says 
"You can't use cursors in Stored Procedures, Functions".??