Bug #53942 valgrind warnings with timestamp() function and incomplete datetime values
Submitted: 24 May 2010 12:13 Modified: 14 Oct 2010 15:32
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Data Types Severity:S3 (Non-critical)
Version:5.0.91,5.1.47,5.6.99-m4 OS:Any
Assigned to: Sergei Glukhov CPU Architecture:Any
Tags: timestamp, valgrind

[24 May 2010 12:13] Shane Bester
Description:
5.1.47 valgrind output:

Conditional jump or move depends on uninitialised value(s)
at: Item_func_add_time::val_str (item_timefunc.cc:2806)
by: Item::get_time (item.cc:959)
by: Item::save_time_in_field (item.cc:329)
by: Item_func_add_time::save_in_field (item_timefunc.h:921)
by: Item_result_field::save_in_result_field (item.h:2175)
by: copy_funcs(Item**)
by: end_write (sql_select.cc:12424)
by: evaluate_join_record (sql_select.cc:11447)
by: sub_select (sql_select.cc:11321)
by: do_select (sql_select.cc:11077)
by: JOIN::exec (sql_select.cc:1907)
by: mysql_select (sql_select.cc:2509)
by: handle_select (sql_select.cc:269)
by: execute_sqlcom_select (sql_parse.cc:5067)
by: mysql_execute_command (sql_parse.cc:2263)
by: mysql_parse (sql_parse.cc:5986)
by: dispatch_command (sql_parse.cc:1233)
by: do_command (sql_parse.cc:874)
by: handle_one_connection (sql_connect.cc:1134)
by: start_thread (in /lib64/libpthread-2.5.so)
by: clone 
 Uninitialised value was created by a stack allocation
   at 0x57BDCC: Item_func_add_time::val_str(String*) (item_timefunc.cc:2794)

How to repeat:
will make testcase later.
[24 May 2010 12:46] MySQL Verification Team
run mysqld under valgrind:
valgrind --tool=memcheck --read-var-info=yes \ 
--track-origins=yes --leak-check=full --db-attach=yes \
--num-callers=50 -v --show-reachable=yes  ./bin/mysqld \ 
--no-defaults --basedir=. --datadir=./data \
--skip-name-resolve  --skip-grant-tables --skip-name-resolve 

Testcase:

drop table if exists `t1`;
create table `t1`(`a` time)engine=myisam;
insert into `t1` values ('23:38:57');
select timestamp(`a`,'1') from `t1`;
[24 May 2010 13:57] MySQL Verification Team
On OpenSuse X86_64:

00524 10:54:27 [Note] ./bin/mysqld: ready for connections.
Version: '5.0.92-valgrind-max-debug'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution
--20989-- REDIR: 0x5d8def0 (realloc) redirected to 0x4c26c69 (realloc)
--20989-- REDIR: 0x5d93b70 (memmove) redirected to 0x4c28290 (memmove)
==20989== Thread 10:
==20989== Conditional jump or move depends on uninitialised value(s)
==20989==    at 0x5A7858: Item_func_add_time::val_str(String*) (item_timefunc.cc:2837)
==20989==    by 0x55D1D7: Item::get_time(st_mysql_time*) (item.cc:929)
==20989==    by 0x55971B: Item::send(Protocol*, String*) (item.cc:5215)
==20989==    by 0x5CF320: select_send::send_data(List<Item>&) (sql_class.cc:1072)
==20989==    by 0x63092C: end_send(JOIN*, st_join_table*, bool) (sql_select.cc:11762)
==20989==    by 0x63F8FE: do_select(JOIN*, List<Item>*, st_table*, Procedure*) (sql_select.cc:10607)
==20989==    by 0x651BC2: JOIN::exec() (sql_select.cc:2177)
==20989==    by 0x64C823: mysql_select(THD*, Item***, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) (sql_select.cc:2366)
==20989==    by 0x651DCB: handle_select(THD*, st_lex*, select_result*, unsigned long) (sql_select.cc:257)
==20989==    by 0x5FB6D2: mysql_execute_command(THD*) (sql_parse.cc:2921)
==20989==    by 0x5FC243: mysql_parse(THD*, char const*, unsigned int, char const**) (sql_parse.cc:6470)
==20989==    by 0x5FD462: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1966)
==20989==    by 0x5FF145: handle_one_connection (sql_parse.cc:1647)
==20989==    by 0x5455A3E: start_thread (in /lib64/libpthread-2.11.1.so)
==20989==  Uninitialised value was created by a stack allocation
==20989==    at 0x5A77C8: Item_func_add_time::val_str(String*) (item_timefunc.cc:2826)
[24 May 2010 13:59] MySQL Verification Team
Thank you for the bug report.
[28 May 2010 7:28] 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/109447

3399 Sergey Glukhov	2010-05-28
      Bug#53942 valgrind warnings with timestamp() function and incomplete datetime values
      Field_time::get_date method does not initialize MYSQL_TIME::time_type field.
      The fix is to init this field.
     @ mysql-test/r/type_time.result
        test case
     @ mysql-test/t/type_time.test
        test case
     @ sql/field.cc
        --init MYSQL_TIME::time_type field in Field_time::get_date method
        --removed duplicated code in Field_time::get_time method
[31 May 2010 9:25] 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/109592

3402 Sergey Glukhov	2010-05-31
      Bug#53942 valgrind warnings with timestamp() function and incomplete datetime values
      Field_time::get_date method does not initialize MYSQL_TIME::time_type field.
      The fix is to init this field.
     @ mysql-test/r/type_time.result
        test case
     @ mysql-test/t/type_time.test
        test case
     @ sql/field.cc
        --use Field_time::get_time in Field_time::get_date
        --removed duplicated code in Field_time::get_date method
[2 Jun 2010 8:51] Bugs System
Pushed into 5.1.48 (revid:georgi.kodinov@oracle.com-20100602084411-2yu607bslbmgufl3) (version source revid:sergey.glukhov@sun.com-20100531092511-sbm69fz2tko1rdz3) (merge vers: 5.1.47) (pib:16)
[4 Jun 2010 2:11] Paul DuBois
Noted in 5.1.48 changelog.

Valgrind warnings resulting from passing incomplete DATETIME values
to the TIMESTAMP() function were corrected.

Setting report to Need Merge pending further pushes.
[17 Jun 2010 6:15] Bugs System
Pushed into 5.5.5-m3 (revid:alexey.kopytov@sun.com-20100615145247-8bj0vmuqlotbqsn9) (version source revid:sergey.glukhov@sun.com-20100531093810-taorogtf0iii4xdm) (merge vers: 5.5.5-m3) (pib:16)
[17 Jun 2010 6:19] Bugs System
Pushed into mysql-next-mr (revid:alik@sun.com-20100615150216-cubqoyn1fj9b6a2p) (version source revid:vasil.dimov@oracle.com-20100513074652-0cvlhgkesgbb2bfh) (pib:16)
[21 Jun 2010 19:27] Paul DuBois
Noted in 5.5.5 changelog.
[14 Oct 2010 8:33] Bugs System
Pushed into mysql-5.1-telco-7.0 5.1.51-ndb-7.0.20 (revid:martin.skold@mysql.com-20101014082627-jrmy9xbfbtrebw3c) (version source revid:vasil.dimov@oracle.com-20100513074652-0cvlhgkesgbb2bfh) (merge vers: 5.5.5-m3) (pib:21)
[14 Oct 2010 8:49] Bugs System
Pushed into mysql-5.1-telco-6.3 5.1.51-ndb-6.3.39 (revid:martin.skold@mysql.com-20101014083757-5qo48b86d69zjvzj) (version source revid:vasil.dimov@oracle.com-20100513074652-0cvlhgkesgbb2bfh) (merge vers: 5.5.5-m3) (pib:21)
[14 Oct 2010 9:03] Bugs System
Pushed into mysql-5.1-telco-6.2 5.1.51-ndb-6.2.19 (revid:martin.skold@mysql.com-20101014084420-y54ecj85j5we27oa) (version source revid:vasil.dimov@oracle.com-20100513074652-0cvlhgkesgbb2bfh) (merge vers: 5.5.5-m3) (pib:21)
[14 Oct 2010 15:32] Jon Stephens
Already documented in the 5.1.48 changelog; no new changelog entries required. Setting back to Closed state.