From 75441c41288c8eebc0b7410b9f191eb2b340ebb3 Mon Sep 17 00:00:00 2001
From: "joerg@mysql.com" <>
Date: Tue, 3 Jan 2006 21:04:15 +0100
Subject: [PATCH 1/7] Copyright string fixes (bug#15974), version fix for
 5.0.17a "certified".

---
 configure.in            | 4 ++--
 extra/comp_err.c        | 7 ++++---
 scripts/mysqld_multi.sh | 3 ---
 3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/configure.in b/configure.in
index 9f0867da68a..7d815a2f71a 100644
--- a/configure.in
+++ b/configure.in
@@ -7,7 +7,7 @@ AC_INIT(sql/mysqld.cc)
 AC_CANONICAL_SYSTEM
 # The Docs Makefile.am parses this line!
 # remember to also change ndb version below and update version.c in ndb
-AM_INIT_AUTOMAKE(mysql, 5.0.17)
+AM_INIT_AUTOMAKE(mysql, 5.0.17a)
 AM_CONFIG_HEADER(config.h)
 
 PROTOCOL_VERSION=10
@@ -18,7 +18,7 @@ SHARED_LIB_VERSION=15:0:0
 # ndb version
 NDB_VERSION_MAJOR=5
 NDB_VERSION_MINOR=0
-NDB_VERSION_BUILD=17
+NDB_VERSION_BUILD=17a
 NDB_VERSION_STATUS=""
 
 # Set all version vars based on $VERSION. How do we do this more elegant ?
diff --git a/extra/comp_err.c b/extra/comp_err.c
index d0e387dcd35..e09eea916b5 100644
--- a/extra/comp_err.c
+++ b/extra/comp_err.c
@@ -876,9 +876,10 @@ static void usage(void)
 {
   DBUG_ENTER("usage");
   print_version();
-  printf("This software comes with ABSOLUTELY NO WARRANTY. This is free "
-	 "software,\nand you are welcome to modify and redistribute it under "
-	 "the GPL license\nUsage:\n");
+  printf("This software comes with ABSOLUTELY NO WARRANTY. "
+         "This is free software,\n"
+         "and you are welcome to modify and redistribute it under the GPL license\n"
+         "Usage:\n");
   my_print_help(my_long_options);
   my_print_variables(my_long_options);
   DBUG_VOID_RETURN;
diff --git a/scripts/mysqld_multi.sh b/scripts/mysqld_multi.sh
index b2b85018d7a..2dcc8dc7bc4 100644
--- a/scripts/mysqld_multi.sh
+++ b/scripts/mysqld_multi.sh
@@ -763,9 +763,6 @@ sub usage
   print <<EOF;
 $my_progname version $VER by Jani Tolonen
 
-This software comes with ABSOLUTELY NO WARRANTY. This is free software,
-and you are welcome to modify and redistribute it under the GPL license.
-
 Description:
 $my_progname can be used to start, or stop any number of separate
 mysqld processes running in different TCP/IP ports and UNIX sockets.

From 15bf4a8588f5c80c5df9fdf2d21205ad945dbc46 Mon Sep 17 00:00:00 2001
From: "joerg@mysql.com" <>
Date: Tue, 3 Jan 2006 22:07:31 +0100
Subject: [PATCH 2/7] NDB tools do not accept letters in "NDB_VERSION_BUILD",
 reduce it to plain "17".

---
 configure.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.in b/configure.in
index 7d815a2f71a..630949317b1 100644
--- a/configure.in
+++ b/configure.in
@@ -18,7 +18,7 @@ SHARED_LIB_VERSION=15:0:0
 # ndb version
 NDB_VERSION_MAJOR=5
 NDB_VERSION_MINOR=0
-NDB_VERSION_BUILD=17a
+NDB_VERSION_BUILD=17
 NDB_VERSION_STATUS=""
 
 # Set all version vars based on $VERSION. How do we do this more elegant ?

From 5236782b4bc0abd300cd7c74bb8ac1a93c4839be Mon Sep 17 00:00:00 2001
From: "kent@mysql.com" <>
Date: Tue, 2 May 2006 23:49:21 +0200
Subject: [PATCH 3/7] sql_parse.cc:   buffer overflow and information exposure
 bugs fixed   (reported by Stefano Di Paola) configure.in:   Changed version
 to 5.0.17b

---
 configure.in     |  2 +-
 sql/sql_parse.cc | 19 ++++++++++++++++++-
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/configure.in b/configure.in
index 630949317b1..c62fdd0bd31 100644
--- a/configure.in
+++ b/configure.in
@@ -7,7 +7,7 @@ AC_INIT(sql/mysqld.cc)
 AC_CANONICAL_SYSTEM
 # The Docs Makefile.am parses this line!
 # remember to also change ndb version below and update version.c in ndb
-AM_INIT_AUTOMAKE(mysql, 5.0.17a)
+AM_INIT_AUTOMAKE(mysql, 5.0.17b)
 AM_CONFIG_HEADER(config.h)
 
 PROTOCOL_VERSION=10
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 7e53d435400..f5a4d5dfa2c 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1006,13 +1006,20 @@ static int check_connection(THD *thd)
     *passwd++ : strlen(passwd);
   db= thd->client_capabilities & CLIENT_CONNECT_WITH_DB ?
     db + passwd_len + 1 : 0;
+  uint db_len= db ? strlen(db) : 0;
+
+  if (passwd + passwd_len + db_len > (char *)net->read_pos + pkt_len)
+  {
+    inc_host_errors(&thd->remote.sin_addr);
+    return ER_HANDSHAKE_ERROR;
+  }
 
   /* Since 4.1 all database names are stored in utf8 */
   if (db)
   {
     db_buff[copy_and_convert(db_buff, sizeof(db_buff)-1,
                              system_charset_info,
-                             db, strlen(db),
+                             db, db_len,
                              thd->charset(), &dummy_errors)]= 0;
     db= db_buff;
   }
@@ -1588,7 +1595,17 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
   {
     char *db, *tbl_name;
     uint db_len= *(uchar*) packet;
+    if (db_len >= packet_length || db_len > NAME_LEN)
+    {
+      my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
+      break;
+    }
     uint tbl_len= *(uchar*) (packet + db_len + 1);
+    if (db_len+tbl_len+2 > packet_length || tbl_len > NAME_LEN)
+    {
+      my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
+      break;
+    }
 
     statistic_increment(thd->status_var.com_other, &LOCK_status);
     thd->enable_slow_log= opt_log_slow_admin_statements;

From 5095d77f00943b6d401df4c41c21ae965b477b09 Mon Sep 17 00:00:00 2001
From: "kent@mysql.com" <>
Date: Tue, 23 May 2006 20:43:48 +0200
Subject: [PATCH 4/7] configure.in:   Changed version to 5.0.17c

---
 configure.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.in b/configure.in
index c62fdd0bd31..4b6a05ffa9e 100644
--- a/configure.in
+++ b/configure.in
@@ -7,7 +7,7 @@ AC_INIT(sql/mysqld.cc)
 AC_CANONICAL_SYSTEM
 # The Docs Makefile.am parses this line!
 # remember to also change ndb version below and update version.c in ndb
-AM_INIT_AUTOMAKE(mysql, 5.0.17b)
+AM_INIT_AUTOMAKE(mysql, 5.0.17c)
 AM_CONFIG_HEADER(config.h)
 
 PROTOCOL_VERSION=10

From 97674810b0fab186733ecb6e36ae8431c7bb7472 Mon Sep 17 00:00:00 2001
From: "kent@mysql.com" <>
Date: Wed, 24 May 2006 00:55:53 +0200
Subject: [PATCH 5/7] don't let bugfix for bug#8303 break the bugfix for
 bug#8378 revert the fix for bug#8303 correct the test for bug#8378

---
 mysql-test/r/ctype_sjis.result |  4 ++--
 mysql-test/t/ctype_sjis.test   |  2 +-
 sql/sql_lex.cc                 | 30 +++++-------------------------
 tests/mysql_client_test.c      | 21 ++++++++++++++-------
 4 files changed, 22 insertions(+), 35 deletions(-)

diff --git a/mysql-test/r/ctype_sjis.result b/mysql-test/r/ctype_sjis.result
index d1976a516d2..dab5991b505 100644
--- a/mysql-test/r/ctype_sjis.result
+++ b/mysql-test/r/ctype_sjis.result
@@ -172,6 +172,6 @@ c2h
 ab_def
 drop table t1;
 SET NAMES sjis;
-SELECT HEX('�����@\�\') FROM DUAL;
-HEX('�����@�_�\')
+SELECT HEX('�����@�\') FROM DUAL;
+HEX('�����@�\')
 8DB2939181408C5C
diff --git a/mysql-test/t/ctype_sjis.test b/mysql-test/t/ctype_sjis.test
index 1d807b5e9a8..01e0b334554 100644
--- a/mysql-test/t/ctype_sjis.test
+++ b/mysql-test/t/ctype_sjis.test
@@ -78,6 +78,6 @@ SET collation_connection='sjis_bin';
 
 --character_set sjis
 SET NAMES sjis;
-SELECT HEX('�����@\�\') FROM DUAL;
+SELECT HEX('�����@�\') FROM DUAL;
 
 # End of 4.1 tests
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 16641ad6dd5..fbc8403cbbc 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -295,18 +295,7 @@ static char *get_text(LEX *lex)
       found_escape=1;
       if (lex->ptr == lex->end_of_query)
 	return 0;
-#ifdef USE_MB
-      int l;
-      if (use_mb(cs) &&
-          (l = my_ismbchar(cs,
-                           (const char *)lex->ptr,
-                           (const char *)lex->end_of_query))) {
-          lex->ptr += l;
-          continue;
-      }
-      else
-#endif
-        yySkip();
+      yySkip();
     }
     else if (c == sep)
     {
@@ -335,9 +324,6 @@ static char *get_text(LEX *lex)
       {
 	uchar *to;
 
-        /* Re-use found_escape for tracking state of escapes */
-        found_escape= 0;
-
 	for (to=start ; str != end ; str++)
 	{
 #ifdef USE_MB
@@ -351,7 +337,7 @@ static char *get_text(LEX *lex)
 	      continue;
 	  }
 #endif
-	  if (!found_escape && *str == '\\' && str+1 != end)
+	  if (*str == '\\' && str+1 != end)
 	  {
 	    switch(*++str) {
 	    case 'n':
@@ -377,20 +363,14 @@ static char *get_text(LEX *lex)
 	      *to++= '\\';		// remember prefix for wildcard
 	      /* Fall through */
 	    default:
-              found_escape= 1;
-              str--;
+              *to++= *str;
 	      break;
 	    }
 	  }
-	  else if (!found_escape && *str == sep)
-          {
-            found_escape= 1;
-          }
+	  else if (*str == sep)
+	    *to++= *str++;		// Two ' or "
 	  else
-          {
 	    *to++ = *str;
-            found_escape= 0;
-          }
 	}
 	*to=0;
 	lex->yytoklen=(uint) (to-start);
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index f0566995262..776dc7cb89d 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -11554,25 +11554,26 @@ static void test_bug7990()
 static void test_bug8378()
 {
 #if defined(HAVE_CHARSET_gbk) && !defined(EMBEDDED_LIBRARY)
-  MYSQL *lmysql;
+  MYSQL *old_mysql=mysql;
   char out[9]; /* strlen(TEST_BUG8378)*2+1 */
-  int len;
+  char buf[256];
+  int len, rc;
 
   myheader("test_bug8378");
 
   if (!opt_silent)
     fprintf(stdout, "\n Establishing a test connection ...");
-  if (!(lmysql= mysql_init(NULL)))
+  if (!(mysql= mysql_init(NULL)))
   {
     myerror("mysql_init() failed");
     exit(1);
   }
-  if (mysql_options(lmysql, MYSQL_SET_CHARSET_NAME, "gbk"))
+  if (mysql_options(mysql, MYSQL_SET_CHARSET_NAME, "gbk"))
   {
     myerror("mysql_options() failed");
     exit(1);
   }
-  if (!(mysql_real_connect(lmysql, opt_host, opt_user,
+  if (!(mysql_real_connect(mysql, opt_host, opt_user,
                            opt_password, current_db, opt_port,
                            opt_unix_socket, 0)))
   {
@@ -11582,12 +11583,18 @@ static void test_bug8378()
   if (!opt_silent)
     fprintf(stdout, " OK");
 
-  len= mysql_real_escape_string(lmysql, out, TEST_BUG8378_IN, 4);
+  len= mysql_real_escape_string(mysql, out, TEST_BUG8378_IN, 4);
 
   /* No escaping should have actually happened. */
   DIE_UNLESS(memcmp(out, TEST_BUG8378_OUT, len) == 0);
 
-  mysql_close(lmysql);
+  sprintf(buf, "SELECT '%s'", out);
+  rc=mysql_real_query(mysql, buf, strlen(buf));
+  myquery(rc);
+
+  mysql_close(mysql);
+
+  mysql=old_mysql;
 #endif
 }
 

From 3be04952990c90654d9ad180f92819dd2e2a98f1 Mon Sep 17 00:00:00 2001
From: "kent@mysql.com" <>
Date: Wed, 24 May 2006 01:05:20 +0200
Subject: [PATCH 6/7] configure.in:   Updated release number 4.1.16a

---
 configure.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.in b/configure.in
index 41475ffcd4a..602f99fb168 100644
--- a/configure.in
+++ b/configure.in
@@ -5,7 +5,7 @@ AC_INIT(sql/mysqld.cc)
 AC_CANONICAL_SYSTEM
 # The Docs Makefile.am parses this line!
 # remember to also change ndb version below and update version.c in ndb
-AM_INIT_AUTOMAKE(mysql, 4.1.16)
+AM_INIT_AUTOMAKE(mysql, 4.1.16a)
 AM_CONFIG_HEADER(config.h)
 
 PROTOCOL_VERSION=10

From 0b10712033b3f9ba607d0e4cb0301214a9bdcb15 Mon Sep 17 00:00:00 2001
From: "kent@mysql.com" <>
Date: Wed, 24 May 2006 11:33:17 +0200
Subject: [PATCH 7/7] configure.in:   Changed version to 5.0.22

---
 configure.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/configure.in b/configure.in
index 174c9a16d8e..74ac7ed4574 100644
--- a/configure.in
+++ b/configure.in
@@ -7,7 +7,7 @@ AC_INIT(sql/mysqld.cc)
 AC_CANONICAL_SYSTEM
 # The Docs Makefile.am parses this line!
 # remember to also change ndb version below and update version.c in ndb
-AM_INIT_AUTOMAKE(mysql, 5.0.21)
+AM_INIT_AUTOMAKE(mysql, 5.0.22)
 AM_CONFIG_HEADER(config.h)
 
 PROTOCOL_VERSION=10
@@ -19,7 +19,7 @@ SHARED_LIB_VERSION=$SHARED_LIB_MAJOR_VERSION:0:0
 # ndb version
 NDB_VERSION_MAJOR=5
 NDB_VERSION_MINOR=0
-NDB_VERSION_BUILD=21
+NDB_VERSION_BUILD=22
 NDB_VERSION_STATUS=""
 
 # Set all version vars based on $VERSION. How do we do this more elegant ?