@@ -54,24 +54,111 @@ int my_access(const char *path, int amode)
54
54
55
55
#endif /* __WIN__ */
56
56
57
- #if defined(MSDOS ) || defined(__WIN__ ) || defined(__EMX__ )
58
57
59
58
/*
60
59
List of file names that causes problem on windows
61
60
62
61
NOTE that one can also not have file names of type CON.TXT
62
+
63
+ NOTE: it is important to keep "CLOCK$" on the first place,
64
+ we skip it in check_if_legal_tablename.
63
65
*/
64
-
65
66
static const char * reserved_names []=
66
67
{
67
- "CON" , "PRN" , "AUX" , "NUL" , "COM1" , "COM2" , "COM3" , "COM4" , "COM5" , "COM6" ,
68
- "COM7" , "COM8" , "COM9" , "LPT1" , "LPT2" , "LPT3" , "LPT4" , "LPT5" , "LPT6" ,
69
- "LPT7" , "LPT8" , "LPT9" , "CLOCK$" ,
68
+ "CLOCK$" ,
69
+ "CON" , "PRN" , "AUX" , "NUL" ,
70
+ "COM1" , "COM2" , "COM3" , "COM4" , "COM5" , "COM6" , "COM7" , "COM8" , "COM9" ,
71
+ "LPT1" , "LPT2" , "LPT3" , "LPT4" , "LPT5" , "LPT6" , "LPT7" , "LPT8" , "LPT9" ,
70
72
NullS
71
73
};
72
74
73
75
#define MAX_RESERVED_NAME_LENGTH 6
74
76
77
+
78
+ /*
79
+ Looks up a null-terminated string in a list,
80
+ case insensitively.
81
+
82
+ SYNOPSIS
83
+ str_list_find()
84
+ list list of items
85
+ str item to find
86
+
87
+ RETURN
88
+ 0 ok
89
+ 1 reserved file name
90
+ */
91
+ static int str_list_find (const char * * list , const char * str )
92
+ {
93
+ const char * * name ;
94
+ for (name = list ; * name ; name ++ )
95
+ {
96
+ if (!my_strcasecmp (& my_charset_latin1 , * name , str ))
97
+ return 1 ;
98
+ }
99
+ return 0 ;
100
+ }
101
+
102
+
103
+ /*
104
+ A map for faster reserved_names lookup,
105
+ helps to avoid loops in many cases.
106
+ 1 - can be the first letter
107
+ 2 - can be the second letter
108
+ 4 - can be the third letter
109
+ */
110
+ static char reserved_map [256 ]=
111
+ {
112
+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,0 , /* ................ */
125
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , /* ................ */
126
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , /* ................ */
127
+ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 /* ................ */
128
+ };
129
+
130
+
131
+ /*
132
+ Check if a table name may cause problems
133
+
134
+ SYNOPSIS
135
+ check_if_legal_tablename
136
+ name Table name (without any extensions)
137
+
138
+ DESCRIPTION
139
+ We don't check 'CLOCK$' because dollar sign is encoded as @0024,
140
+ making table file name 'CLOCK@0024', which is safe.
141
+ This is why we start lookup from the second element
142
+ (i.e. &reserver_name[1])
143
+
144
+ RETURN
145
+ 0 ok
146
+ 1 reserved file name
147
+ */
148
+
149
+ int check_if_legal_tablename (const char * name )
150
+ {
151
+ DBUG_ENTER ("check_if_legal_tablename" );
152
+ DBUG_RETURN ((reserved_map [(uchar ) name [0 ]] & 1 ) &&
153
+ (reserved_map [(uchar ) name [1 ]] & 2 ) &&
154
+ (reserved_map [(uchar ) name [2 ]] & 4 ) &&
155
+ str_list_find (& reserved_names [1 ], name ));
156
+ }
157
+
158
+
159
+ #if defined(MSDOS ) || defined(__WIN__ ) || defined(__EMX__ )
160
+
161
+
75
162
/*
76
163
Check if a path will access a reserverd file name that may cause problems
77
164
0 commit comments