List:Commits« Previous MessageNext Message »
From:Tatiana A. Nurnberg Date:March 19 2009 5:42pm
Subject:bzr commit into mysql-5.1-bugteam branch (azundris:2757) Bug#43153
View as plain text  
#At file:///misc/mysql/forest/43153/51-43153/ based on revid:iggy@stripped

 2757 Tatiana A. Nurnberg	2009-03-19
      Bug#43153: Version comment is too long
      
      mysql-client used static buffer to concatenate server-
      version and version_comment. Sufficiently long comments
      could get cut off. This was harmless, but looked daft.
      
      Now using a dynamic buffer instead.
     @ client/mysql.cc
        Use dynamic rather than static buffer for server
        information. If we can get both version and comment,
        concat them and use that. Otherwise, try to use just
        version. If that fails too, return empty string so
        overly trusting callers do not crash. Release memory
        as needed.

    modified:
      client/mysql.cc
=== modified file 'client/mysql.cc'
--- a/client/mysql.cc	2009-03-19 13:59:10 +0000
+++ b/client/mysql.cc	2009-03-19 17:42:43 +0000
@@ -49,7 +49,7 @@ const char *VER= "14.14";
 #define MAX_COLUMN_LENGTH	     1024
 
 /* Buffer to hold 'version' and 'version_comment' */
-#define MAX_SERVER_VERSION_LENGTH     128
+static char *server_version= NULL;
 
 /* Array of options to pass to libemysqld */
 #define MAX_SERVER_ARGS               64
@@ -1236,6 +1236,7 @@ sig_handler mysql_end(int sig)
   glob_buffer.free();
   old_buffer.free();
   processed_prompt.free();
+  my_free(server_version,MYF(MY_ALLOW_ZERO_PTR));
   my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR));
   my_free(opt_mysql_unix_port,MYF(MY_ALLOW_ZERO_PTR));
   my_free(histfile,MYF(MY_ALLOW_ZERO_PTR));
@@ -4365,16 +4366,11 @@ select_limit, max_join_size);
 static const char *
 server_version_string(MYSQL *con)
 {
-  static char buf[MAX_SERVER_VERSION_LENGTH] = "";
-
   /* Only one thread calls this, so no synchronization is needed */
-  if (buf[0] == '\0')
+  if (server_version == NULL)
   {
-    char *bufp = buf;
     MYSQL_RES *result;
 
-    bufp= strnmov(buf, mysql_get_server_info(con), sizeof buf);
-
     /* "limit 1" is protection against SQL_SELECT_LIMIT=0 */
     if (!mysql_query(con, "select @@version_comment limit 1") &&
         (result = mysql_use_result(con)))
@@ -4382,17 +4378,32 @@ server_version_string(MYSQL *con)
       MYSQL_ROW cur = mysql_fetch_row(result);
       if (cur && cur[0])
       {
-        bufp = strxnmov(bufp, sizeof buf - (bufp - buf), " ", cur[0], NullS);
+        /* version, space, comment, \0 */
+        size_t len= strlen(mysql_get_server_info(con)) + strlen(cur[0]) + 2;
+
+        if ((server_version= (char *) my_malloc(len, MYF(MY_WME))))
+        {
+          char *bufp;
+          bufp = strmov(server_version, mysql_get_server_info(con));
+          bufp = strmov(bufp, " ");
+          (void) strmov(bufp, cur[0]);
+        }
       }
       mysql_free_result(result);
     }
 
-    /* str*nmov doesn't guarantee NUL-termination */
-    if (bufp == buf + sizeof buf)
-      buf[sizeof buf - 1] = '\0';
+    /*
+      If for some reason we didn't get a version_comment, we'll
+      keep things simple.
+    */
+
+    if (server_version == NULL)
+    {
+      server_version= strdup(mysql_get_server_info(con));
+    }
   }
 
-  return buf;
+  return server_version ? server_version : "";
 }
 
 static int


Attachment: [text/bzr-bundle] bzr/azundris@mysql.com-20090319174243-u1nelqacvt77555n.bundle
Thread
bzr commit into mysql-5.1-bugteam branch (azundris:2757) Bug#43153Tatiana A. Nurnberg19 Mar