Bug #32007 select udf_function() doesn't return an error if error during udf initialization
Submitted: 31 Oct 2007 21:20 Modified: 9 Nov 2007 0:14
Reporter: Konstantin Osipov (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Errors Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: Konstantin Osipov CPU Architecture:Any

[31 Oct 2007 21:20] Konstantin Osipov
Description:
See udf.test in the main test suite:
--error 0
select myfunc_double();

And in the result file:

select myfunc_double();
ERROR HY000: myfunc_double must have at least one argument

That is, the error is converted to a warning.

See also Bug#31178.

How to repeat:
Run udf.test

Suggested fix:
===== sql/item_func.cc 1.425 vs edited =====
--- 1.425/sql/item_func.cc	2007-10-30 20:08:11 +03:00
+++ edited/sql/item_func.cc	2007-10-31 18:47:08 +03:00
@@ -2897,6 +2897,7 @@ udf_handler::fix_fields(THD *thd, Item_r
 
   if (u_d->func_init)
   {
+    char init_msg_buff[MYSQL_ERRMSG_SIZE];
     char *to=num_buffer;
     for (uint i=0; i < arg_count; i++)
     {
@@ -2949,10 +2950,10 @@ udf_handler::fix_fields(THD *thd, Item_r
     }
     thd->net.last_error[0]=0;
     Udf_func_init init= u_d->func_init;
-    if ((error=(uchar) init(&initid, &f_args, thd->net.last_error)))
+    if ((error=(uchar) init(&initid, &f_args, init_msg_buff)))
     {
       my_error(ER_CANT_INITIALIZE_UDF, MYF(0),
-               u_d->name.str, thd->net.last_error);
+               u_d->name.str, init_msg_buff);
       free_udf(u_d);
       DBUG_RETURN(TRUE);
     }

What happens is:
net.last_error buffer is used to store the temporary message.
Then, when we call my_error, we look at net.last_error and conclude that
there is already an error in the error stack, and do not overwrite it.
However, thd->net.report_error is not set, so the error does not abort the select.
Later the error is available as a warning.
[31 Oct 2007 21:32] 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/36807

ChangeSet@1.2608, 2007-11-01 00:31:57+03:00, kostja@bodhi.(none) +3 -0
  A fix for Bug#32007 select udf_function() doesn't return an error if error
  during udf initialization. The bug is spotted while working on Bug 12713.
  
  If a user-defined function was used in a SELECT statement, and an
  error would occur during UDF initialization, this error would not terminate
  execution of the SELECT, but rather would be converted to a warning.
  
  The fix is to use a stack buffer to store the message from udf_init instead
  of private my_error() buffer.
[31 Oct 2007 21:40] Konstantin Osipov
Approved on IRC.
[7 Nov 2007 21:59] Bugs System
Pushed into 6.0.4-alpha
[7 Nov 2007 22:00] Bugs System
Pushed into 5.1.23-rc
[9 Nov 2007 0:14] Paul Dubois
Noted in 5.1.23, 6.0.4 changelogs.