Commit 414a8619 authored by Alexander Nozdrin's avatar Alexander Nozdrin

Backporting revision from mysql-6.0-codebase-bugfixing.

Original revision:
------------------------------------------------------------
revno: 3817
revision-id: guilhem@mysql.com-20100108092756-k0zzf4kvx9b7bh38
parent: guilhem@mysql.com-20100107101133-hrrgcdqg508runuf
committer: Guilhem Bichot <guilhem@mysql.com>
branch nick: mysql-6.0-codebase-bugfixing
timestamp: Fri 2010-01-08 10:27:56 +0100
message:
  fix for BUG#50120 "Valgrind errors in any test, inside mysqltest"
  Problem was that as v->name[v->name_len] may be uninitialized (which is ok per se),
  it shouldn't be used in an if(). We remove this zero_the_char/restore_it logic by
  rather zero-terminating the v->name string when we create it in var_init().
------------------------------------------------------------
parent 146aa9b8
...@@ -1927,13 +1927,20 @@ VAR *var_init(VAR *v, const char *name, int name_len, const char *val, ...@@ -1927,13 +1927,20 @@ VAR *var_init(VAR *v, const char *name, int name_len, const char *val,
+ name_len+1, MYF(MY_WME)))) + name_len+1, MYF(MY_WME))))
die("Out of memory"); die("Out of memory");
tmp_var->name = (name) ? (char*) tmp_var + sizeof(*tmp_var) : 0; if (name != NULL)
{
tmp_var->name= reinterpret_cast<char*>(tmp_var) + sizeof(*tmp_var);
memcpy(tmp_var->name, name, name_len);
tmp_var->name[name_len]= 0;
}
else
tmp_var->name= NULL;
tmp_var->alloced = (v == 0); tmp_var->alloced = (v == 0);
if (!(tmp_var->str_val = (char*)my_malloc(val_alloc_len+1, MYF(MY_WME)))) if (!(tmp_var->str_val = (char*)my_malloc(val_alloc_len+1, MYF(MY_WME))))
die("Out of memory"); die("Out of memory");
memcpy(tmp_var->name, name, name_len);
if (val) if (val)
{ {
memcpy(tmp_var->str_val, val, val_len); memcpy(tmp_var->str_val, val, val_len);
...@@ -2077,12 +2084,9 @@ void var_set(const char *var_name, const char *var_name_end, ...@@ -2077,12 +2084,9 @@ void var_set(const char *var_name, const char *var_name_end,
v->int_dirty= 0; v->int_dirty= 0;
v->str_val_len= strlen(v->str_val); v->str_val_len= strlen(v->str_val);
} }
char oldc= v->name[v->name_len]; /* setenv() expects \0-terminated strings */
if (oldc) DBUG_ASSERT(v->name[v->name_len] == 0);
v->name[v->name_len]= 0; // setenv() expects \0-terminated strings setenv(v->name, v->str_val, 1);
setenv(v->name, v->str_val, 1); // v->str_val is always \0-terminated
if (oldc)
v->name[v->name_len]= oldc;
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment