summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <monty@mashka.mysql.fi>2002-09-17 23:46:53 +0300
committerunknown <monty@mashka.mysql.fi>2002-09-17 23:46:53 +0300
commitf0fbecca27b1a5b754636b9372b37454c28ec336 (patch)
treec51e7c970efa7653918302f4513422428385158d
parentddcc49ec62c271a4f022a673b39c8693ed4e7a86 (diff)
downloadmariadb-git-f0fbecca27b1a5b754636b9372b37454c28ec336.tar.gz
fixed so that --ssl and --skip-ssl works with the MySQL clients.
Fixed core dump bug when sending wrong string to AES_DECRYPT() BitKeeper/deleted/.del-explain_log.sh~e570be5f63576fe1: Delete: scripts/explain_log.sh Docs/manual.texi: Updated bug reporting. Added somew new changelog entries and changed some old client/mysql.cc: Fixed so that --ssl and --skip-ssl works client/mysqladmin.c: Fixed so that --ssl and --skip-ssl works client/mysqlcheck.c: Fixed so that --ssl and --skip-ssl works client/mysqldump.c: Fixed so that --ssl and --skip-ssl works client/mysqlimport.c: Fixed so that --ssl and --skip-ssl works client/mysqlshow.c: Fixed so that --ssl and --skip-ssl works include/sslopt-case.h: Fixed so that --ssl and --skip-ssl works mysql-test/r/func_str.result: Test of problem with AES_DECRYPT() mysql-test/t/func_str.test: Test of problem with AES_DECRYPT() mysys/my_aes.c: Fixed problem with wrong decrypt string. scripts/mysql_explain_log.sh: Applied missed patch sql/item_strfunc.cc: Fixed aes_encrypt() and aes_decrypt() to be safer and avoid some mallocs() sql/net_pkg.cc: Return ER_UNKNOWN_ERROR instead of errocode 0 in some cases.
-rw-r--r--Docs/manual.texi31
-rw-r--r--client/mysql.cc3
-rw-r--r--client/mysqladmin.c8
-rw-r--r--client/mysqlcheck.c12
-rw-r--r--client/mysqldump.c8
-rw-r--r--client/mysqlimport.c8
-rw-r--r--client/mysqlshow.c14
-rw-r--r--include/sslopt-case.h29
-rw-r--r--mysql-test/r/func_str.result5
-rw-r--r--mysql-test/t/func_str.test9
-rw-r--r--mysys/my_aes.c5
-rw-r--r--scripts/explain_log.sh383
-rw-r--r--scripts/mysql_explain_log.sh2
-rw-r--r--sql/item_strfunc.cc44
-rw-r--r--sql/net_pkg.cc8
15 files changed, 118 insertions, 451 deletions
diff --git a/Docs/manual.texi b/Docs/manual.texi
index 2030f36efce..74d6f2ac48b 100644
--- a/Docs/manual.texi
+++ b/Docs/manual.texi
@@ -2304,12 +2304,14 @@ to do and is a powerful way to get information about any table in a database
that will help us create a situation matching the one you have.
@item
-For speed-related bugs or problems with @code{SELECT} statements, you should
-always include the output of @code{EXPLAIN SELECT ...}, and at least the
-number of rows that the @code{SELECT} statement produces. The more
-information you give about your situation, the more likely it is that someone
-can help you! For example, the following is an example of a very good bug
-report (it should of course be posted with the @code{mysqlbug} script):
+For speed-related bugs or problems with @code{SELECT} statements, you
+should always include the output of @code{EXPLAIN SELECT ...}, and at
+least the number of rows that the @code{SELECT} statement produces. You
+should also include the output from @code{SHOW CREATE TABLE table_name}
+for each involved table. The more information you give about your
+situation, the more likely it is that someone can help you! For
+example, the following is an example of a very good bug report (it
+should of course be posted with the @code{mysqlbug} script):
Example run using the @code{mysql} command-line tool (note the use of the
@code{\G} statement terminator for statements whose output width would
@@ -50440,6 +50442,12 @@ each individual 4.0.x release.
@itemize @bullet
@item
+Fixed overrun bug when calling @code{AES_DECRYPT()} with wrong arguments
+@item
+@code{--skip-ssl} can now be used to disable SSL in the MySQL clients,
+even if one is using other ssl options in a options file or previously
+on the command line.
+@item
Added @code{LOCK TABLES} and @code{CREATE TEMPORARY TABLES} privilege on
the database level. One must run the @code{ mysql_fix_privilege_tables}
script on old installations to activate these.
@@ -50494,12 +50502,13 @@ This affected at least @code{default-table-type} option.
Fixed a bug that caused @code{REPAIR TABLE} to fail on tables
with duplicates in a unique key.
@item
-Fixed a bug in guessing a field type out of the function. The error was
-introduced in 4.0.3 so that field type depended on the first argument to
-the function instead of the function itself
+Fixed a bug from 4.0.3 in calculating the default field type for some
+functions. This affected queries of type @code{CREATE TABLE table_name
+SELECT expression(),...}
@item
-Fixed a bug with wildcarded fields in select list, which led to the wrong
-number of elements in a list containing all fields
+Fixed bug in queries of type
+@code{SELECT * FROM table-list GROUP BY ...} and
+@code{SELECT DISTINCT * FROM ...}.
@item
Fixed bug with the @code{--slow-log} when logging an administrator command
(like @code{FLUSH TABLES}).
diff --git a/client/mysql.cc b/client/mysql.cc
index eaf80a1014e..ec5eb01d0e7 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -2209,9 +2209,6 @@ sql_real_connect(char *host,char *database,char *user,char *password,
if (using_opt_local_infile)
mysql_options(&mysql,MYSQL_OPT_LOCAL_INFILE, (char*) &opt_local_infile);
#ifdef HAVE_OPENSSL
- if (opt_ssl_key || opt_ssl_cert || opt_ssl_ca || opt_ssl_capath ||
- opt_ssl_cipher)
- opt_use_ssl= 1;
if (opt_use_ssl)
mysql_ssl_set(&mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
opt_ssl_capath, opt_ssl_cipher);
diff --git a/client/mysqladmin.c b/client/mysqladmin.c
index cdca59574f7..01e36509c30 100644
--- a/client/mysqladmin.c
+++ b/client/mysqladmin.c
@@ -52,7 +52,7 @@ static uint ex_val_max_len[MAX_MYSQL_VAR];
static my_bool ex_status_printed = 0; /* First output is not relative. */
static uint ex_var_count, max_var_length, max_val_length;
-#include "sslopt-vars.h"
+#include <sslopt-vars.h>
static void print_version(void);
static void usage(void);
@@ -150,7 +150,7 @@ static struct my_option my_long_options[] =
{"sleep", 'i', "Execute commands again and again with a sleep between.",
(gptr*) &interval, (gptr*) &interval, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0,
0, 0},
-#include "sslopt-longopts.h"
+#include <sslopt-longopts.h>
#ifndef DONT_ALLOW_USER_CHANGE
{"user", 'u', "User for login if not current user.", (gptr*) &user,
(gptr*) &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -211,6 +211,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case '#':
DBUG_PUSH(argument ? argument : "d:t:o,/tmp/mysqladmin.trace");
break;
+#include <sslopt-case.h>
case 'V':
print_version();
exit(0);
@@ -279,9 +280,6 @@ int main(int argc,char *argv[])
mysql_options(&mysql,MYSQL_OPT_CONNECT_TIMEOUT, (char*) &tmp);
}
#ifdef HAVE_OPENSSL
- if (opt_ssl_key || opt_ssl_cert || opt_ssl_ca || opt_ssl_capath ||
- opt_ssl_cipher)
- opt_use_ssl= 1;
if (opt_use_ssl)
mysql_ssl_set(&mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
opt_ssl_capath, opt_ssl_cipher);
diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c
index 91405a784ea..394555f37a9 100644
--- a/client/mysqlcheck.c
+++ b/client/mysqlcheck.c
@@ -20,9 +20,9 @@
#include "client_priv.h"
#include <m_ctype.h>
-#include "mysql_version.h"
-#include "mysqld_error.h"
-#include "sslopt-vars.h"
+#include <mysql_version.h>
+#include <mysqld_error.h>
+#include <sslopt-vars.h>
/* Exit codes */
@@ -121,7 +121,7 @@ static struct my_option my_long_options[] =
{"socket", 'S', "Socket file to use for connection.",
(gptr*) &opt_mysql_unix_port, (gptr*) &opt_mysql_unix_port, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-#include "sslopt-longopts.h"
+#include <sslopt-longopts.h>
{"tables", OPT_TABLES, "Overrides option --databases (-B).", 0, 0, 0,
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
#ifndef DONT_ALLOW_USER_CHANGE
@@ -239,6 +239,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case '#':
DBUG_PUSH(argument ? argument : "d:t:o");
break;
+#include <sslopt-case.h>
case OPT_TABLES:
opt_databases = 0;
break;
@@ -529,9 +530,6 @@ static int dbConnect(char *host, char *user, char *passwd)
if (opt_compress)
mysql_options(&mysql_connection, MYSQL_OPT_COMPRESS, NullS);
#ifdef HAVE_OPENSSL
- if (opt_ssl_key || opt_ssl_cert || opt_ssl_ca || opt_ssl_capath ||
- opt_ssl_cipher)
- opt_use_ssl= 1;
if (opt_use_ssl)
mysql_ssl_set(&mysql_connection, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
opt_ssl_capath, opt_ssl_cipher);
diff --git a/client/mysqldump.c b/client/mysqldump.c
index 6a26f4167f7..612746c205b 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -88,7 +88,7 @@ static my_string opt_mysql_unix_port=0;
static int first_error=0;
extern ulong net_buffer_length;
static DYNAMIC_STRING extended_row;
-#include "sslopt-vars.h"
+#include <sslopt-vars.h>
FILE *md_result_file;
static struct my_option my_long_options[] =
@@ -211,7 +211,7 @@ static struct my_option my_long_options[] =
{"socket", 'S', "Socket file to use for connection.",
(gptr*) &opt_mysql_unix_port, (gptr*) &opt_mysql_unix_port, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-#include "sslopt-longopts.h"
+#include <sslopt-longopts.h>
{"tab",'T',
"Creates tab separated textfile for each table to given path. (creates .sql and .txt files). NOTE: This only works if mysqldump is run on the same machine as the mysqld daemon.",
(gptr*) &path, (gptr*) &path, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -335,6 +335,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case '#':
DBUG_PUSH(argument ? argument : "d:t:o");
break;
+#include <sslopt-case.h>
case 'V': print_version(); exit(0);
case 'X':
opt_xml = 1;
@@ -457,9 +458,6 @@ static int dbConnect(char *host, char *user,char *passwd)
if (opt_compress)
mysql_options(&mysql_connection,MYSQL_OPT_COMPRESS,NullS);
#ifdef HAVE_OPENSSL
- if (opt_ssl_key || opt_ssl_cert || opt_ssl_ca || opt_ssl_capath ||
- opt_ssl_cipher)
- opt_use_ssl= 1;
if (opt_use_ssl)
mysql_ssl_set(&mysql_connection, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
opt_ssl_capath, opt_ssl_cipher);
diff --git a/client/mysqlimport.c b/client/mysqlimport.c
index 603e9036106..a11b7383517 100644
--- a/client/mysqlimport.c
+++ b/client/mysqlimport.c
@@ -47,7 +47,7 @@ static char *opt_password=0, *current_user=0,
static uint opt_mysql_port=0;
static my_string opt_mysql_unix_port=0;
static my_string opt_ignore_lines=0;
-#include "sslopt-vars.h"
+#include <sslopt-vars.h>
static struct my_option my_long_options[] =
{
@@ -119,7 +119,7 @@ static struct my_option my_long_options[] =
{"socket", 'S', "Socket file to use for connection.",
(gptr*) &opt_mysql_unix_port, (gptr*) &opt_mysql_unix_port, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-#include "sslopt-longopts.h"
+#include <sslopt-longopts.h>
#ifndef DONT_ALLOW_USER_CHANGE
{"user", 'u', "User for login if not current user.", (gptr*) &current_user,
(gptr*) &current_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -188,6 +188,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case '#':
DBUG_PUSH(argument ? argument : "d:t:o");
break;
+#include <sslopt-case.h>
case 'V': print_version(); exit(0);
case 'I':
case '?':
@@ -347,9 +348,6 @@ static MYSQL *db_connect(char *host, char *database, char *user, char *passwd)
mysql_options(&mysql_connection,MYSQL_OPT_LOCAL_INFILE,
(char*) &opt_local_file);
#ifdef HAVE_OPENSSL
- if (opt_ssl_key || opt_ssl_cert || opt_ssl_ca || opt_ssl_capath ||
- opt_ssl_cipher)
- opt_use_ssl= 1;
if (opt_use_ssl)
mysql_ssl_set(&mysql_connection, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
opt_ssl_capath, opt_ssl_cipher);
diff --git a/client/mysqlshow.c b/client/mysqlshow.c
index 718716b60be..5475fc7b531 100644
--- a/client/mysqlshow.c
+++ b/client/mysqlshow.c
@@ -18,16 +18,14 @@
#define SHOW_VERSION "9.4"
-#include <my_global.h>
#include "client_priv.h"
#include <my_sys.h>
#include <m_string.h>
-#include "mysql.h"
-#include "mysql_version.h"
-#include "mysqld_error.h"
+#include <mysql.h>
+#include <mysqld_error.h>
#include <signal.h>
#include <stdarg.h>
-#include "sslopt-vars.h"
+#include <sslopt-vars.h>
static my_string host=0,opt_password=0,user=0;
static my_bool opt_show_keys=0,opt_compress=0,opt_status=0, tty_password=0;
@@ -85,9 +83,6 @@ int main(int argc, char **argv)
if (opt_compress)
mysql_options(&mysql,MYSQL_OPT_COMPRESS,NullS);
#ifdef HAVE_OPENSSL
- if (opt_ssl_key || opt_ssl_cert || opt_ssl_ca || opt_ssl_capath ||
- opt_ssl_cipher)
- opt_use_ssl= 1;
if (opt_use_ssl)
mysql_ssl_set(&mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
opt_ssl_capath, opt_ssl_cipher);
@@ -156,7 +151,7 @@ static struct my_option my_long_options[] =
{"socket", 'S', "Socket file to use for connection.",
(gptr*) &opt_mysql_unix_port, (gptr*) &opt_mysql_unix_port, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
-#include "sslopt-longopts.h"
+#include <sslopt-longopts.h>
#ifndef DONT_ALLOW_USER_CHANGE
{"user", 'u', "User for login if not current user.", (gptr*) &user,
(gptr*) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
@@ -224,6 +219,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case '#':
DBUG_PUSH(argument ? argument : "d:t:o");
break;
+#include <sslopt-case.h>
case 'V':
print_version();
exit(0);
diff --git a/include/sslopt-case.h b/include/sslopt-case.h
new file mode 100644
index 00000000000..ea23c31aa82
--- /dev/null
+++ b/include/sslopt-case.h
@@ -0,0 +1,29 @@
+/* Copyright (C) 2000 MySQL AB
+
+ 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; either version 2 of the License, or
+ (at your option) any later version.
+
+ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifdef HAVE_OPENSSL
+ case OPT_SSL_KEY:
+ case OPT_SSL_CERT:
+ case OPT_SSL_CA:
+ case OPT_SSL_CAPATH:
+ case OPT_SSL_CIPHER:
+ /*
+ Enable use of SSL if we are using any ssl option
+ One can disable SSL later by using --skip-ssl or --ssl=0
+ */
+ opt_use_ssl= 1;
+ break;
+#endif
diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result
index dd5e5191536..69e37d7b911 100644
--- a/mysql-test/r/func_str.result
+++ b/mysql-test/r/func_str.result
@@ -223,3 +223,8 @@ SELECT CONCAT_WS('";"',title,prio,category,program,bugdesc,created,modified,bugs
CONCAT_WS('";"',title,prio,category,program,bugdesc,created,modified,bugstatus,submitter)
Link";"1";"1";"1";"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";"2001-02-28 08:40:16";"20010228084016";"0";"4
drop table t1;
+CREATE TABLE t1 (id int(11) NOT NULL auto_increment, tmp text NOT NULL, KEY id (id)) TYPE=MyISAM;
+INSERT INTO t1 VALUES (1, 'a545f661efdd1fb66fdee3aab79945bf');
+SELECT 1 FROM t1 WHERE tmp=AES_DECRYPT(tmp,"password");
+1
+DROP TABLE t1;
diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test
index daf5587b450..717b9c86a07 100644
--- a/mysql-test/t/func_str.test
+++ b/mysql-test/t/func_str.test
@@ -114,3 +114,12 @@ SELECT CONCAT('"',CONCAT_WS('";"',title,prio,category,program,bugdesc,created,mo
SELECT CONCAT('"',CONCAT_WS('";"',title,prio,category,program,bugstatus,submitter), '"') FROM t1;
SELECT CONCAT_WS('";"',title,prio,category,program,bugdesc,created,modified,bugstatus,submitter) FROM t1;
drop table t1;
+
+#
+# Test bug in AES_DECRYPT() when called with wrong argument
+#
+
+CREATE TABLE t1 (id int(11) NOT NULL auto_increment, tmp text NOT NULL, KEY id (id)) TYPE=MyISAM;
+INSERT INTO t1 VALUES (1, 'a545f661efdd1fb66fdee3aab79945bf');
+SELECT 1 FROM t1 WHERE tmp=AES_DECRYPT(tmp,"password");
+DROP TABLE t1;
diff --git a/mysys/my_aes.c b/mysys/my_aes.c
index 10ef62ae0a5..a3618e44b82 100644
--- a/mysys/my_aes.c
+++ b/mysys/my_aes.c
@@ -178,7 +178,7 @@ int my_aes_decrypt(const char *source, int source_length, char *dest,
char block[AES_BLOCK_SIZE]; /* 128 bit block used for padding */
int rc; /* Result codes */
int num_blocks; /* Number of complete blocks */
- char pad_len; /* Pad size for the last block */
+ uint pad_len; /* Pad size for the last block */
int i;
if ((rc=my_aes_create_key(&aes_key,AES_DECRYPT,key,key_length)))
@@ -197,7 +197,8 @@ int my_aes_decrypt(const char *source, int source_length, char *dest,
}
rijndaelDecrypt(aes_key.rk, aes_key.nr, source, block);
- pad_len = block[AES_BLOCK_SIZE-1]; /* Use last char in the block as size */
+ /* Use last char in the block as size */
+ pad_len = (uint) (uchar) block[AES_BLOCK_SIZE-1];
if (pad_len > AES_BLOCK_SIZE)
return AES_BAD_DATA;
diff --git a/scripts/explain_log.sh b/scripts/explain_log.sh
deleted file mode 100644
index c4a4ef21568..00000000000
--- a/scripts/explain_log.sh
+++ /dev/null
@@ -1,383 +0,0 @@
-#!@PERL@ -w
-use strict;
-use DBI;
-
-use Getopt::Long;
-$Getopt::Long::ignorecase=0;
-
-print "explain_log provided by http://www.mobile.de\n";
-print "=========== ================================\n";
-
-my $Param={};
-
-$Param->{host}='';
-$Param->{user}='';
-$Param->{password}='';
-$Param->{PrintError}=0;
-
-if (!GetOptions ('date|d:i' => \$Param->{ViewDate},
- 'host|h:s' => \$Param->{host},
- 'user|u:s' => \$Param->{user},
- 'password|p:s' => \$Param->{password},
- 'printerror|e:s' => \$Param->{PrintError},
- )) {
- ShowOptions();
-}
-else {
- $Param->{UpdateCount} = 0;
- $Param->{SelectCount} = 0;
- $Param->{IdxUseCount} = 0;
- $Param->{LineCount} = 0;
-
- $Param->{Init} = 0;
- $Param->{Field} = 0;
- $Param->{Refresh} = 0;
- $Param->{QueryCount} = 0;
- $Param->{Statistics} =0;
-
- $Param->{Query} = undef;
- $Param->{ALL} = undef ;
- $Param->{Comment} = undef ;
-
- @{$Param->{Rows}} = (qw|possible_keys key type|);
-
- if ($Param->{ViewDate}) {
- $Param->{View} = 0;
- }
- else {
- $Param->{View} = 1;
- }
-
- #print "Date=$Param->{ViewDate}, host=$Param->{host}, user=$Param->{user}, password=$Param->{password}\n";
-
- $Param->{dbh}=DBI->connect("DBI:mysql:host=$Param->{host}",$Param->{user},$Param->{password},{PrintError=>0});
- if (DBI::err()) {
- print "Error: " . DBI::errstr() . "\n";
- }
- else {
- $Param->{Start} = time;
- while(<STDIN>) {
- $Param->{LineCount} ++ ;
-
- if ($Param->{ViewDate} ) {
- if (m/^(\d{6})\s+\d{1,2}:\d\d:\d\d\s.*$/) { # get date
- #print "# $1 #\n";
- if ($1 == $Param->{ViewDate}) {
- $Param->{View} = 1;
- }
- else {
- $Param->{View} = 0;
- }
- }
- }
- if ($Param->{View} ) {
- #print "->>>$_";
-
- if (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Connect.+\s+on\s+(.*)$/i) { # get connection ID($2) and database($3)
- #print "C-$1--$2--$3------\n";
- RunQuery($Param);
- if (defined $3) {
- $Param->{CID}->{$2} = $3 ;
- #print "DB:$Param->{CID}->{$2} .. $2 .. $3 \n";
- }
- }
-
- elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Connect.+$/i) { # get connection ID($2) and database($3)
- #print "\n <<<<<<<<<<<<<<<<<<----------------------------<<<<<<<<<<<<<<<< \n";
- #print "Connect \n";
- RunQuery($Param);
- }
- elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Change user .*\s+on\s+(.*)$/i) { # get connection ID($2) and database($3)
- #print "C-$1--$2--$3------\n";
- RunQuery($Param);
- if (defined $3) {
- $Param->{CID}->{$2} = $3 ;
- #print "DB:$Param->{CID}->{$2} .. $2 .. $3 \n";
- }
- }
-
- elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Quit\s+$/i) { # remove connection ID($2) and querystring
- #print "Q-$1--$2--------\n";
- RunQuery($Param);
- delete $Param->{CID}->{$2} ;
- }
-
- elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Query\s+(select.+)$/i) { # get connection ID($2) and querystring
- #print "S1-$1--$2--$3------\n";
- RunQuery($Param);
- unless ($Param->{CID}->{$2}) {
- #print "Error: No Database for Handle: $2 found\n";
- }
- else {
- $Param->{DB}=$Param->{CID}->{$2};
-
- my $s = "$3";
- $s =~ s/from\s/from $Param->{DB}./i;
- $Param->{Query}="EXPLAIN $s";
-
- #$s =~ m/from\s+(\w+[.]\w+)/i;
- #$Param->{tab} =$1;
- #print "-- $Param->{tab} -- $s --\n";
- }
- }
-
- elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Query\s+(update.+)$/i) { # get connection ID($2) and querystring
- #print "S2--$1--$2--$3------\n";
- RunQuery($Param);
- unless ($Param->{CID}->{$2}) {
- #print "Error: No Database for Handle: $2 found\n";
- }
- else {
- $Param->{DB}=$Param->{CID}->{$2};
-
- my $ud = $3;
- $ud =~ m/^update\s+(\w+).+(where.+)$/i;
- $Param->{Query} ="EXPLAIN SELECT * FROM $1 $2";
- $Param->{Query} =~ s/from\s/from $Param->{DB}./i;
-
- #$Param->{Query} =~ m/from\s+(\w+[.]\w+)/i;
- #$Param->{tab} =$1;
- }
- }
-
- elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Statistics\s+(.*)$/i) { # get connection ID($2) and info?
- $Param->{Statistics} ++;
- #print "Statistics--$1--$2--$3------\n";
- RunQuery($Param);
- }
- elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Query\s+(.+)$/i) { # get connection ID($2)
- $Param->{QueryCount} ++;
- #print "Query-NULL $3\n";
- RunQuery($Param);
- }
- elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Refresh\s+(.+)$/i) { # get connection ID($2)
- $Param->{Refresh} ++;
- #print "Refresh\n";
- RunQuery($Param);
- }
- elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Init\s+(.+)$/i) { # get connection ID($2)
- $Param->{Init} ++;
- #print "Init $3\n";
- RunQuery($Param);
- }
- elsif (m/^(\d{6}\s+\d{1,2}:\d\d:\d\d\s+|\s+)(\d+)\s+Field\s+(.+)$/i) { # get connection ID($2)
- $Param->{Field} ++;
- #print "Field $3\n";
- RunQuery($Param);
- }
-
- elsif (m/^\s+(.+)$/ ) { # command could be some lines ...
- #print "multi-lined ($1)\n";
- my ($A)=$1;
- chomp $A;
- $Param->{Query} .= " $1";
- #print "multi-lined ($1)<<$Param->{Query}>>\n";
- }
-
-
- }
-
- }
-
- $Param->{dbh}->disconnect();
-
- if (1 == 0) {
- print "\nunclosed handles----------------------------------------\n";
- my $count=0;
- foreach (sort keys %{$Param->{CID}}) {
- print "$count | $_ : $Param->{CID}->{$_} \n";
- $count ++;
- }
- }
-
- print "\nIndex usage ------------------------------------\n";
- foreach my $t (sort keys %{$Param->{Data}}) {
- print "\nTable\t$t: ---\n";
- foreach my $k (sort keys %{$Param->{Data}->{$t}}) {
- print " count\t$k:\n";
- my %h = %{$Param->{Data}->{$t}->{$k}};
- foreach (sort {$h{$a} <=> $h{$b}} keys %h) {
- print " $Param->{Data}->{$t}->{$k}->{$_}\t$_\n";
- }
- }
- }
-
- $Param->{AllCount}=0;
- print "\nQueries causing table scans -------------------\n\n";
- foreach (@{$Param->{ALL}}) {
- $Param->{AllCount} ++;
- print "$_\n";
- }
- print "Sum: $Param->{AllCount} table scans\n";
-
- print "\nSummary ---------------------------------------\n\n";
- print "Select: \t$Param->{SelectCount} queries\n";
- print "Update: \t$Param->{UpdateCount} queries\n";
- print "\n";
-
- print "Init: \t$Param->{Init} times\n";
- print "Field: \t$Param->{Field} times\n";
- print "Refresh: \t$Param->{Refresh} times\n";
- print "Query: \t$Param->{QueryCount} times\n";
- print "Statistics:\t$Param->{Statistics} times\n";
- print "\n";
-
- print "Logfile: \t$Param->{LineCount} lines\n";
- print "Started: \t".localtime($Param->{Start})."\n";
- print "Finished: \t".localtime(time)."\n";
-
- }
-}
-
-
-###########################################################################
-#
-#
-#
-sub RunQuery {
- my $Param = shift ;
-
- if (defined $Param->{Query}) {
- if (defined $Param->{DB} ) {
-
- $Param->{Query} =~ m/from\s+(\w+[.]\w+|\w+)/i;
- $Param->{tab} =$1;
- #print "||$Param->{tab} -- $Param->{Query}\n";
-
- my $sth=$Param->{dbh}->prepare("USE $Param->{DB}");
- if (DBI::err()) {
- if ($Param->{PrintError}) {print "Error: ".DBI::errstr()."\n";}
- }
- else {
- $sth->execute();
- if (DBI::err()) {
- if ($Param->{PrintError}) {print "Error: ".DBI::errstr()."\n";}
- }
- else {
- $sth->finish();
-
- $sth=$Param->{dbh}->prepare($Param->{Query});
- if (DBI::err()) {
- if ($Param->{PrintError}) {print "Error: ".DBI::errstr()."\n";}
- }
- else {
- #print "$Param->{Query}\n";
- $sth->execute();
- if (DBI::err()) {
- if ($Param->{PrintError}) {print "[$Param->{LineCount}]<<$Param->{Query}>>\n";}
- if ($Param->{PrintError}) {print "Error: ".DBI::errstr()."\n";}
- }
- else {
- my $row = undef;
- while ($row = $sth->fetchrow_hashref()) {
- $Param->{SelectCount} ++;
-
- if (defined $row->{Comment}) {
- push (@{$Param->{Comment}}, "$row->{Comment}; $_; $Param->{DB}; $Param->{Query}");
- }
- foreach (@{$Param->{Rows}}) {
- if (defined $row->{$_}) {
- #if (($_ eq 'type' ) and ($row->{$_} eq 'ALL')) {
- if ($row->{type} eq 'ALL') {
- push (@{$Param->{ALL}}, "$Param->{Query}");
- #print ">> $row->{$_} $_ $Param->{DB} $Param->{Query}\n";
- }
- $Param->{IdxUseCount} ++;
- $Param->{Data}->{$Param->{tab}}->{$_}->{$row->{$_}} ++;
- }
- }
- }
- }
- }
- }
- }
- $sth->finish();
- }
- $Param->{Query} = undef ;
- }
-}
-
-###########################################################################
-#
-#
-#
-sub ShowOptions {
- print <<EOF;
-Usage: $0 [OPTIONS] < LOGFILE
-
---date=YYMMDD select only entrys of date
--d=YYMMDD
---host=HOSTNAME db-host to ask
--h=HOSTNAME
---user=USERNAME db-user
--u=USERNAME
---password=PASSWORD password of db-user
--p=PASSWORD
-
-Read logfile from STDIN an try to EXPLAIN all SELECT statements. All UPDATE statements are rewritten to an EXPLAIN SELECT statement. The results of the EXPLAIN statement are collected and counted. All results with type=ALL are collected in an separete list. Results are printed to STDOUT.
-
-EOF
-}
-
-1;
-
-__END__
-
-=pod
-
-=head1 NAME
-
-explain_log.pl
-
-Feed a mysqld general logfile (created with mysqld --log) back into mysql
-and collect statistics about index usage with EXPLAIN.
-
-=head1 DISCUSSION
-
-To optimize your indices, you have to know which ones are actually
-used and what kind of queries are causing table scans. Especially
-if you are generating your queries dynamically and you have a huge
-amount of queries going on, this isn't easy.
-
-Use this tool to take a look at the effects of your real life queries.
-Then add indices to avoid table scans and remove those which aren't used.
-
-=head1 USAGE
-
-explain_log.pl [--date=YYMMDD] --host=dbhost] [--user=dbuser] [--password=dbpw] < logfile
-
---date=YYMMDD select only entrys of date
-
--d=YYMMDD
-
---host=HOSTNAME db-host to ask
-
--h=HOSTNAME
-
---user=USERNAME db-user
-
--u=USERNAME
-
---password=PASSWORD password of db-user
-
--p=PASSWORD
-
-=head1 EXAMPLE
-
-explain_log.pl --host=localhost --user=foo --password=bar < /var/lib/mysql/mobile.log
-
-=head1 AUTHOR
-
- Stefan Nitz
- Jan Willamowius <jan@mobile.de>, http://www.mobile.de
-
-=head1 RECRUITING
-
-If you are looking for a MySQL or Perl job, take a look at http://www.mobile.de
-and send me an email with your resume (you must be speaking German!).
-
-=head1 SEE ALSO
-
-mysql documentation
-
-=cut
diff --git a/scripts/mysql_explain_log.sh b/scripts/mysql_explain_log.sh
index d7f6bb97b40..c4a4ef21568 100644
--- a/scripts/mysql_explain_log.sh
+++ b/scripts/mysql_explain_log.sh
@@ -279,7 +279,7 @@ sub RunQuery {
if (defined $row->{$_}) {
#if (($_ eq 'type' ) and ($row->{$_} eq 'ALL')) {
if ($row->{type} eq 'ALL') {
- push (@{$Param->{ALL}}, "$row->{$_} $_ $Param->{DB} $Param->{Query}");
+ push (@{$Param->{ALL}}, "$Param->{Query}");
#print ">> $row->{$_} $_ $Param->{DB} $Param->{Query}\n";
}
$Param->{IdxUseCount} ++;
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 3e32720a663..af533eefe9a 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -114,7 +114,7 @@ String *Item_func_sha::val_str(String *str)
/* No need to check error as the only case would be too long message */
sha1_input(&context,(const unsigned char *) sptr->ptr(), sptr->length());
/* Ensure that memory is free and we got result */
- if ( !( str->alloc(SHA1_HASH_SIZE*2) || (sha1_result(&context,digest)) ) )
+ if (!( str->alloc(SHA1_HASH_SIZE*2) || (sha1_result(&context,digest))))
{
sprintf((char *) str->ptr(),
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\
@@ -144,24 +144,25 @@ void Item_func_sha::fix_length_and_dec()
String *Item_func_aes_encrypt::val_str(String *str)
{
- String * sptr = args[0]->val_str(str); // String to encrypt
- String tmp_value; // required to handle second parameter
- String * key= args[1]->val_str(&tmp_value); // key
+ char key_buff[80];
+ String tmp_key_value(key_buff, sizeof(key_buff));
+ String *sptr= args[0]->val_str(str); // String to encrypt
+ String *key= args[1]->val_str(&tmp_key_value); // key
int aes_length;
if (sptr && key) // we need both arguments to be not NULL
{
null_value=0;
- aes_length=my_aes_get_size(sptr->length()); // calculate result length
+ aes_length=my_aes_get_size(sptr->length()); // Calculate result length
- if (!str->alloc(aes_length)) // Ensure that memory is free
+ if (!str_value.alloc(aes_length)) // Ensure that memory is free
{
// finally encrypt directly to allocated buffer.
- if (my_aes_encrypt(sptr->ptr(),sptr->length(), (char*) str->ptr(),
+ if (my_aes_encrypt(sptr->ptr(),sptr->length(), (char*) str_value.ptr(),
key->ptr(), key->length()) == aes_length)
{
// We got the expected result length
- str->length((uint) aes_length);
- return str;
+ str_value.length((uint) aes_length);
+ return &str_value;
}
}
}
@@ -178,30 +179,35 @@ void Item_func_aes_encrypt::fix_length_and_dec()
String *Item_func_aes_decrypt::val_str(String *str)
{
- String * sptr= args[0]->val_str(str); // String to decrypt
- String tmp_value; // temporary string required for parsing
- String * key= args[1]->val_str(&tmp_value); // key
- int length; // original length after decrypt
- if (sptr && key) // Need to have both arguments not NULL
+ char key_buff[80];
+ String tmp_key_value(key_buff, sizeof(key_buff)), *sptr, *key;
+ DBUG_ENTER("Item_func_aes_decrypt::val_str");
+
+ sptr= args[0]->val_str(str); // String to decrypt
+ key= args[1]->val_str(&tmp_key_value); // Key
+ if (sptr && key) // Need to have both arguments not NULL
{
null_value=0;
- if (!str->alloc(sptr->length())) // Ensure that memory is free
+ if (!str_value.alloc(sptr->length())) // Ensure that memory is free
{
// finally decrypt directly to allocated buffer.
- length=my_aes_decrypt(sptr->ptr(), sptr->length(), (char*) str->ptr(),
+ int length;
+ length=my_aes_decrypt(sptr->ptr(), sptr->length(),
+ (char*) str_value.ptr(),
key->ptr(), key->length());
if (length >= 0) // if we got correct data data
{
- str->length((uint) length);
- return str;
+ str_value.length((uint) length);
+ DBUG_RETURN(&str_value);
}
}
}
// Bad parameters. No memory or bad data will all go here
null_value=1;
- return 0;
+ DBUG_RETURN(0);
}
+
void Item_func_aes_decrypt::fix_length_and_dec()
{
max_length=args[0]->max_length;
diff --git a/sql/net_pkg.cc b/sql/net_pkg.cc
index 55c9bd3cfab..8bb601cebcf 100644
--- a/sql/net_pkg.cc
+++ b/sql/net_pkg.cc
@@ -115,7 +115,13 @@ net_printf(NET *net, uint errcode, ...)
is useful for rare errors that are not worth the hassle to put in
errmsg.sys, but at the same time, the message is not fixed text
*/
- format=errcode ? ER(errcode) : va_arg(args,char*);
+ if (errcode)
+ format= ER(errcode);
+ else
+ {
+ format=va_arg(args,char*);
+ errcode= ER_UNKNOWN_ERROR;
+ }
offset= net->return_errno ? 2 : 0;
text_pos=(char*) net->buff+head_length+offset+1;
(void) vsprintf(my_const_cast(char*) (text_pos),format,args);