summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authordkatz@damien-katzs-computer.local <>2007-08-05 21:37:55 -0400
committerdkatz@damien-katzs-computer.local <>2007-08-05 21:37:55 -0400
commita933f28a937dd8e6b547a68c94b1baedd3a5ff2d (patch)
tree9172987b105bf8879768d7b8a20358ca9da23be1 /sql
parent3fe2098964a0c6b8c5bc2534db260dcdddb7d246 (diff)
downloadmariadb-git-a933f28a937dd8e6b547a68c94b1baedd3a5ff2d.tar.gz
Bug #29804 UDF parameters don't contain correct string length
Previously, UDF *_init functions were passed constant strings with erroneous lengths. The length came from the containing variable's size, not the length of the value itself. Now the *_init functions get the constant as a null terminated string with the correct length supplied.
Diffstat (limited to 'sql')
-rw-r--r--sql/item_func.cc3
-rw-r--r--sql/udf_example.c35
2 files changed, 37 insertions, 1 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 9a26169ad30..4492b7519aa 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -2916,7 +2916,8 @@ udf_handler::fix_fields(THD *thd, Item_result_field *func,
String *res= arguments[i]->val_str(&buffers[i]);
if (arguments[i]->null_value)
continue;
- f_args.args[i]= (char*) res->ptr();
+ f_args.args[i]= (char*) res->c_ptr();
+ f_args.lengths[i]= res->length();
break;
}
case INT_RESULT:
diff --git a/sql/udf_example.c b/sql/udf_example.c
index b603464568e..5165a577555 100644
--- a/sql/udf_example.c
+++ b/sql/udf_example.c
@@ -1106,4 +1106,39 @@ char * is_const(UDF_INIT *initid, UDF_ARGS *args __attribute__((unused)),
}
+my_bool check_const_len_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
+{
+ if (args->arg_count != 1)
+ {
+ strmov(message, "IS_CONST accepts only one argument");
+ return 1;
+ }
+ if (args->args[0] == 0)
+ {
+ initid->ptr= "Not constant";
+ }
+ else if(strlen(args->args[0]) == args->lengths[0])
+ {
+ initid->ptr= "Correct length";
+ }
+ else
+ {
+ initid->ptr= "Wrong length";
+ }
+ initid->max_length = 100;
+ return 0;
+}
+
+char * check_const_len(UDF_INIT *initid, UDF_ARGS *args __attribute__((unused)),
+ char *result, unsigned long *length,
+ char *is_null, char *error __attribute__((unused)))
+{
+ strmov(result, initid->ptr);
+ *length= strlen(result);
+ *is_null= 0;
+ return result;
+}
+
+
+
#endif /* HAVE_DLOPEN */