List:Commits« Previous MessageNext Message »
From:Nirbhay Choubey Date:February 10 2012 8:39am
Subject:bzr push into mysql-trunk branch (nirbhay.choubey:3745 to 3746) WL#5605
View as plain text  
 3746 Nirbhay Choubey	2012-02-10
      WL#5605 : Assert that MySQL uses an approved random
                number generator
      
      Added support for OpenSSL/yaSSL supplied PRNG to
      create_random_string method, which generates a
      random string to be used in MySQL authentication
      protocol.

    added:
      include/my_rnd.h
      sql/my_rnd.cc
    modified:
      libmysql/CMakeLists.txt
      sql/CMakeLists.txt
      sql/password.c
 3745 Praveenkumar Hulakund	2012-01-18
      BUG#11764724 - 57586: UNKNOWN TABLE WHEN TRYING TO DROP A TABLE AND NO AVAILABLE UNDO 
      SLOTS LEFT
      
      Modified changes made as part of fix for this bug to  fix Perf regression.
      FIX for perf regression:
      -------------------------------
      Current fix had a if condition to check whether return value of function "ha_delete_table"
      is "HA_ERR_TOO_MANY_CONCURRENT_TRXS". If yes then I used to "goto err" and in "err:" check
      whether error is "HA_ERR_TOO_MANY_CONCURRENT_TRXS" and print error message. So there were 
      TWO if conditions added to check whether error is "HA_ERR_TOO_MANY_CONCURRENT_TRXS" or not.
      These conditions were getting evaluated every time, this caused perf regression.
      
      As a fix, removed both the if conditions and added only one if condition in "if (error)" block.
      This condition is added to check whether error is "HA_ERR_TOO_MANY_CONCURRENT_TRXS". If yes 
      then print error and then "goto err". Now, this condition is checked only if there is any error.
      Otherwise it will not be evaluated and so performance should not be affected.
      
      Actual Issue Description:
      -------------------------------
      If you attempt to drop an existing InnoDB table, but you do not have any 
      available undo slots open, then you will receive an "unknown table" error. 
      
      mysql> DROP TABLE test.innodb_table_monitor; 
      ERROR 1051 (42S02): Unknown table 'innodb_table_monitor' 
      
      Actual issue Analysis:
      -------------------------------
      Here, max number of concurrent transactions/connections are started and then the
      next transaction to drop a table is initiated. Since, system has already max number
      of transactions running, next transaction to "drop table" was not started and innodb
      returned error "DB_TOO_MANY_CONCURRENT_TRXS". But this error was not handled properly 
      in sql layer because of which "drop table" operation was throwing wrong error message. 
      
      Fix:
      -------------------------------
      As a fix, I have added check in sql (in function "mysql_rm_table_part2") to handle error 
      code "HA_ERR_TOO_MANY_CONCURRENT_TRXS" and throw proper error message.
      
      Ouput of drop command after fix (with max number of concurrent transaction running)
      
      mysql> drop table test;
      ERROR 177 (HY000): Too many active concurrent transactions

    modified:
      sql/sql_table.cc
=== added file 'include/my_rnd.h'
--- a/include/my_rnd.h	1970-01-01 00:00:00 +0000
+++ b/include/my_rnd.h	2012-02-10 08:20:50 +0000
@@ -0,0 +1,37 @@
+#ifndef MY_RANDOM_INCLUDED
+#define MY_RANDOM_INCLUDED
+
+/*
+   Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
+
+/*
+  A wrapper to use OpenSSL/YaSSL PRNGs.
+*/
+
+#include <mysql.h>
+#include <limits.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+double my_rnd_ssl(struct rand_struct *rand_st);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MY_RANDOM_INCLUDED */

=== modified file 'libmysql/CMakeLists.txt'
--- a/libmysql/CMakeLists.txt	2011-11-18 12:48:52 +0000
+++ b/libmysql/CMakeLists.txt	2012-02-10 08:20:50 +0000
@@ -144,6 +144,7 @@ SET(CLIENT_SOURCES
   ../sql/net_serv.cc
   ../sql-common/pack.c 
   ../sql/password.c
+  ../sql/my_rnd.cc
 )
 ADD_CONVENIENCE_LIBRARY(clientlib ${CLIENT_SOURCES})
 DTRACE_INSTRUMENT(clientlib)

=== modified file 'sql/CMakeLists.txt'
--- a/sql/CMakeLists.txt	2012-01-05 10:14:20 +0000
+++ b/sql/CMakeLists.txt	2012-02-10 08:20:50 +0000
@@ -72,6 +72,7 @@ SET(SQL_SHARED_SOURCES
   mdl.cc
   mf_iocache.cc
   my_decimal.cc
+  my_rnd.cc
   net_serv.cc
   opt_explain.cc
   opt_range.cc

=== added file 'sql/my_rnd.cc'
--- a/sql/my_rnd.cc	1970-01-01 00:00:00 +0000
+++ b/sql/my_rnd.cc	2012-02-10 08:20:50 +0000
@@ -0,0 +1,73 @@
+/*
+   Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
+
+#include <my_rnd.h>
+
+#if defined(HAVE_YASSL)
+
+#if defined(YASSL_PREFIX)
+#define RAND_bytes yaRAND_bytes
+#endif /* YASSL_PREFIX */
+
+#include <../extra/yassl/include/openssl/ssl.h>
+
+#elif defined(HAVE_OPENSSL)
+#include <openssl/rand.h>
+#endif /* HAVE_YASSL */
+
+
+/*
+  A wrapper to use OpenSSL/yaSSL PRNGs.
+*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+  Generate a random number using the OpenSSL/yaSSL supplied
+  random number generator if available.
+
+  @param rand_st [INOUT] Structure used for number generation
+                         only if none of the SSL libraries are
+                         available.
+
+  @retval                Generated random number.
+*/
+
+double my_rnd_ssl(struct rand_struct *rand_st)
+{
+
+#if defined(HAVE_YASSL) || defined(HAVE_OPENSSL)
+  int rc;
+  unsigned int res;
+
+#if defined(HAVE_YASSL)
+  rc= yaSSL::RAND_bytes((unsigned char *) &res, sizeof (unsigned int));
+#else
+  rc= RAND_bytes((unsigned char *) &res, sizeof (unsigned int));
+#endif
+
+  if (rc)
+    return (double)res / (double)UINT_MAX;
+  else
+#endif /* defined(HAVE_YASSL) || defined(HAVE_OPENSSL) */
+    return my_rnd(rand_st);
+}
+
+#ifdef __cplusplus
+}
+#endif

=== modified file 'sql/password.c'
--- a/sql/password.c	2011-07-04 00:25:46 +0000
+++ b/sql/password.c	2012-02-10 08:20:50 +0000
@@ -64,6 +64,7 @@
 #include <my_sys.h>
 #include <m_string.h>
 #include <sha1.h>
+#include <my_rnd.h>
 #include "mysql.h"
 
 /************ MySQL 3.23-4.0 authentication routines: untouched ***********/
@@ -197,8 +198,8 @@ void scramble_323(char *to, const char *
     randominit(&rand_st,hash_pass[0] ^ hash_message[0],
                hash_pass[1] ^ hash_message[1]);
     for (; message < message_end; message++)
-      *to++= (char) (floor(my_rnd(&rand_st)*31)+64);
-    extra=(char) (floor(my_rnd(&rand_st)*31));
+      *to++= (char) (floor(my_rnd_ssl(&rand_st) * 31) + 64);
+    extra=(char) (floor(my_rnd_ssl(&rand_st) * 31));
     while (to_start != to)
       *(to_start++)^=extra;
   }
@@ -240,10 +241,10 @@ check_scramble_323(const unsigned char *
   to=buff;
   DBUG_ASSERT(sizeof(buff) > SCRAMBLE_LENGTH_323);
   for (pos=scrambled ; *pos && to < buff+sizeof(buff) ; pos++)
-    *to++=(char) (floor(my_rnd(&rand_st)*31)+64);
+    *to++=(char) (floor(my_rnd_ssl(&rand_st) * 31) + 64);
   if (pos-scrambled != SCRAMBLE_LENGTH_323)
     return 1;
-  extra=(char) (floor(my_rnd(&rand_st)*31));
+  extra=(char) (floor(my_rnd_ssl(&rand_st) * 31));
   to=buff;
   while (*scrambled)
   {
@@ -321,7 +322,7 @@ void create_random_string(char *to, uint
   char *end= to + length;
   /* Use pointer arithmetics as it is faster way to do so. */
   for (; to < end; to++)
-    *to= (char) (my_rnd(rand_st)*94+33);
+    *to= (char) (my_rnd_ssl(rand_st) * 94 + 33);
   *to= '\0';
 }
 

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (nirbhay.choubey:3745 to 3746) WL#5605Nirbhay Choubey10 Feb