Bug #20784 Uninitialized memory in update on table with PK not on first column
Submitted: 29 Jun 2006 20:34 Modified: 4 Jul 2006 8:22
Reporter: Kristian Nielsen Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: Cluster (NDB) storage engine Severity:S3 (Non-critical)
Version:5.0.23 OS:Linux (Linux)
Assigned to: Tomas Ulin CPU Architecture:Any

[29 Jun 2006 20:34] Kristian Nielsen
Description:
The test case 'ndb_autodiscover' started to produce this warning in Valgrind:

VALGRIND: 'Conditional jump or move depends on uninitialised value(s)'
    COUNT: 1
    FUNCTION: compare_record(st_table*,    FILES:    master.err
    TESTS:    ndb_autodiscover
    STACK: at 0x627780: compare_record(st_table*, unsigned long) (sql_update.cc:35)
             by 0x6241FC: mysql_update(THD*, st_table_list*, List<Item>&, List<Item>&, Item*, unsigned, st_order*, unsigned long, enum_duplicates, bool) (sql_update.cc:448)
             by 0x5C345A: mysql_execute_command(THD*) (sql_parse.cc:3255)
             by 0x5C9871: mysql_parse(THD*, char*, unsigned) (sql_parse.cc:5817)
             by 0x5C0CB8: dispatch_command(enum_server_command, THD*, char*, unsigned) (sql_parse.cc:1752)
             by 0x5C06BC: do_command(THD*) (sql_parse.cc:1538)
             by 0x5BFBDC: handle_one_connection (sql_parse.cc:1175)
             by 0x4D51C63: start_thread (in /lib64/tls/libpthread-0.60.so)
             by 0x540D242: clone (in /lib64/tls/libc-2.3.2.so)

It can also be repeated with the following minimal test case:

-- source include/have_ndb.inc
-- source include/not_embedded.inc

--disable_warnings
drop table if exists t1;
--enable_warnings
create table t1(
  adress char(255),
  id int not null primary key,
  name char(200)
) engine=ndb;
insert into t1 values ("Adress for record 2", 2, "Carl-Gustav");
update t1 set name="Bertil" where id = 2;
drop table t1;

The Valgrind error disappears if the table is instead defined as

create table t1(
  adress char(255),
  id int not null primary key,
  name char(200)
) engine=ndb;

so it might be related to columns that come before the primary key column.

The problem is that in mysql_update(), the char(255) field adress is not initialized in the table records table->record[0] and table->record[1]. This causes the Valgrind warning when compare_record() compares the two records to determine if the row has been actually changed in values.

Not sure if the bug is that the 'adress' field is not initialised, or if it is that compare_record() uses the field in the comparison (despite not being used in the update).

How to repeat:
perl mysql-test-run.pl --ps-protocol --valgrind-all ndb_autodiscover
[4 Jul 2006 7:53] 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/8678
[4 Jul 2006 11:38] Jonas Oreland
pushed into 5.0.24