Bug #6761 mysql_list_fields() does not work
Submitted: 23 Nov 2004 0:11 Modified: 12 Jan 2005 17:34
Reporter: Christian Hammers (Silver Quality Contributor) (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.0.22 and 4.1.x OS:Linux (Debian GNU/Linux)
Assigned to: Konstantin Osipov CPU Architecture:Any

[23 Nov 2004 0:11] Christian Hammers
Description:
[ as reported in http://bugs.debian.org/282486 ]

A simple 
  mysql_list_fields(db_conn, table_name, "%");  
does not work as expected. The mysql log file shows the following for table_name="t":
  041123  0:58:55       5 Connect      root@app109.intern on test
                                5 Query         show tables like '%'
                                5 Field List    t %es like '%'
As you can see the string operation produces garbage, I guess the final \0 is missing after
the percent character as the garbage looks just too similar to the previous command.
A correct query (after patching the sourcecode) produces a:
                                8 Field List  t %
and gives the expected results.

How to repeat:
I try to attach a test code snipped.

Suggested fix:
Take a look at sql/sql_parse.cc in function dispatch_command():

    // command not cachable => no gap for data base name
    if (!(thd->query=fields=thd->memdup(packet,thd->query_length+1)))
      break;
    mysql_log.write(thd,command,"%s %s",table_list.real_name,fields);
    fprintf(stderr, "#42# command=|%d|\n", command);
    fprintf(stderr, "#42# table_list.real_name=|%s|\n", table_list.real_name);
    fprintf(stderr, "#42# fields=|%s|\n", fields);

The lines marked with '#42#' produces:
Nov 23 00:58:55 app109 mysqld[6263]: #42# command=|4|
Nov 23 00:58:55 app109 mysqld[6263]: #42# table_list.real_name=|t|
Nov 23 00:58:55 app109 mysqld[6263]: #42# fields=|%es like '%'|

As "ngrep -d lo" only shows:
T 192.168.42.109:32931 -> 192.168.42.109:3306 [AP]
  .....t.gugu                                                                                                 

I would assume that this is the part of the code where the correct network package gets
parsed and an incorrect value for the 'fields' variable is assigned.
[23 Nov 2004 0:11] Christian Hammers
test program

Attachment: mysql-list-fields-test.c (text/x-csrc), 1.63 KiB.

[12 Jan 2005 11:59] Konstantin Osipov
ChangeSet
  1.2025 05/01/12 14:50:00 konstantin@mysql.com +1 -0
  A fix for Bug#6761 "mysql_list_fields() does not work": test
  case will be added to client_test in 4.1
[12 Jan 2005 17:34] Konstantin Osipov
Fixed in 4.0.23, 4.1.9 and 5.0.3