Skip to content

Commit

Permalink
MDEV-11646 main.myisam, maria.maria, main.mix2_myisam, main.myisampac…
Browse files Browse the repository at this point in the history
…k, main.mrr_icp_extra fail in buildbot with valgrind (Syscall param pwrite64(buf) points to uninitialised byte(s))

If the table has a varchar column and a forced fixed for format
(as in varchar.inc), Field_varstring::store() will only store the
actual number of bytes, not padded, in the record[0].

That is, on inserts a part of record[0] can be uninitialized.

Fix: initialize record[0] when a TABLE is created, it doesn't matter
what kind of garbage can be in this unused/invisible part of the
record, as long as it's not some random memory contents
(that can contain sensitive data).
  • Loading branch information
vuvova committed Jun 30, 2017
1 parent a1e51e7 commit b503b1c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
7 changes: 1 addition & 6 deletions sql/sql_insert.cc
Expand Up @@ -970,12 +970,7 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
be overwritten by fill_record() anyway (and fill_record() does not be overwritten by fill_record() anyway (and fill_record() does not
use default values in this case). use default values in this case).
*/ */
#ifdef HAVE_valgrind table->record[0][0]= share->default_values[0];
if (table->file->ha_table_flags() && HA_RECORD_MUST_BE_CLEAN_ON_WRITE)
restore_record(table,s->default_values); // Get empty record
else
#endif
table->record[0][0]= share->default_values[0];


/* Fix undefined null_bits. */ /* Fix undefined null_bits. */
if (share->null_bytes > 1 && share->last_null_bit_pos) if (share->null_bytes > 1 && share->last_null_bit_pos)
Expand Down
11 changes: 1 addition & 10 deletions sql/table.cc
Expand Up @@ -4150,16 +4150,7 @@ void TABLE::init(THD *thd, TABLE_LIST *tl)


DBUG_ASSERT(key_read == 0); DBUG_ASSERT(key_read == 0);


/* mark the record[0] uninitialized */ restore_record(this, s->default_values);
TRASH(record[0], s->reclength);

/*
Initialize the null marker bits, to ensure that if we are doing a read
of only selected columns (like in keyread), all null markers are
initialized.
*/
memset(record[0], 255, s->null_bytes);
memset(record[1], 255, s->null_bytes);


/* Tables may be reused in a sub statement. */ /* Tables may be reused in a sub statement. */
DBUG_ASSERT(!file->extra(HA_EXTRA_IS_ATTACHED_CHILDREN)); DBUG_ASSERT(!file->extra(HA_EXTRA_IS_ATTACHED_CHILDREN));
Expand Down

0 comments on commit b503b1c

Please sign in to comment.