List:Commits« Previous MessageNext Message »
From:Georgi Kodinov Date:May 2 2012 2:59pm
Subject:bzr push into mysql-trunk branch (Georgi.Kodinov:3835 to 3836) WL#5924
View as plain text  
 3836 Georgi Kodinov	2012-05-02
      WL#5924 : Add connect string processing to mysql
      
      Addressed second part of Kristofer's comments:
      1. The overall length of the attributes transferred is 
      encoded as a dynamic length instead of as a fixed 2
      byte string.
      2. Added a write_length_encoded_string() to serialize 
      both name and length for uniformity.
      3. Adjusted some unit test buffer sizes.

    modified:
      libmysqld/lib_sql.cc
      sql-common/client.c
      sql/sql_acl.cc
      storage/perfschema/unittest/pfs_connect_attr-t.cc
 3835 Georgi Kodinov	2012-05-02
      WL#5924 :  Add connect string processing to mysql
      
      wrapped the PSI_CALL into a 
      #ifdef HAVE_PSI_THREAD_INTERFACE (as Chris P suggests)
      for embedded as well.

    modified:
      libmysqld/lib_sql.cc
=== modified file 'libmysqld/lib_sql.cc'
--- a/libmysqld/lib_sql.cc	2012-05-02 11:32:54 +0000
+++ b/libmysqld/lib_sql.cc	2012-05-02 14:54:35 +0000
@@ -742,14 +742,16 @@ emb_transfer_connect_attrs(MYSQL *mysql)
   if (mysql->options.extension &&
       mysql->options.extension->connection_attributes_length)
   {
-    uchar *buf;
+    uchar *buf, *ptr;
     THD *thd= (THD*)mysql->thd;
     size_t length= mysql->options.extension->connection_attributes_length;
+    size_t length_length;
 
-    buf= (uchar *) my_alloca(length + 2);
+    /* 9 = max length of the serialized length */
+    ptr= buf= (uchar *) my_alloca(length + 9);
     send_client_connect_attrs(mysql, buf);
-    PSI_CALL(set_thread_connect_attrs)((char *) (buf + 2), length,
-                                       thd->charset());
+    net_field_length_ll(&ptr);
+    PSI_CALL(set_thread_connect_attrs)((char *) ptr, length, thd->charset());
     my_afree(buf);
   }
 #endif

=== modified file 'sql-common/client.c'
--- a/sql-common/client.c	2012-04-02 14:48:44 +0000
+++ b/sql-common/client.c	2012-05-02 14:54:35 +0000
@@ -2267,6 +2267,16 @@ struct st_mysql_client_plugin *mysql_cli
 };
 
 
+static uchar *
+write_length_encoded_string(uchar *buf, char *string, size_t length)
+{
+  buf= net_store_length(buf, length);
+  memcpy(buf, string, length);
+  buf+= length;
+  return buf;
+}
+
+
 uchar *
 send_client_connect_attrs(MYSQL *mysql, uchar *buf)
 {
@@ -2275,10 +2285,10 @@ send_client_connect_attrs(MYSQL *mysql, 
   {
 
     /* Always store the length if the client supports it */
-    int2store(buf,
-              mysql->options.extension ?
-              mysql->options.extension->connection_attributes_length : 0);
-    buf+= 2;
+    buf= net_store_length(buf,
+                          mysql->options.extension ?
+                          mysql->options.extension->connection_attributes_length :
+                          0);
 
     /* check if we have connection attributes */
     if (mysql->options.extension &&
@@ -2296,18 +2306,8 @@ send_client_connect_attrs(MYSQL *mysql, 
         /* we can't have zero length keys */
         DBUG_ASSERT(key->length);
 
-        /* store the key string */
-        buf= net_store_length(buf, key->length);
-        memcpy(buf, key->str, key->length);
-        buf+= key->length;
-
-        /* store the value string (optionally with zero length) */
-        buf= net_store_length(buf, value->length);
-        if (value->length)
-        {
-          memcpy(buf, value->str, value->length);
-          buf+= value->length;
-        }
+        buf= write_length_encoded_string(buf, key->str, key->length);
+        buf= write_length_encoded_string(buf, value->str, value->length);
       }
     }
   }
@@ -2376,7 +2376,7 @@ static int send_change_user_packet(MCPVI
     mysql->options.extension->connection_attributes_length : 0;
 
   buff= my_alloca(USERNAME_LENGTH + data_len + 1 + NAME_LEN + 2 + NAME_LEN +
-                  connect_attrs_len + 2 /* for the length of the attrs */);
+                  connect_attrs_len + 9 /* for the length of the attrs */);
 
   end= strmake(buff, mysql->user, USERNAME_LENGTH) + 1;
 
@@ -2423,6 +2423,9 @@ error:
   return res;
 }
 
+
+#define MAX_CONNECTION_ATTR_STORAGE_LENGTH 65536
+
 /**
   sends a client authentication packet (second packet in the 3-way handshake)
 
@@ -2464,11 +2467,11 @@ static int send_client_reply_packet(MCPV
      mysql->options.extension) ?
     mysql->options.extension->connection_attributes_length : 0;
 
-  DBUG_ASSERT(connect_attrs_len < 65536);
+  DBUG_ASSERT(connect_attrs_len < MAX_CONNECTION_ATTR_STORAGE_LENGTH);
 
   /* see end= buff+32 below, fixed size of the packet is 32 bytes */
   buff= my_alloca(33 + USERNAME_LENGTH + data_len + NAME_LEN + NAME_LEN +
-                  connect_attrs_len + 2 /* for the length of the attrs */);
+                  connect_attrs_len + 9 /* for the length of the attrs */);
 
   mysql->client_flag|= mysql->options.client_flag;
   mysql->client_flag|= CLIENT_CAPABILITIES;
@@ -4326,8 +4329,6 @@ get_attr_key(LEX_STRING *part, size_t *l
   return (uchar *) part[0].str;
 }
 
-#define MAX_CONNECTION_ATTR_STORAGE_LENGTH UINT_MAX
-
 int STDCALL
 mysql_options4(MYSQL *mysql,enum mysql_option option,
                const void *arg1, const void *arg2)

=== modified file 'sql/sql_acl.cc'
--- a/sql/sql_acl.cc	2012-05-02 11:04:32 +0000
+++ b/sql/sql_acl.cc	2012-05-02 14:54:35 +0000
@@ -8420,15 +8420,20 @@ static bool
 read_client_connect_attrs(char **ptr, size_t *max_bytes_available,
                           const CHARSET_INFO *from_cs)
 {
-  uint length;
+  size_t length, length_length;
+  char *ptr_save;
   /* not enough bytes to hold the length */
-  if (*max_bytes_available < 2)
+  if (*max_bytes_available < 1)
     return true;
 
   /* read the length */
-  length= uint2korr(*ptr);
-  *ptr+= 2;
-  *max_bytes_available-= 2;
+  ptr_save= *ptr;
+  length= net_field_length_ll((uchar **) ptr);
+  length_length= *ptr - ptr_save;
+  if (*max_bytes_available < length_length)
+    return true;
+
+  *max_bytes_available-= length_length;
 
   /* length says there're more data than can fit into the packet */
   if (length > *max_bytes_available)
@@ -8436,7 +8441,7 @@ read_client_connect_attrs(char **ptr, si
 
 #ifdef HAVE_PSI_THREAD_INTERFACE
   if (PSI_CALL(set_thread_connect_attrs)(*ptr, length, from_cs) && log_warnings)
-    sql_print_warning("Connection attributes of length %u were truncated",
+    sql_print_warning("Connection attributes of length %lu were truncated",
                       length);
 #endif
   return false;

=== modified file 'storage/perfschema/unittest/pfs_connect_attr-t.cc'
--- a/storage/perfschema/unittest/pfs_connect_attr-t.cc	2012-04-03 08:35:11 +0000
+++ b/storage/perfschema/unittest/pfs_connect_attr-t.cc	2012-05-02 14:54:35 +0000
@@ -176,8 +176,8 @@ void test_multibyte_lengths()
 
 void test_utf8_parser()
 {
-  /* utf8 max byte length per character is 3*/
-  char name[33 * 3], value[1024 * 3], packet[1500 * 3], *ptr;
+  /* utf8 max byte length per character is 6 */
+  char name[33 * 6], value[1024 * 6], packet[1500 * 6], *ptr;
   uint name_len, value_len;
   bool result;
   const CHARSET_INFO *cs= &my_charset_utf8_bin;

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (Georgi.Kodinov:3835 to 3836) WL#5924Georgi Kodinov2 May