components/mysql-5-1/patches/bug40980.patch
branchs11u1-sru
changeset 2686 1362b3693ee1
equal deleted inserted replaced
2682:6bb5d5f3a128 2686:1362b3693ee1
       
     1 # Fixes Solaris bug #15688738
       
     2 # ===========================
       
     3 
       
     4 --- storage/myisam/mi_delete_table.c	2006-12-31 00:32:21 +0000
       
     5 +++ storage/myisam/mi_delete_table.c	2010-04-01 14:49:02 +0000
       
     6 @@ -19,6 +19,41 @@
       
     7  
       
     8  #include "fulltext.h"
       
     9  
       
    10 +
       
    11 +/**
       
    12 +  Remove MyISAM data/index file safely
       
    13 +
       
    14 +  @details
       
    15 +    If name is a symlink and file it is pointing to is not in
       
    16 +    data directory, file is also removed.
       
    17 +
       
    18 +  @param name    file to remove
       
    19 +  
       
    20 +  @returns
       
    21 +    0 on success or my_errno on failure
       
    22 +*/
       
    23 +
       
    24 +static int _mi_safe_delete_file(const char *name)
       
    25 +{
       
    26 +  DBUG_ENTER("_mi_safe_delete_file");
       
    27 +  if (my_is_symlink(name) && (*myisam_test_invalid_symlink)(name))
       
    28 +  {
       
    29 +    /*
       
    30 +      Symlink is pointing to file in data directory.
       
    31 +      Remove symlink, keep file.
       
    32 +    */
       
    33 +    if (my_delete(name, MYF(MY_WME)))
       
    34 +      DBUG_RETURN(my_errno);
       
    35 +  }
       
    36 +  else
       
    37 +  {
       
    38 +    if (my_delete_with_symlink(name, MYF(MY_WME)))
       
    39 +      DBUG_RETURN(my_errno);
       
    40 +  }
       
    41 +  DBUG_RETURN(0);
       
    42 +}
       
    43 +
       
    44 +
       
    45  int mi_delete_table(const char *name)
       
    46  {
       
    47    char from[FN_REFLEN];
       
    48 @@ -58,12 +93,12 @@ int mi_delete_table(const char *name)
       
    49  #endif /* USE_RAID */
       
    50  
       
    51    fn_format(from,name,"",MI_NAME_IEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
       
    52 -  if (my_delete_with_symlink(from, MYF(MY_WME)))
       
    53 +  if (_mi_safe_delete_file(from))
       
    54      DBUG_RETURN(my_errno);
       
    55    fn_format(from,name,"",MI_NAME_DEXT,MY_UNPACK_FILENAME|MY_APPEND_EXT);
       
    56  #ifdef USE_RAID
       
    57    if (raid_type)
       
    58      DBUG_RETURN(my_raid_delete(from, raid_chunks, MYF(MY_WME)) ? my_errno : 0);
       
    59  #endif
       
    60 -  DBUG_RETURN(my_delete_with_symlink(from, MYF(MY_WME)) ? my_errno : 0);
       
    61 +  DBUG_RETURN(_mi_safe_delete_file(from));
       
    62  }
       
    63 
       
    64 --- mysql-test/r/bug40980.result	1970-01-01 01:00:00.000000000 +0100
       
    65 +++ mysql-test/r/bug40980.result	2013-06-20 21:42:12.280326900 +0200
       
    66 @@ -0,0 +1,14 @@
       
    67 +drop table if exists t1,t2,t7,t8,t9;
       
    68 +drop database if exists mysqltest;
       
    69 +#
       
    70 +# BUG#40980 - Drop table can remove another MyISAM table's
       
    71 +#             data and index files
       
    72 +#
       
    73 +CREATE TABLE user(a INT) DATA DIRECTORY='MYSQL_TMP_DIR/mysql'
       
    74 +                             INDEX DIRECTORY='MYSQL_TMP_DIR/mysql';
       
    75 +FLUSH TABLE user;
       
    76 +# Symlinking mysql database to tmpdir
       
    77 +FLUSH TABLE mysql.user;
       
    78 +DROP TABLE user;
       
    79 +FLUSH TABLE mysql.user;
       
    80 +SELECT * FROM mysql.user;
       
    81 
       
    82 --- mysql-test/t/bug40980.test	1970-01-01 01:00:00.000000000 +0100
       
    83 +++ mysql-test/t/bug40980.test	2013-06-20 21:41:50.813398500 +0200
       
    84 @@ -0,0 +1,29 @@
       
    85 +--source include/have_symlink.inc
       
    86 +--source include/not_windows.inc
       
    87 +
       
    88 +--disable_warnings
       
    89 +drop table if exists t1,t2,t7,t8,t9;
       
    90 +drop database if exists mysqltest;
       
    91 +--enable_warnings
       
    92 +
       
    93 +--echo #
       
    94 +--echo # BUG#40980 - Drop table can remove another MyISAM table's
       
    95 +--echo #             data and index files
       
    96 +--echo #
       
    97 +--mkdir $MYSQL_TMP_DIR/mysql 
       
    98 +--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR
       
    99 +eval CREATE TABLE user(a INT) DATA DIRECTORY='$MYSQL_TMP_DIR/mysql'
       
   100 +                             INDEX DIRECTORY='$MYSQL_TMP_DIR/mysql';
       
   101 +FLUSH TABLE user;
       
   102 +--echo # Symlinking mysql database to tmpdir
       
   103 +--remove_file $MYSQL_TMP_DIR/mysql/user.MYD
       
   104 +--remove_file $MYSQL_TMP_DIR/mysql/user.MYI
       
   105 +--rmdir $MYSQL_TMP_DIR/mysql
       
   106 +--exec ln -s $MYSQLD_DATADIR/mysql $MYSQL_TMP_DIR/mysql
       
   107 +FLUSH TABLE mysql.user;
       
   108 +DROP TABLE user;
       
   109 +FLUSH TABLE mysql.user;
       
   110 +--disable_result_log
       
   111 +SELECT * FROM mysql.user;
       
   112 +--enable_result_log
       
   113 +--remove_file $MYSQL_TMP_DIR/mysql