MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:kgeorge Date:January 18 2007 3:33pm
Subject:bk commit into 5.0 tree (gkodinov:1.2380) BUG#25382
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of kgeorge. When kgeorge 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@stripped, 2007-01-18 17:33:38+02:00, gkodinov@stripped +3 -0
  Bug #25382: Passing NULL to an UDF called from stored procedures 
   crashes server
   Check for null value is reliable only after calling some of the 
   val_xxx() methods. If the val_xxx() method is not called
   the null_value flag will be set only for certain types of NULL
   values (like SQL constant NULLs for example).
   This caused a crash while trying to dereference a NULL pointer
   that is returned by val_str() for NULL values.
   Fixed by swapping the order of val_xxx() and null_value check.

  mysql-test/r/udf.result@stripped, 2007-01-18 17:33:31+02:00, gkodinov@stripped +34 -0
    Bug #25382: Passing NULL to an UDF called from stored procedures 
     crashes server
     - test case

  mysql-test/t/udf.test@stripped, 2007-01-18 17:33:32+02:00, gkodinov@stripped +47 -0
    Bug #25382: Passing NULL to an UDF called from stored procedures 
     crashes server
     - test case

  sql/item_func.cc@stripped, 2007-01-18 17:33:33+02:00, gkodinov@stripped +6 -3
    Bug #25382: Passing NULL to an UDF called from stored procedures 
     crashes server
     - reliably check null_value

# 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:	gkodinov
# Host:	macbook.gmz
# Root:	/Users/kgeorge/mysql/work/B25382-5.0-opt

--- 1.321/sql/item_func.cc	2007-01-09 22:23:11 +02:00
+++ 1.322/sql/item_func.cc	2007-01-18 17:33:33 +02:00
@@ -2729,25 +2729,28 @@ udf_handler::fix_fields(THD *thd, Item_r
 
       if (arguments[i]->const_item())
       {
-        if (arguments[i]->null_value)
-          continue;
-
         switch (arguments[i]->result_type()) 
         {
         case STRING_RESULT:
         case DECIMAL_RESULT:
         {
           String *res= arguments[i]->val_str(&buffers[i]);
+          if (arguments[i]->null_value)
+            continue;
           f_args.args[i]= (char*) res->ptr();
           break;
         }
         case INT_RESULT:
           *((longlong*) to)= arguments[i]->val_int();
+          if (arguments[i]->null_value)
+            continue;
           f_args.args[i]= to;
           to+= ALIGN_SIZE(sizeof(longlong));
           break;
         case REAL_RESULT:
           *((double*) to)= arguments[i]->val_real();
+          if (arguments[i]->null_value)
+            continue;
           f_args.args[i]= to;
           to+= ALIGN_SIZE(sizeof(double));
           break;

--- 1.10/mysql-test/r/udf.result	2006-12-15 11:38:24 +02:00
+++ 1.11/mysql-test/r/udf.result	2007-01-18 17:33:31 +02:00
@@ -240,3 +240,37 @@ drop table bug18761;
 select is_const((1,2,3));
 ERROR 21000: Operand should contain 1 column(s)
 drop function if exists is_const;
+CREATE FUNCTION metaphon RETURNS STRING SONAME "UDF_EXAMPLE_LIB";
+CREATE FUNCTION myfunc_double RETURNS REAL SONAME "UDF_EXAMPLE_LIB";
+CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "UDF_EXAMPLE_LIB";
+create function f1(p1 varchar(255))
+returns varchar(255)
+begin
+return metaphon(p1);
+end//
+create function f2(p1 varchar(255))
+returns double
+begin
+return myfunc_double(p1);
+end//
+create function f3(p1 varchar(255))
+returns double
+begin
+return myfunc_int(p1);
+end//
+select f3(NULL);
+f3(NULL)
+0
+select f2(NULL);
+f2(NULL)
+NULL
+select f1(NULL);
+f1(NULL)
+NULL
+drop function f1;
+drop function f2;
+drop function f3;
+drop function metaphon;
+drop function myfunc_double;
+drop function myfunc_int;
+End of 5.0 tests.

--- 1.11/mysql-test/t/udf.test	2006-12-15 11:38:24 +02:00
+++ 1.12/mysql-test/t/udf.test	2007-01-18 17:33:32 +02:00
@@ -242,3 +242,50 @@ drop table bug18761;
 select is_const((1,2,3));
 
 drop function if exists is_const;
+
+#
+# Bug #25382: Passing NULL to an UDF called from stored procedures 
+# crashes server
+#
+--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
+eval CREATE FUNCTION metaphon RETURNS STRING SONAME "$UDF_EXAMPLE_LIB";
+
+--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
+eval CREATE FUNCTION myfunc_double RETURNS REAL SONAME "$UDF_EXAMPLE_LIB";
+
+--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB
+eval CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "$UDF_EXAMPLE_LIB";
+
+delimiter //;
+create function f1(p1 varchar(255))
+returns varchar(255)
+begin
+  return metaphon(p1);
+end//
+
+create function f2(p1 varchar(255))
+returns double
+begin
+  return myfunc_double(p1);
+end//
+
+create function f3(p1 varchar(255))
+returns double
+begin
+  return myfunc_int(p1);
+end//
+
+delimiter ;//
+
+select f3(NULL);
+select f2(NULL);
+select f1(NULL);
+
+drop function f1;
+drop function f2;
+drop function f3;
+drop function metaphon;
+drop function myfunc_double;
+drop function myfunc_int;
+
+--echo End of 5.0 tests.
Thread
bk commit into 5.0 tree (gkodinov:1.2380) BUG#25382kgeorge18 Jan