Bug #69752 mysql_plugin removes non-directory type files specified with the basedir option
Submitted: 15 Jul 2013 19:51 Modified: 2 Dec 2013 17:51
Reporter: Davi Arnaut (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S2 (Serious)
Version:5.5 OS:Any
Assigned to:
Tags: basedir, delete, mysql_plugin

[15 Jul 2013 19:51] Davi Arnaut
Description:
The mysql_plugin client inadvertently attempts to remove any filename
specified to the --basedir option. The problem is that if the filename
does not end with a slash, it will attempt to unlink it, which succeeds
for files, but not for directories.

How to repeat:
$ touch /tmp/foobar
$ mysql_plugin --basedir=/tmp/foobar
$ ls -la /tmp/foobar
ls: cannot access /tmp/foobar: No such file or directory

Suggested fix:
I guess the author meant "delete" as in C++'s deallocate memory.

--- a/client/mysql_plugin.c
+++ b/client/mysql_plugin.c
@@ -856,7 +856,7 @@ static int process_options(int argc, char *argv[], char *operation)
       strncat(buff, FN_DIRSEP, sizeof(buff) - strlen(buff) - 1);
 #endif
       buff[sizeof(buff) - 1]= 0;
-      my_delete(opt_basedir, MYF(0));
+      my_free(opt_basedir);
       opt_basedir= my_strdup(buff, MYF(MY_FAE));
     }
   }
[16 Jul 2013 8:42] Umesh Shastry
Hello Davi,

Thank you for the report and contribution.

Thanks,
Umesh
[2 Dec 2013 17:51] Paul Dubois
Noted in 5.5.36, 5.6.16, 5.7.4 changelogs.

For the path specified with the --basedir option, mysql_plugin
attempted to unlink the path rather than free the memory in which the
path was stored.
[4 Dec 2013 9:03] Laurynas Biveinis
5.5$ bzr log -r 4464
------------------------------------------------------------
revno: 4464
committer: Arun Kuruvila <arun.kuruvila@oracle.com>
branch nick: fixed-5-5
timestamp: Mon 2013-09-02 14:53:45 +0530
message:
  Bug #17168602 MYSQL_PLUGIN REMOVES NON-DIRECTORY TYPE FILES 
                SPECIFIED WITH THE BASEDIR OPTION
  
  Description: The mysql_plugin client attempts to remove any
  filename specified to the --basedir option. The problem is 
  that if the filename does not end with a slash, it will 
  attempt to unlink it, which succeeds for files, but not for 
  directories.
  
  Analysis: When we are starting mysql_plugin with basedir 
  option and if we are giving path of a file as basedir, it 
  deletes that file. It was because it uses a function 
  my_delete which unlinks the file path given.
  
  Fix:  As a fix we replace that line using another function 
  my_free, which will only free the  pointer which is having 
  that file path.
[4 Dec 2013 9:09] Laurynas Biveinis
5.5$ bzr log -r 4467
------------------------------------------------------------
revno: 4467
committer: Venkata Sidagam <venkata.sidagam@oracle.com>
branch nick: 5.5
timestamp: Thu 2013-09-05 14:18:43 +0530
message:
  Bug #17168602 MYSQL_PLUGIN REMOVES NON-DIRECTORY TYPE 
                FILES SPECIFIED WITH THE BASEDIR OPTION
  
  Reverting the patch. Because asked for second review.
[4 Dec 2013 9:42] Laurynas Biveinis
It appears that this bug was not fixed after all since the fix was reverted.  client/mysql_plugin.c line 859 still reads my_delete() at bzr revno 4535 (5.5.35)
[16 Dec 2013 15:43] Paul Dubois
The 5.5 fix is in 5.5.36, not 5.5.35.
[17 Dec 2013 5:10] Laurynas Biveinis
Ah, I didn't notice the exact fix version. Sorry for the confusion.
[2 Feb 2014 17:33] Laurynas Biveinis
5.5$ bzr log -r 4551
------------------------------------------------------------
revno: 4551
committer: Arun Kuruvila <arun.kuruvila@oracle.com>
branch nick: mysql-5.5
timestamp: Mon 2013-11-25 12:31:09 +0530
message:
  Bug #17168602 MYSQL_PLUGIN REMOVES NON-DIRECTORY TYPE FILES 
                SPECIFIED WITH THE BASEDIR OPTION 
  
  Description: The mysql_plugin client attempts to remove any
  filename specified to the --basedir option. The problem is
  that if the filename does not end with a slash, it will 
  attempt to unlink it, which succeeds for files, but not for
  directories.
  
  Analysis: When we are starting mysql_plugin with basedir 
  option and if we are giving path of a file as basedir, it 
  deletes that file. It was because it uses a function 
  my_delete which unlinks the file path given.
  
  Fix:  As a fix we replace that line using another function 
  my_free, which will only free the  pointer which is having 
  that file path.