Skip to content

Commit ba3b5a7

Browse files
author
Alexander Nozdrin
committed
Backporting revision from mysql-6.0-codebase-bugfixing.
Original revision: ------------------------------------------------------------ revno: 3817 revision-id: [email protected] parent: [email protected] committer: Guilhem Bichot <[email protected]> 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(). ------------------------------------------------------------
1 parent c06a305 commit ba3b5a7

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

client/mysqltest.cc

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,13 +1927,20 @@ VAR *var_init(VAR *v, const char *name, int name_len, const char *val,
19271927
+ name_len+1, MYF(MY_WME))))
19281928
die("Out of memory");
19291929

1930-
tmp_var->name = (name) ? (char*) tmp_var + sizeof(*tmp_var) : 0;
1930+
if (name != NULL)
1931+
{
1932+
tmp_var->name= reinterpret_cast<char*>(tmp_var) + sizeof(*tmp_var);
1933+
memcpy(tmp_var->name, name, name_len);
1934+
tmp_var->name[name_len]= 0;
1935+
}
1936+
else
1937+
tmp_var->name= NULL;
1938+
19311939
tmp_var->alloced = (v == 0);
19321940

19331941
if (!(tmp_var->str_val = (char*)my_malloc(val_alloc_len+1, MYF(MY_WME))))
19341942
die("Out of memory");
19351943

1936-
memcpy(tmp_var->name, name, name_len);
19371944
if (val)
19381945
{
19391946
memcpy(tmp_var->str_val, val, val_len);
@@ -2077,12 +2084,9 @@ void var_set(const char *var_name, const char *var_name_end,
20772084
v->int_dirty= 0;
20782085
v->str_val_len= strlen(v->str_val);
20792086
}
2080-
char oldc= v->name[v->name_len];
2081-
if (oldc)
2082-
v->name[v->name_len]= 0; // setenv() expects \0-terminated strings
2083-
setenv(v->name, v->str_val, 1); // v->str_val is always \0-terminated
2084-
if (oldc)
2085-
v->name[v->name_len]= oldc;
2087+
/* setenv() expects \0-terminated strings */
2088+
DBUG_ASSERT(v->name[v->name_len] == 0);
2089+
setenv(v->name, v->str_val, 1);
20862090
}
20872091
DBUG_VOID_RETURN;
20882092
}

0 commit comments

Comments
 (0)