Bug #19137 myx_util_functions.c / unquote_identifier mangles result
Submitted: 17 Apr 2006 12:39 Modified: 19 Apr 2006 12:11
Reporter: John Yodsnukis (Basic Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Workbench Preview Severity:S2 (Serious)
Version:1.0.5beta svn revision 1239 OS:Linux (Linux (Gentoo on PPC))
Assigned to: CPU Architecture:Any

[17 Apr 2006 12:39] John Yodsnukis
Description:
myx_util_functions.c/unquote_identifier function mangles the string it is unquoting.  Probably a pascal to c array index mistake.

How to repeat:
char* unquote_identifier(char *table_name)
{
  char *beginning= table_name;

  if (*table_name == '"' || *table_name == '`')
  {
    size_t len = strlen(table_name) -3;
    strncpy(beginning, table_name + 1, len);
    beginning[len + 1] = '\0';
  };
  return beginning;
}

table_name="abcde" will return table_name=abcdd

Suggested fix:
char* unquote_identifier(char *table_name)
{
  char *beginning= table_name;

  if (*table_name == '"' || *table_name == '`')
  {
//  size_t len = strlen(table_name) -3;
    size_t len = strlen(table_name) - 2;
    strncpy(beginning, table_name + 1, len);
//  beginning[len + 1] = '\0';
    beginning[len] = '\0';
  };
  return beginning;
}
[17 Apr 2006 16:16] MySQL Verification Team
Thank you for the bug report. I downloaded the source package and looks
has a different code for tha function:

/*
 * Normally a mysql identifier is quoted with ` (backtick).
 * In Ansi Mode " is also a valid identifier.
 * This function handles both.
 */
char* unquote_identifier(char *table_name)
{
  char quote_char;
  int write_back= -1;
  char previous_symbol= 0;
  char *beginning= table_name;

  if (*table_name == '"' || *table_name == '`')
    quote_char= *table_name++;
  else
    return table_name; /* the string is not quoted */

  for(;*table_name; table_name++)
  {
    if (table_name[0] == quote_char || table_name[0] == '\\')
    {
      if (table_name[0]!=previous_symbol)
      {
        previous_symbol= table_name[0];
      }
      else
      {
        write_back--;
        previous_symbol= 0;
      }
    }

    table_name[write_back]= *table_name;
  }

  table_name[write_back-1]= '\0';

  return beginning;
}

Where you got that source?

Thanks in advance.
[17 Apr 2006 16:53] John Yodsnukis
revision 1239 of svn:

http://svn.mysql.com/svnpublic/mysql-gui-common/library_util/source/myx_util_functions.c

It's been changed in the svn repository since the beta.
[18 Apr 2006 20:55] Alfredo Kojima
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html
[19 Apr 2006 12:11] John Yodsnukis
Thank you for the prompt attention.