List:Commits« Previous MessageNext Message »
From:Sergey Glukhov Date:June 20 2011 8:03am
Subject:bzr commit into mysql-5.1 branch (sergey.glukhov:3648) Bug#12634989
View as plain text  
#At file:///home/gluh/MySQL/mysql-5.1/ based on revid:marko.makela@stripped

 3648 Sergey Glukhov	2011-06-20
      Bug#12634989 VALGRIND WARNING ABOUT UNINITIALIZED VALUES CREATED IN ITEM_FUNC_DAYOFMONTH
      added missing null value check for functions
      SUBSTRING, LEFT, RIGHT, REPEAT, LPAD, RPAD.
     @ mysql-test/r/func_str.result
        test case
     @ mysql-test/t/func_str.test
        test case
     @ sql/item_strfunc.cc
        added missing null value check for functions
        SUBSTRING, LEFT, RIGHT, REPEAT, LPAD, RPAD.

    modified:
      mysql-test/r/func_str.result
      mysql-test/t/func_str.test
      sql/item_strfunc.cc
=== modified file 'mysql-test/r/func_str.result'
--- a/mysql-test/r/func_str.result	2011-01-13 07:57:15 +0000
+++ b/mysql-test/r/func_str.result	2011-06-20 08:03:47 +0000
@@ -2628,4 +2628,43 @@ SELECT * FROM t1;
 a
 aaaaaaaaaaaaaa
 DROP TABLE t1;
+#
+# Bug#12634989 VALGRIND WARNING ABOUT UNINITIALIZED VALUES CREATED IN ITEM_FUNC_DAYOFMONTH
+#
+SELECT SUBSTRING('1', DAY(FROM_UNIXTIME(-1)));
+SUBSTRING('1', DAY(FROM_UNIXTIME(-1)))
+NULL
+SELECT LEFT('1', DAY(FROM_UNIXTIME(-1)));
+LEFT('1', DAY(FROM_UNIXTIME(-1)))
+NULL
+SELECT RIGHT('1', DAY(FROM_UNIXTIME(-1)));
+RIGHT('1', DAY(FROM_UNIXTIME(-1)))
+NULL
+SELECT REPEAT('1', DAY(FROM_UNIXTIME(-1)));
+REPEAT('1', DAY(FROM_UNIXTIME(-1)))
+NULL
+SELECT RPAD('hi', DAY(FROM_UNIXTIME(-1)),'?');
+RPAD('hi', DAY(FROM_UNIXTIME(-1)),'?')
+NULL
+SELECT LPAD('hi', DAY(FROM_UNIXTIME(-1)),'?');
+LPAD('hi', DAY(FROM_UNIXTIME(-1)),'?')
+NULL
+CREATE TABLE t1
+SELECT SUBSTRING('1', DAY(FROM_UNIXTIME(-1))) AS f1,
+LEFT('1', DAY(FROM_UNIXTIME(-1))) AS f2,
+RIGHT('1', DAY(FROM_UNIXTIME(-1))) AS f3,
+REPEAT('1', DAY(FROM_UNIXTIME(-1))) AS f4,
+RPAD('hi', DAY(FROM_UNIXTIME(-1)),'?') AS f5,
+LPAD('hi', DAY(FROM_UNIXTIME(-1)),'?') AS f6;
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `f1` varchar(1) DEFAULT NULL,
+  `f2` varchar(1) DEFAULT NULL,
+  `f3` varchar(1) DEFAULT NULL,
+  `f4` longtext,
+  `f5` longtext,
+  `f6` longtext
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP TABLE t1;
 End of 5.1 tests

=== modified file 'mysql-test/t/func_str.test'
--- a/mysql-test/t/func_str.test	2011-01-13 07:57:15 +0000
+++ b/mysql-test/t/func_str.test	2011-06-20 08:03:47 +0000
@@ -1380,4 +1380,25 @@ LOAD DATA INFILE 'bug58165.txt' INTO TAB
 SELECT * FROM t1;
 DROP TABLE t1;
 
+--echo #
+--echo # Bug#12634989 VALGRIND WARNING ABOUT UNINITIALIZED VALUES CREATED IN ITEM_FUNC_DAYOFMONTH
+--echo #
+
+SELECT SUBSTRING('1', DAY(FROM_UNIXTIME(-1)));
+SELECT LEFT('1', DAY(FROM_UNIXTIME(-1)));
+SELECT RIGHT('1', DAY(FROM_UNIXTIME(-1)));
+SELECT REPEAT('1', DAY(FROM_UNIXTIME(-1)));
+SELECT RPAD('hi', DAY(FROM_UNIXTIME(-1)),'?');
+SELECT LPAD('hi', DAY(FROM_UNIXTIME(-1)),'?');
+
+CREATE TABLE t1
+SELECT SUBSTRING('1', DAY(FROM_UNIXTIME(-1))) AS f1,
+       LEFT('1', DAY(FROM_UNIXTIME(-1))) AS f2,
+       RIGHT('1', DAY(FROM_UNIXTIME(-1))) AS f3,
+       REPEAT('1', DAY(FROM_UNIXTIME(-1))) AS f4,
+       RPAD('hi', DAY(FROM_UNIXTIME(-1)),'?') AS f5,
+       LPAD('hi', DAY(FROM_UNIXTIME(-1)),'?') AS f6;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
 --echo End of 5.1 tests

=== modified file 'sql/item_strfunc.cc'
--- a/sql/item_strfunc.cc	2011-05-16 20:04:01 +0000
+++ b/sql/item_strfunc.cc	2011-06-20 08:03:47 +0000
@@ -1162,7 +1162,10 @@ void Item_str_func::left_right_max_lengt
   max_length=args[0]->max_length;
   if (args[1]->const_item())
   {
-    int length=(int) args[1]->val_int()*collation.collation->mbmaxlen;
+    int length=(int) args[1]->val_int();
+    if (args[1]->null_value)
+      return;
+    length*= collation.collation->mbmaxlen;
     if (length <= 0)
       max_length=0;
     else
@@ -1266,6 +1269,8 @@ void Item_func_substr::fix_length_and_de
   if (args[1]->const_item())
   {
     int32 start= (int32) args[1]->val_int();
+    if (args[1]->null_value)
+      goto end;
     if (start < 0)
       max_length= ((uint)(-start) > max_length) ? 0 : (uint)(-start);
     else
@@ -1274,11 +1279,15 @@ void Item_func_substr::fix_length_and_de
   if (arg_count == 3 && args[2]->const_item())
   {
     int32 length= (int32) args[2]->val_int();
+    if (args[2]->null_value)
+      goto end;
     if (length <= 0)
       max_length=0; /* purecov: inspected */
     else
       set_if_smaller(max_length,(uint) length);
   }
+
+end:
   max_length*= collation.collation->mbmaxlen;
 }
 
@@ -2404,6 +2413,8 @@ void Item_func_repeat::fix_length_and_de
   {
     /* must be longlong to avoid truncation */
     longlong count= args[1]->val_int();
+    if (args[1]->null_value)
+      goto end;
 
     /* Assumes that the maximum length of a String is < INT_MAX32. */
     /* Set here so that rest of code sees out-of-bound value as such. */
@@ -2417,12 +2428,12 @@ void Item_func_repeat::fix_length_and_de
       maybe_null= 1;
     }
     max_length= (ulong) max_result_length;
+    return;
   }
-  else
-  {
-    max_length= MAX_BLOB_WIDTH;
-    maybe_null= 1;
-  }
+
+end:
+  max_length= MAX_BLOB_WIDTH;
+  maybe_null= 1;
 }
 
 /**
@@ -2492,6 +2503,8 @@ void Item_func_rpad::fix_length_and_dec(
     if (collation.collation->mbmaxlen > 0)
     {
       ulonglong temp= (ulonglong) args[1]->val_int();
+      if (args[1]->null_value)
+        goto end;
 
       /* Assumes that the maximum length of a String is < INT_MAX32. */
       /* Set here so that rest of code sees out-of-bound value as such. */
@@ -2507,12 +2520,12 @@ void Item_func_rpad::fix_length_and_dec(
       maybe_null= 1;
     }
     max_length= (ulong) length;
+    return;
   }
-  else
-  {
-    max_length= MAX_BLOB_WIDTH;
-    maybe_null= 1;
-  }
+
+end:
+  max_length= MAX_BLOB_WIDTH;
+  maybe_null= 1;
 }
 
 
@@ -2609,6 +2622,8 @@ void Item_func_lpad::fix_length_and_dec(
     if (collation.collation->mbmaxlen > 0)
     {
       ulonglong temp= (ulonglong) args[1]->val_int();
+      if (args[1]->null_value)
+        goto end;
 
       /* Assumes that the maximum length of a String is < INT_MAX32. */
       /* Set here so that rest of code sees out-of-bound value as such. */
@@ -2624,12 +2639,12 @@ void Item_func_lpad::fix_length_and_dec(
       maybe_null= 1;
     }
     max_length= (ulong) length;
+    return;
   }
-  else
-  {
-    max_length= MAX_BLOB_WIDTH;
-    maybe_null= 1;
-  }
+
+end:
+  max_length= MAX_BLOB_WIDTH;
+  maybe_null= 1;
 }
 
 


Attachment: [text/bzr-bundle] bzr/sergey.glukhov@oracle.com-20110620080347-aub9n7zuxu9qmlo7.bundle
Thread
bzr commit into mysql-5.1 branch (sergey.glukhov:3648) Bug#12634989Sergey Glukhov20 Jun