From: Date: February 15 2006 5:10pm Subject: bk commit into 5.0 tree (msvensson:1.2049) BUG#17261 List-Archive: http://lists.mysql.com/commits/2655 X-Bug: 17261 Message-Id: <20060215161027.855B95454F@devsrv-b.mysql.com> Below is the list of changes that have just been committed into a local 5.0 repository of msvensson. When msvensson does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.2049 06/02/15 17:10:20 msvensson@stripped +5 -0 Bug#17261 Passing a variable from a stored procedure to UDF crashes mysqld - Pass "buffers[i]" to val_str() in udf_handler::fix_fields insteead of NULL. - Add testcase for UDF that will load and run the udf_example functions if available mysql-test/t/udf.test 1.1 06/02/15 17:10:16 msvensson@stripped +94 -0 New BitKeeper file ``mysql-test/t/udf.test'' mysql-test/t/udf.test 1.0 06/02/15 17:10:16 msvensson@stripped +0 -0 BitKeeper file /space/magnus/bug17261/my50-bug17261/mysql-test/t/udf.test mysql-test/r/udf.result 1.1 06/02/15 17:10:15 msvensson@stripped +86 -0 New BitKeeper file ``mysql-test/r/udf.result'' mysql-test/r/have_udf.require 1.1 06/02/15 17:10:15 msvensson@stripped +1 -0 New BitKeeper file ``mysql-test/r/have_udf.require'' mysql-test/r/udf.result 1.0 06/02/15 17:10:15 msvensson@stripped +0 -0 BitKeeper file /space/magnus/bug17261/my50-bug17261/mysql-test/r/udf.result mysql-test/r/have_udf.require 1.0 06/02/15 17:10:15 msvensson@stripped +0 -0 BitKeeper file /space/magnus/bug17261/my50-bug17261/mysql-test/r/have_udf.require sql/udf_example.cc 1.19 06/02/15 17:10:10 msvensson@stripped +1 -1 Spelling error"on"->"one" sql/item_func.cc 1.274 06/02/15 17:10:10 msvensson@stripped +1 -1 Instead of passing a NULL pointer into val_str, use the "buffers" array to provide a temp string buffer. # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: msvensson # Host: devsrv-b.mysql.com # Root: /space/magnus/bug17261/my50-bug17261 --- 1.273/sql/item_func.cc 2006-02-07 13:21:41 +01:00 +++ 1.274/sql/item_func.cc 2006-02-15 17:10:10 +01:00 @@ -2606,7 +2606,7 @@ switch(arguments[i]->type()) { case Item::STRING_ITEM: // Constant string ! { - String *res=arguments[i]->val_str((String *) 0); + String *res=arguments[i]->val_str(&buffers[i]); if (arguments[i]->null_value) continue; f_args.args[i]= (char*) res->ptr(); --- 1.18/sql/udf_example.cc 2004-12-21 11:37:40 +01:00 +++ 1.19/sql/udf_example.cc 2006-02-15 17:10:10 +01:00 @@ -518,7 +518,7 @@ { if (!args->arg_count) { - strcpy(message,"myfunc_double must have at least on argument"); + strcpy(message,"myfunc_double must have at least one argument"); return 1; } /* --- New file --- +++ mysql-test/r/have_udf.require 06/02/15 17:10:15 CREATE FUNCTION metaphon RETURNS STRING SONAME 'udf_example.so'; --- New file --- +++ mysql-test/r/udf.result 06/02/15 17:10:15 drop table if exists t1; CREATE FUNCTION metaphon RETURNS STRING SONAME 'udf_example.so'; CREATE FUNCTION myfunc_double RETURNS REAL SONAME 'udf_example.so'; CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME 'udf_example.so'; ERROR HY000: Can't find function 'myfunc_int_init' in library CREATE FUNCTION sequence RETURNS INTEGER SONAME "udf_example.so"; CREATE FUNCTION lookup RETURNS STRING SONAME 'udf_example.so'; CREATE FUNCTION reverse_lookup RETURNS STRING SONAME 'udf_example.so'; CREATE AGGREGATE FUNCTION avgcost RETURNS REAL SONAME 'udf_example.so'; select myfunc_double(); ERROR HY000: myfunc_double must have at least on argument select myfunc_double(1); myfunc_double(1) 49.00 select myfunc_double(78654); myfunc_double(78654) 54.00 select myfunc_int(); ERROR 42000: FUNCTION test.myfunc_int does not exist select lookup(); ERROR HY000: Wrong arguments to lookup; Use the source select lookup("127.0.0.1"); lookup("127.0.0.1") 127.0.0.1 select lookup(127,0,0,1); ERROR HY000: Wrong arguments to lookup; Use the source select lookup("localhost"); lookup("localhost") 127.0.0.1 select reverse_lookup(); ERROR HY000: Wrong number of arguments to reverse_lookup; Use the source select reverse_lookup("127.0.0.1"); reverse_lookup("127.0.0.1") localhost select reverse_lookup(127,0,0,1); reverse_lookup(127,0,0,1) localhost select reverse_lookup("localhost"); reverse_lookup("localhost") NULL select avgcost(); ERROR HY000: wrong number of arguments: AVGCOST() requires two arguments select avgcost(100,23.76); ERROR HY000: wrong argument type: AVGCOST() requires an INT and a REAL create table t1(sum int, price float(24)); insert into t1 values(100, 50.00), (100, 100.00); select avgcost(sum, price) from t1; avgcost(sum, price) 75.0000 delete from t1; insert into t1 values(100, 54.33), (200, 199.99); select avgcost(sum, price) from t1; avgcost(sum, price) 151.4367 drop table t1; select metaphon('hello'); metaphon('hello') HL CREATE PROCEDURE `XXX1`(in testval varchar(10)) begin select metaphon(testval); end// call XXX1('hello'); metaphon(testval) HL drop procedure xxx1; CREATE PROCEDURE `XXX2`() begin declare testval varchar(10); set testval = 'hello'; select metaphon(testval); end// call XXX2(); metaphon(testval) HL drop procedure xxx2; DROP FUNCTION metaphon; DROP FUNCTION myfunc_double; DROP FUNCTION myfunc_int; ERROR 42000: FUNCTION test.myfunc_int does not exist DROP FUNCTION sequence; DROP FUNCTION lookup; DROP FUNCTION reverse_lookup; DROP FUNCTION avgcost; --- New file --- +++ mysql-test/t/udf.test 06/02/15 17:10:16 --source include/have_udf.inc # # To run this tests you need to compile "sql/udf_example.cc" into # udf_example.so and setup LD_LIBRARY_PATH to point out where # the library are. # --disable_warnings drop table if exists t1; --enable_warnings # # Create the example functions from udf_example # CREATE FUNCTION metaphon RETURNS STRING SONAME 'udf_example.so'; CREATE FUNCTION myfunc_double RETURNS REAL SONAME 'udf_example.so'; # myfunc_int does not have a myfunc_int_init function and can # not be loaded unless server is started with --allow-suspicious-udfs --error 1127 CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME 'udf_example.so'; CREATE FUNCTION sequence RETURNS INTEGER SONAME "udf_example.so"; CREATE FUNCTION lookup RETURNS STRING SONAME 'udf_example.so'; CREATE FUNCTION reverse_lookup RETURNS STRING SONAME 'udf_example.so'; CREATE AGGREGATE FUNCTION avgcost RETURNS REAL SONAME 'udf_example.so'; select myfunc_double(); select myfunc_double(1); select myfunc_double(78654); select myfunc_int(); select lookup(); select lookup("127.0.0.1"); select lookup(127,0,0,1); select lookup("localhost"); select reverse_lookup(); select reverse_lookup("127.0.0.1"); select reverse_lookup(127,0,0,1); select reverse_lookup("localhost"); select avgcost(); select avgcost(100,23.76); create table t1(sum int, price float(24)); insert into t1 values(100, 50.00), (100, 100.00); select avgcost(sum, price) from t1; delete from t1; insert into t1 values(100, 54.33), (200, 199.99); select avgcost(sum, price) from t1; drop table t1; #------------------------------------------------------------------------ # BUG#17261 Passing a variable from a stored procedure to UDF crashes mysqld #------------------------------------------------------------------------ select metaphon('hello'); delimiter //; CREATE PROCEDURE `XXX1`(in testval varchar(10)) begin select metaphon(testval); end// delimiter ;// call XXX1('hello'); drop procedure xxx1; delimiter //; CREATE PROCEDURE `XXX2`() begin declare testval varchar(10); set testval = 'hello'; select metaphon(testval); end// delimiter ;// call XXX2(); drop procedure xxx2; # # Drop the example functions from udf_example # DROP FUNCTION metaphon; DROP FUNCTION myfunc_double; --error 1305 DROP FUNCTION myfunc_int; DROP FUNCTION sequence; DROP FUNCTION lookup; DROP FUNCTION reverse_lookup; DROP FUNCTION avgcost;