~ubuntu-branches/ubuntu/maverick/mysql-5.1/maverick-proposed

« back to all changes in this revision

Viewing changes to sql/sql_plugin.cc

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 14:16:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20120222141605-nxlu9yzc6attylc2
Tags: upstream-5.1.61
ImportĀ upstreamĀ versionĀ 5.1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2005 MySQL AB
 
1
/*
 
2
   Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
2
3
 
3
4
   This program is free software; you can redistribute it and/or modify
4
5
   it under the terms of the GNU General Public License as published by
11
12
 
12
13
   You should have received a copy of the GNU General Public License
13
14
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 
16
*/
15
17
 
16
18
#include "mysql_priv.h"
17
19
#include <my_pthread.h>
231
233
#endif /* EMBEDDED_LIBRARY */
232
234
 
233
235
 
 
236
/**
 
237
   Check if the provided path is valid in the sense that it does cause
 
238
   a relative reference outside the directory.
 
239
 
 
240
   @note Currently, this function only check if there are any
 
241
   characters in FN_DIRSEP in the string, but it might change in the
 
242
   future.
 
243
 
 
244
   @code
 
245
   check_valid_path("../foo.so") -> true
 
246
   check_valid_path("foo.so") -> false
 
247
   @endcode
 
248
 */
 
249
bool check_valid_path(const char *path, size_t len)
 
250
{
 
251
  size_t prefix= my_strcspn(files_charset_info, path, path + len, FN_DIRSEP);
 
252
  return  prefix < len;
 
253
}
 
254
 
 
255
 
234
256
/****************************************************************************
235
257
  Value type thunks, allows the C world to play in the C++ world
236
258
****************************************************************************/
354
376
  struct st_plugin_dl *tmp, plugin_dl;
355
377
  void *sym;
356
378
  DBUG_ENTER("plugin_dl_add");
 
379
  DBUG_PRINT("enter", ("dl->str: '%s', dl->length: %d",
 
380
                       dl->str, (int) dl->length));
357
381
  plugin_dir_len= strlen(opt_plugin_dir);
358
382
  /*
359
383
    Ensure that the dll doesn't have a path.
360
384
    This is done to ensure that only approved libraries from the
361
385
    plugin directory are used (to make this even remotely secure).
362
386
  */
363
 
  if (my_strchr(files_charset_info, dl->str, dl->str + dl->length, FN_LIBCHAR) ||
 
387
  if (check_valid_path(dl->str, dl->length) ||
364
388
      check_string_char_length((LEX_STRING *) dl, "", NAME_CHAR_LEN,
365
389
                               system_charset_info, 1) ||
366
390
      plugin_dir_len + dl->length + 1 >= FN_REFLEN)
473
497
    {
474
498
      free_plugin_mem(&plugin_dl);
475
499
      if (report & REPORT_TO_USER)
476
 
        my_error(ER_OUTOFMEMORY, MYF(0), plugin_dl.dl.length);
 
500
        my_error(ER_OUTOFMEMORY, MYF(0),
 
501
                 static_cast<int>(plugin_dl.dl.length));
477
502
      if (report & REPORT_TO_LOG)
478
 
        sql_print_error(ER(ER_OUTOFMEMORY), plugin_dl.dl.length);
 
503
        sql_print_error(ER(ER_OUTOFMEMORY),
 
504
                        static_cast<int>(plugin_dl.dl.length));
479
505
      DBUG_RETURN(0);
480
506
    }
481
507
    /*
498
524
  {
499
525
    free_plugin_mem(&plugin_dl);
500
526
    if (report & REPORT_TO_USER)
501
 
      my_error(ER_OUTOFMEMORY, MYF(0), plugin_dl.dl.length);
 
527
      my_error(ER_OUTOFMEMORY, MYF(0), static_cast<int>(plugin_dl.dl.length));
502
528
    if (report & REPORT_TO_LOG)
503
 
      sql_print_error(ER(ER_OUTOFMEMORY), plugin_dl.dl.length);
 
529
      sql_print_error(ER(ER_OUTOFMEMORY),
 
530
                      static_cast<int>(plugin_dl.dl.length));
504
531
    DBUG_RETURN(0);
505
532
  }
506
533
  plugin_dl.dl.length= copy_and_convert(plugin_dl.dl.str, plugin_dl.dl.length,
512
539
  {
513
540
    free_plugin_mem(&plugin_dl);
514
541
    if (report & REPORT_TO_USER)
515
 
      my_error(ER_OUTOFMEMORY, MYF(0), sizeof(struct st_plugin_dl));
 
542
      my_error(ER_OUTOFMEMORY, MYF(0),
 
543
               static_cast<int>(sizeof(struct st_plugin_dl)));
516
544
    if (report & REPORT_TO_LOG)
517
 
      sql_print_error(ER(ER_OUTOFMEMORY), sizeof(struct st_plugin_dl));
 
545
      sql_print_error(ER(ER_OUTOFMEMORY),
 
546
                      static_cast<int>(sizeof(struct st_plugin_dl)));
518
547
    DBUG_RETURN(0);
519
548
  }
520
549
  DBUG_RETURN(tmp);
3030
3059
    Allocate temporary space for the value of the tristate.
3031
3060
    This option will have a limited lifetime and is not used beyond
3032
3061
    server initialization.
3033
 
    GET_ENUM value is an integer.
 
3062
    GET_ENUM value is a unsigned long integer.
3034
3063
  */
3035
3064
  options[0].value= options[1].value= (uchar **)alloc_root(mem_root,
3036
 
                                                          sizeof(int));
3037
 
  *((uint*) options[0].value)= *((uint*) options[1].value)=
3038
 
    (uint) options[0].def_value;
 
3065
                                                          sizeof(ulong));
 
3066
  *((ulong*) options[0].value)= *((ulong*) options[1].value)=
 
3067
    (ulong) options[0].def_value;
3039
3068
 
3040
3069
  options+= 2;
3041
3070
 
3319
3348
     Set plugin loading policy from option value. First element in the option
3320
3349
     list is always the <plugin name> option value.
3321
3350
    */
3322
 
    plugin_load_policy= (enum_plugin_load_policy)*(uint*)opts[0].value;
 
3351
    plugin_load_policy= (enum_plugin_load_policy)*(ulong*)opts[0].value;
3323
3352
  }
3324
3353
 
3325
3354
  disable_plugin= (plugin_load_policy == PLUGIN_OFF);