Bug #17261 Passing a variable from a stored procedure to UDF crashes mysqld
Submitted: 9 Feb 2006 4:10 Modified: 22 Mar 2006 17:27
Reporter: Dmitry Apresian Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.18 OS:Linux (Fedora Core 4)
Assigned to: Magnus Blåudd CPU Architecture:Any

[9 Feb 2006 4:10] Dmitry Apresian
Description:
When a UDF that takes one or more string parameters is called from a stored procedure with a local variable as parameter, mysqld crashes

How to repeat:
1. Create a UDF function that takes a string argument (can use metaphon from udf_example)
2. Create a stored procedure like this:

CREATE PROCEDURE `XXX1`(in testval varchar(10))
begin 
select metaphon(testval); 
end

call XXX1('hello');

or like this

CREATE PROCEDURE `XXX2`()
begin 
declare testval varchar(10);
set testval = 'hello';
select metaphon(testval); 
end

call XXX2();

Suggested fix:
I have found a workaround where instead of calling with the variable directly I call substring(testval, 1) and that works, but it shouldn't be necessary.
[9 Feb 2006 7:29] Jorge del Conde
Thanks for your bug report.  Reproduced following the udf example found here: 
http://dev.mysql.com/doc/refman/5.0/en/udf-compiling.html
[15 Feb 2006 13:19] Magnus Blåudd
Found these two interesting comments in our online reference manual.

"Anthony Ball on April 21 2003 10:36am
After much time trying to track a problem on solaris(2.7, gcc 2.9-gnupro-99r1) I found that I needed -c -shared as compiler options. Almost everything worked without the -c, but strangely, any time I tried to use double quoted strings in the code they got turned into empty strings."

"Leonard Cuff on August 3 2005 1:02am
On Mac OS X 10.4 (Tiger), the following incantations were needed, in
order to build a "shared object" file.

export MACOSX_DEPLOYMENT_TARGET="10.4"
gcc -c myfunction.c
gcc -bundle -o myfunction.so myfunction.o -undefined dynamic_lookup
"
[15 Feb 2006 16:10] 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/2655
[15 Feb 2006 16: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/2656
[21 Feb 2006 13:23] Magnus Blåudd
Related to bug#11835
[10 Mar 2006 9:41] 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/3687
[22 Mar 2006 11:32] Magnus Blåudd
Pushed a patch to 5.0.20 and 5.1.8 that passes a pointer to a buffer instead of a NULL pointer to the function val_str in item_func.cc

Also pushed test cases for udf's. So to test wheter your server can handle udf's, run "cd mysql-test; ./mysql-test-run.pl --do-test=udf". The test should pass if udf's are supported and working and will be skipped if udf's are not supported by the mysqld.
[22 Mar 2006 17:27] Mike Hillyer
Documented:

      <listitem>
        <para>
          Stored procedures that call UDFs and pass local string
          variables caused server crashes. (Bug #17261)
        </para>
      </listitem>
[5 Apr 2006 9:13] Alexander Nozdrin
BUG#18193 has been marked as a duplicate of this bug.