List:Commits« Previous MessageNext Message »
From:Magne Mahre Date:February 9 2011 9:09am
Subject:bzr commit into mysql-5.1 branch (magne.mahre:3584) Bug#48053
View as plain text  
#At file:///export/home/tmp/x/mysql-5.1-48053/ based on revid:karen.langford@stripped

 3584 Magne Mahre	2011-02-09
      Bug#48053 String::c_ptr has a race and/or does an invalid 
                memory reference
      There are two issues present here.
        1) There is a possibility that we test a byte beyond the
           allocated buffer
        2) We compare a byte that might never have been
           initalized to see if it's 0.
      The first issue is not triggered by existing code, but an
      ASSERT has been added to safe-guard against introducing
      new code that triggers it.
      The second issue is what triggers the Valgrind warnings
      reported in the bug report. A buffer is allocated in
      class String to hold the value. This buffer is populated
      by the character data constituting the string, but is not
      zero-terminated in most cases.  Testing if it is indeed
      zero-terminated means that we check a byte that has never
      been explicitly set, thus causing Valgrind to trigger.
      Note that issue 2 is not a serious problem.  The variable
      is read, and if it's not zero, we will set it to zero.
      There are no further consequences.
      Note that this patch does not fix the underlying problems
      with issue 1, as it is deemed too risky to fix at this
      point (as noted in the bug report).  As discussed in
      the report, the c_ptr() method should probably be
      replaced, but this requires a thorough analysis of the
      ~200 calls to the method.
     @ sql/
        These two cases have been reported to fail
        with Valgrind.

=== modified file 'mysql-test/r/variables.result'
--- a/mysql-test/r/variables.result	2010-11-25 03:11:05 +0000
+++ b/mysql-test/r/variables.result	2011-02-09 09:09:55 +0000
@@ -1544,4 +1544,15 @@ SET @@global.max_binlog_cache_size=DEFAU
 SET @@global.max_join_size=DEFAULT;
 SET @@global.key_buffer_size=@kbs;
 SET @@global.key_cache_block_size=@kcbs;
+# Bug #48053 String::c_ptr has a race and/or does an invalid 
+#            memory reference
+#            (triggered by Valgrind tests)
+set global LC_MESSAGES=convert((@@global.log_bin_trust_function_creators) using cp1250);
+ERROR HY000: Unknown system variable 'LC_MESSAGES'
+set global LC_TIME_NAMES=convert((-8388608) using macroman);
+ERROR HY000: Unknown locale: '-8388608'
+set global LC_TIME_NAMES=convert((convert((0x63) using eucjpms)) using big5);
+ERROR HY000: Unknown locale: 'c'
 End of 5.1 tests

=== modified file 'mysql-test/t/variables.test'
--- a/mysql-test/t/variables.test	2011-02-02 17:05:28 +0000
+++ b/mysql-test/t/variables.test	2011-02-09 09:09:55 +0000
@@ -1299,4 +1299,16 @@ SET @@global.max_join_size=DEFAULT;
 SET @@global.key_buffer_size=@kbs;
 SET @@global.key_cache_block_size=@kcbs;
+--echo #
+--echo # Bug #48053 String::c_ptr has a race and/or does an invalid 
+--echo #            memory reference
+--echo #            (triggered by Valgrind tests)
+--echo #
+--error 1193
+set global LC_MESSAGES=convert((@@global.log_bin_trust_function_creators) using cp1250);
+--error 1105
+set global LC_TIME_NAMES=convert((-8388608) using macroman);
+--error 1105
+set global LC_TIME_NAMES=convert((convert((0x63) using eucjpms)) using big5);
 --echo End of 5.1 tests

=== modified file 'sql/'
--- a/sql/	2011-02-02 17:05:28 +0000
+++ b/sql/	2011-02-09 09:09:55 +0000
@@ -1828,7 +1828,7 @@ bool sys_var::check_set(THD *thd, set_va
     var->save_result.ulong_value= ((ulong)
-				   find_set(enum_names, res->c_ptr(),
+				   find_set(enum_names, res->c_ptr_safe(),
                                             &error, &error_len,
@@ -2941,7 +2941,7 @@ bool sys_var_thd_lc_time_names::check(TH
       my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
       return 1;
-    const char *locale_str= res->c_ptr();
+    const char *locale_str= res->c_ptr_safe();
     if (!(locale_match= my_locale_by_name(locale_str)))

=== modified file 'sql/sql_string.h'
--- a/sql/sql_string.h	2011-01-13 07:57:15 +0000
+++ b/sql/sql_string.h	2011-02-09 09:09:55 +0000
@@ -106,6 +106,9 @@ public:
   inline const char *ptr() const { return Ptr; }
   inline char *c_ptr()
+    DBUG_ASSERT(!alloced || !Ptr || !Alloced_length || 
+                (Alloced_length >= (str_length + 1)));
     if (!Ptr || Ptr[str_length])		/* Should be safe */
       (void) realloc(str_length);
     return Ptr;

Attachment: [text/bzr-bundle] bzr/
bzr commit into mysql-5.1 branch (magne.mahre:3584) Bug#48053Magne Mahre9 Feb