Commit 14c4d0d7 authored by unknown's avatar unknown
Browse files

A fix for bug#4368 '"like" fails in PreparedStatement, crashes

server': the bug occurs when arguments of LIKE function are in 
differentcharacter sets. If these character sets are compatible, 
we create an item-converter. In prepared mode, this item
needs to be created in memory of current prepared statement.


mysql-test/r/ps.result:
  Test for Bug#4368 added.
mysql-test/t/ps.test:
  A test case for bug#4368 '"like" fails in PreparedStatement, 
  crashes server'.
parent 6a5f9b41
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -259,3 +259,14 @@ execute `
1234
1234
set names default;
create table t1 (a varchar(10)) charset=utf8;
insert into t1 (a) values ('yahoo');
set character_set_connection=latin1;
prepare stmt from 'select a from t1 where a like ?';
set @var='google';
execute stmt using @var;
a
execute stmt using @var;
a
deallocate prepare stmt;
drop table t1;
+17 −0
Original line number Diff line number Diff line
@@ -261,3 +261,20 @@ execute `
set names default;


# 
# BUG#4368 "select * from t1 where a like ?" crashes server if a is in utf8
# and ? is in latin1
# Check that Item converting latin1 to utf8 (for LIKE function) is created
# in memory of prepared statement.
#

create table t1 (a varchar(10)) charset=utf8;
insert into t1 (a) values ('yahoo');
set character_set_connection=latin1;
prepare stmt from 'select a from t1 where a like ?';
set @var='google';
execute stmt using @var;
execute stmt using @var;
deallocate prepare stmt;
drop table t1;
+13 −2
Original line number Diff line number Diff line
@@ -211,9 +211,20 @@ void Item_bool_func2::fix_length_and_dec()
      }
      else
      {
	conv= new Item_func_conv_charset(args[weak],args[strong]->collation.collation);
        THD *thd= current_thd;
        /*
          In case we're in statement prepare, create conversion item
          in its memory: it will be reused on each execute.
        */
        Item_arena *arena= thd->current_arena, backup;
        if (arena->is_stmt_prepare())
          thd->set_n_backup_item_arena(arena, &backup);
	conv= new Item_func_conv_charset(args[weak],
                                         args[strong]->collation.collation);
        if (arena->is_stmt_prepare())
          thd->restore_backup_item_arena(arena, &backup);
        conv->collation.set(args[weak]->collation.derivation);
        conv->fix_fields(current_thd, 0, &conv);
        conv->fix_fields(thd, 0, &conv);
      }
      args[weak]= conv ? conv : args[weak];
    }