~ubuntu-branches/ubuntu/quantal/mysql-5.5/quantal-security

« back to all changes in this revision

Viewing changes to mysys/my_access.c

  • Committer: Package Import Robot
  • Author(s): Seth Arnold
  • Date: 2013-04-18 18:15:39 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20130418181539-7uo1w041b4h2ulbs
Tags: 5.5.31-0ubuntu0.12.10.1
* SECURITY UPDATE: Update to 5.5.31 to fix security issues (LP: #1170516)
  - http://www.oracle.com/technetwork/topics/security/cpuapr2013-1899555.html
* debian/patches/71_disable_rpl_tests.patch: refreshed.
* debian/patches/fix-mysqldump-test.patch: removed, fixed differently
  upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
156
156
}
157
157
 
158
158
 
 
159
#ifdef __WIN__
 
160
/**
 
161
  Checks if the drive letter supplied is valid or not. Valid drive
 
162
  letters are A to Z, both lower case and upper case.
 
163
 
 
164
  @param drive_letter : The drive letter to validate.
 
165
 
 
166
  @return TRUE if the drive exists, FALSE otherwise.
 
167
*/
 
168
static my_bool does_drive_exists(char drive_letter)
 
169
{
 
170
  DWORD drive_mask= GetLogicalDrives();
 
171
  drive_letter= toupper(drive_letter);
 
172
 
 
173
  return (drive_letter >= 'A' && drive_letter <= 'Z') &&
 
174
         (drive_mask & (0x1 << (drive_letter - 'A')));
 
175
}
 
176
#endif
 
177
 
 
178
/**
 
179
  Verifies if the file name supplied is allowed or not. On Windows
 
180
  file names with a colon (:) are not allowed because such file names
 
181
  store data in Alternate Data Streams which can be used to hide 
 
182
  the data.
 
183
 
 
184
  @param name contains the file name with or without path
 
185
  @param length contains the length of file name
 
186
 
 
187
  @return TRUE if the file name is allowed, FALSE otherwise.
 
188
*/
 
189
my_bool is_filename_allowed(const char *name __attribute__((unused)),
 
190
                            size_t length __attribute__((unused)))
 
191
{
 
192
#ifdef __WIN__
 
193
  /* 
 
194
    For Windows, check if the file name contains : character.
 
195
    Start from end of path and search if the file name contains :
 
196
  */
 
197
  const char* ch = NULL;
 
198
  for(ch= name + length - 1; ch >= name; --ch)
 
199
  {
 
200
    if (FN_LIBCHAR == *ch || '/' == *ch)
 
201
      break;
 
202
    else if (':' == *ch)
 
203
    {
 
204
      /*
 
205
        File names like C:foobar.txt are allowed since the syntax means
 
206
        file foobar.txt in current directory of C drive. However file
 
207
        names likes CC:foobar are not allowed since this syntax means ADS
 
208
        foobar in file CC.
 
209
      */
 
210
      return ((ch - name == 1) && does_drive_exists(*name));
 
211
    }
 
212
  }
 
213
  return TRUE;
 
214
#else
 
215
  /* For other platforms, file names can contain colon : */
 
216
  return TRUE;
 
217
#endif
 
218
} /* is_filename_allowed */
 
219
 
159
220
#if defined(__WIN__) || defined(__EMX__)
160
221
 
161
222
 
177
238
  const char **reserved_name;
178
239
  DBUG_ENTER("check_if_legal_filename");
179
240
 
 
241
  if(!is_filename_allowed(path, strlen(path)))
 
242
    DBUG_RETURN(1);
 
243
 
180
244
  path+= dirname_length(path);                  /* To start of filename */
181
245
  if (!(end= strchr(path, FN_EXTCHAR)))
182
246
    end= strend(path);