1- /* Copyright (c) 2000, 2011 , Oracle and/or its affiliates. All rights reserved.
1+ /* Copyright (c) 2000, 2017 , Oracle and/or its affiliates. All rights reserved.
22
33 This program is free software; you can redistribute it and/or modify
44 it under the terms of the GNU General Public License as published by
@@ -78,6 +78,7 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
7878 ulong rec_per_key_part [HA_MAX_POSSIBLE_KEY * MI_MAX_KEY_SEG ];
7979 my_off_t key_root [HA_MAX_POSSIBLE_KEY ],key_del [MI_MAX_KEY_BLOCK_SIZE ];
8080 ulonglong max_key_file_length , max_data_file_length ;
81+ ST_FILE_ID file_id = {0 , 0 };
8182 DBUG_ENTER ("mi_open" );
8283
8384 LINT_INIT (m_info );
@@ -89,11 +90,15 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
8990
9091 realpath_err = my_realpath (name_buff ,
9192 fn_format (org_name ,name ,"" ,MI_NAME_IEXT ,4 ),MYF (0 ));
92- if (my_is_symlink (org_name ) &&
93- (realpath_err || (* myisam_test_invalid_symlink )(name_buff )))
93+ if (my_is_symlink (name_buff , & file_id ))
9494 {
95- my_errno = HA_WRONG_CREATE_OPTION ;
96- DBUG_RETURN (NULL );
95+ if (realpath_err ||
96+ (* myisam_test_invalid_symlink )(name_buff ) ||
97+ my_is_symlink (name_buff , & file_id ))
98+ {
99+ my_errno = HA_WRONG_CREATE_OPTION ;
100+ DBUG_RETURN (NULL );
101+ }
97102 }
98103
99104 mysql_mutex_lock (& THR_LOCK_myisam );
@@ -113,17 +118,28 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
113118 my_errno = HA_ERR_CRASHED ;
114119 goto err ;
115120 });
121+ DEBUG_SYNC_C ("before_opening_indexfile" );
116122 if ((kfile = mysql_file_open (mi_key_file_kfile ,
117123 name_buff ,
118- (open_mode = O_RDWR ) | O_SHARE , MYF (0 ))) < 0 )
124+ (open_mode = O_RDWR ) | O_SHARE | O_NOFOLLOW ,
125+ MYF (0 ))) < 0 )
119126 {
120127 if ((errno != EROFS && errno != EACCES ) ||
121128 mode != O_RDONLY ||
122129 (kfile = mysql_file_open (mi_key_file_kfile ,
123130 name_buff ,
124- (open_mode = O_RDONLY ) | O_SHARE , MYF (0 ))) < 0 )
131+ (open_mode = O_RDONLY ) | O_SHARE | O_NOFOLLOW ,
132+ MYF (0 ))) < 0 )
125133 goto err ;
126134 }
135+
136+ if (!my_is_same_file (kfile , & file_id ))
137+ {
138+ mysql_file_close (kfile , MYF (0 ));
139+ my_errno = HA_WRONG_CREATE_OPTION ;
140+ goto err ;
141+ }
142+
127143 share -> mode = open_mode ;
128144 errpos = 1 ;
129145 if (mysql_file_read (kfile , share -> state .header .file_version , head_length ,
@@ -1206,24 +1222,36 @@ int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, const char *org_name,
12061222{
12071223 char * data_name = share -> data_file_name ;
12081224 char real_data_name [FN_REFLEN ];
1225+ ST_FILE_ID file_id = {0 , 0 };
12091226
12101227 if (org_name )
12111228 {
12121229 fn_format (real_data_name ,org_name ,"" ,MI_NAME_DEXT ,4 );
1213- if (my_is_symlink (real_data_name ))
1230+ if (my_is_symlink (real_data_name , & file_id ))
12141231 {
12151232 if (my_realpath (real_data_name , real_data_name , MYF (0 )) ||
1216- (* myisam_test_invalid_symlink )(real_data_name ))
1233+ (* myisam_test_invalid_symlink )(real_data_name ) ||
1234+ my_is_symlink (real_data_name , & file_id ))
12171235 {
12181236 my_errno = HA_WRONG_CREATE_OPTION ;
12191237 return 1 ;
12201238 }
12211239 data_name = real_data_name ;
12221240 }
12231241 }
1242+ DEBUG_SYNC_C ("before_opening_datafile" );
12241243 info -> dfile = mysql_file_open (mi_key_file_dfile ,
1225- data_name , share -> mode | O_SHARE , MYF (MY_WME ));
1226- return info -> dfile >= 0 ? 0 : 1 ;
1244+ data_name , share -> mode | O_SHARE | O_NOFOLLOW ,
1245+ MYF (MY_WME ));
1246+ if (info -> dfile < 0 )
1247+ return 1 ;
1248+ if (org_name && !my_is_same_file (info -> dfile , & file_id ))
1249+ {
1250+ mysql_file_close (info -> dfile , MYF (0 ));
1251+ my_errno = HA_WRONG_CREATE_OPTION ;
1252+ return 1 ;
1253+ }
1254+ return 0 ;
12271255}
12281256
12291257
0 commit comments