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

« back to all changes in this revision

Viewing changes to sql/sql_show.cc

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2015-07-16 13:59:34 UTC
  • mfrom: (1.1.18)
  • Revision ID: package-import@ubuntu.com-20150716135934-plzpylrt211i3se4
Tags: 5.5.44-0ubuntu0.12.04.1
* SECURITY UPDATE: Update to 5.5.44 to fix security issues (LP: #1475294)
  - http://www.oracle.com/technetwork/topics/security/cpujul2015-2367936.html
  - CVE-2015-2582
  - CVE-2015-2620
  - CVE-2015-2643
  - CVE-2015-2648
  - CVE-2015-4737
  - CVE-2015-4752
  - CVE-2015-4757

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
 
1
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
2
2
 
3
3
   This program is free software; you can redistribute it and/or modify
4
4
   it under the terms of the GNU General Public License as published by
404
404
 
405
405
find_files_result
406
406
find_files(THD *thd, List<LEX_STRING> *files, const char *db,
407
 
           const char *path, const char *wild, bool dir)
 
407
           const char *path, const char *wild, bool dir, MEM_ROOT *tmp_mem_root)
408
408
{
409
409
  uint i;
410
410
  char *ext;
411
411
  MY_DIR *dirp;
412
412
  FILEINFO *file;
413
413
  LEX_STRING *file_name= 0;
 
414
  MEM_ROOT **root_ptr= NULL, *old_root= NULL;
414
415
  uint file_name_len;
415
416
#ifndef NO_EMBEDDED_ACCESS_CHECKS
416
417
  uint col_access=thd->col_access;
440
441
    DBUG_RETURN(FIND_FILES_DIR);
441
442
  }
442
443
 
 
444
  if (tmp_mem_root)
 
445
  {
 
446
    root_ptr= my_pthread_getspecific_ptr(MEM_ROOT**, THR_MALLOC);
 
447
    old_root= *root_ptr;
 
448
    *root_ptr= tmp_mem_root;
 
449
  }
 
450
 
443
451
  for (i=0 ; i < (uint) dirp->number_off_files  ; i++)
444
452
  {
445
453
    char uname[NAME_LEN + 1];                   /* Unencoded name */
519
527
        continue;
520
528
    }
521
529
#endif
522
 
    if (!(file_name= 
523
 
          thd->make_lex_string(file_name, uname, file_name_len, TRUE)) ||
 
530
    if (!(file_name= tmp_mem_root ?
 
531
                     make_lex_string_root(tmp_mem_root, file_name, uname,
 
532
                                          file_name_len, TRUE) :
 
533
                     thd->make_lex_string(file_name, uname,
 
534
                                          file_name_len, TRUE)) ||
524
535
        files->push_back(file_name))
525
536
    {
526
537
      my_dirend(dirp);
532
543
 
533
544
  (void) ha_find_files(thd, db, path, wild, dir, files);
534
545
 
 
546
  if (tmp_mem_root)
 
547
    *root_ptr= old_root;
 
548
 
535
549
  DBUG_RETURN(FIND_FILES_OK);
536
550
}
537
551
 
1139
1153
                      to tailor the format of the statement.  Can be
1140
1154
                      NULL, in which case only SQL_MODE is considered
1141
1155
                      when building the statement.
 
1156
    show_database     If true, then print the database before the table
 
1157
                      name. The database name is only printed in the event
 
1158
                      that it is different from the current database.
 
1159
                      If false, then do not print the database before
 
1160
                      the table name.
1142
1161
  
1143
1162
  NOTE
1144
1163
    Currently always return 0, but might return error code in the
1834
1853
      Security_context *tmp_sctx= tmp->security_ctx;
1835
1854
      struct st_my_thread_var *mysys_var;
1836
1855
      if ((tmp->vio_ok() || tmp->system_thread) &&
1837
 
          (!user || (tmp_sctx->user && !strcmp(tmp_sctx->user, user))))
 
1856
          (!user || (!tmp->system_thread && tmp_sctx->user &&
 
1857
                     !strcmp(tmp_sctx->user, user))))
1838
1858
      {
1839
1859
        thread_info *thd_info= new thread_info;
1840
1860
 
1944
1964
      const char *val, *db;
1945
1965
 
1946
1966
      if ((!tmp->vio_ok() && !tmp->system_thread) ||
1947
 
          (user && (!tmp_sctx->user || strcmp(tmp_sctx->user, user))))
 
1967
          (user && (tmp->system_thread || !tmp_sctx->user ||
 
1968
                    strcmp(tmp_sctx->user, user))))
1948
1969
        continue;
1949
1970
 
1950
1971
      restore_record(table, s->default_values);
2875
2896
 
2876
2897
int make_db_list(THD *thd, List<LEX_STRING> *files,
2877
2898
                 LOOKUP_FIELD_VALUES *lookup_field_vals,
2878
 
                 bool *with_i_schema)
 
2899
                 bool *with_i_schema, MEM_ROOT *tmp_mem_root)
2879
2900
{
2880
2901
  LEX_STRING *i_s_name_copy= 0;
2881
2902
  i_s_name_copy= thd->make_lex_string(i_s_name_copy,
2899
2920
        return 1;
2900
2921
    }
2901
2922
    return (find_files(thd, files, NullS, mysql_data_home,
2902
 
                       lookup_field_vals->db_value.str, 1) != FIND_FILES_OK);
 
2923
                       lookup_field_vals->db_value.str, 1, tmp_mem_root) !=
 
2924
                      FIND_FILES_OK);
2903
2925
  }
2904
2926
 
2905
2927
 
2941
2963
    return 1;
2942
2964
  *with_i_schema= 1;
2943
2965
  return (find_files(thd, files, NullS,
2944
 
                     mysql_data_home, NullS, 1) != FIND_FILES_OK);
 
2966
                     mysql_data_home, NullS, 1, tmp_mem_root) != FIND_FILES_OK);
2945
2967
}
2946
2968
 
2947
2969
 
3049
3071
static int
3050
3072
make_table_name_list(THD *thd, List<LEX_STRING> *table_names, LEX *lex,
3051
3073
                     LOOKUP_FIELD_VALUES *lookup_field_vals,
3052
 
                     bool with_i_schema, LEX_STRING *db_name)
 
3074
                     bool with_i_schema, LEX_STRING *db_name,
 
3075
                     MEM_ROOT *tmp_mem_root)
3053
3076
{
3054
3077
  char path[FN_REFLEN + 1];
3055
3078
  build_table_filename(path, sizeof(path) - 1, db_name->str, "", "", 0);
3103
3126
                              lookup_field_vals->table_value.str));
3104
3127
 
3105
3128
  find_files_result res= find_files(thd, table_names, db_name->str, path,
3106
 
                                    lookup_field_vals->table_value.str, 0);
 
3129
                                    lookup_field_vals->table_value.str, 0,
 
3130
                                    tmp_mem_root);
3107
3131
  if (res != FIND_FILES_OK)
3108
3132
  {
3109
3133
    /*
3769
3793
  bool can_deadlock;
3770
3794
  DBUG_ENTER("get_all_tables");
3771
3795
 
 
3796
  MEM_ROOT tmp_mem_root;
 
3797
  init_sql_alloc(&tmp_mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
 
3798
 
3772
3799
  /*
3773
3800
    In cases when SELECT from I_S table being filled by this call is
3774
3801
    part of statement which also uses other tables or is being executed
3860
3887
    goto err;
3861
3888
  }
3862
3889
 
3863
 
  if (make_db_list(thd, &db_names, &lookup_field_vals, &with_i_schema))
 
3890
  if (make_db_list(thd, &db_names, &lookup_field_vals, &with_i_schema, &tmp_mem_root))
3864
3891
    goto err;
3865
3892
  it.rewind(); /* To get access to new elements in basis list */
3866
3893
  while ((db_name= it++))
3878
3905
      List<LEX_STRING> table_names;
3879
3906
      int res= make_table_name_list(thd, &table_names, lex,
3880
3907
                                    &lookup_field_vals,
3881
 
                                    with_i_schema, db_name);
 
3908
                                    with_i_schema, db_name, &tmp_mem_root);
3882
3909
      if (res == 2)   /* Not fatal error, continue */
3883
3910
        continue;
3884
3911
      if (res)
3965
3992
      with_i_schema= 0;
3966
3993
    }
3967
3994
  }
3968
 
 
3969
3995
  error= 0;
3970
3996
err:
 
3997
 
 
3998
  free_root(&tmp_mem_root, MYF(0));
3971
3999
  thd->restore_backup_open_tables_state(&open_tables_state_backup);
3972
4000
 
3973
4001
  DBUG_RETURN(error);
3993
4021
    Returning error status in this case leads to client hangup.
3994
4022
  */
3995
4023
 
 
4024
  /*
 
4025
   * A temporary class is created to free tmp_mem_root when we return from
 
4026
   * this function, since we have 'return' from this function from many
 
4027
   * places. This is just to avoid goto.
 
4028
   */
 
4029
  class free_tmp_mem_root
 
4030
  {
 
4031
  public:
 
4032
    free_tmp_mem_root()
 
4033
    {
 
4034
      init_sql_alloc(&tmp_mem_root, TABLE_ALLOC_BLOCK_SIZE, 0);
 
4035
    }
 
4036
    ~free_tmp_mem_root()
 
4037
    {
 
4038
      free_root(&tmp_mem_root, MYF(0));
 
4039
    }
 
4040
    MEM_ROOT tmp_mem_root;
 
4041
  };
 
4042
 
 
4043
  free_tmp_mem_root dummy_member;
 
4044
 
3996
4045
  LOOKUP_FIELD_VALUES lookup_field_vals;
3997
4046
  List<LEX_STRING> db_names;
3998
4047
  LEX_STRING *db_name;
4006
4055
 
4007
4056
  if (get_lookup_field_values(thd, cond, tables, &lookup_field_vals))
4008
4057
    DBUG_RETURN(0);
 
4058
 
4009
4059
  DBUG_PRINT("INDEX VALUES",("db_name='%s', table_name='%s'",
4010
4060
                             lookup_field_vals.db_value.str,
4011
4061
                             lookup_field_vals.table_value.str));
4012
4062
  if (make_db_list(thd, &db_names, &lookup_field_vals,
4013
 
                   &with_i_schema))
 
4063
                   &with_i_schema, &dummy_member.tmp_mem_root))
4014
4064
    DBUG_RETURN(1);
4015
4065
 
4016
4066
  /*
6310
6360
    Lock LOCK_plugin_delete to avoid deletion of any plugins while creating
6311
6361
    SHOW_VAR array and hold it until all variables are stored in the table.
6312
6362
  */
6313
 
  mysql_mutex_lock(&LOCK_plugin_delete);
 
6363
  if (thd->fill_variables_recursion_level++ == 0)
 
6364
  {
 
6365
    mysql_mutex_lock(&LOCK_plugin_delete);
 
6366
  }
 
6367
 
6314
6368
  // Lock LOCK_system_variables_hash to prepare SHOW_VARs array.
6315
6369
  mysql_rwlock_rdlock(&LOCK_system_variables_hash);
6316
6370
  DEBUG_SYNC(thd, "acquired_LOCK_system_variables_hash");
6320
6374
  res= show_status_array(thd, wild, sys_var_array, option_type, NULL, "",
6321
6375
                         tables->table, upper_case_names, cond);
6322
6376
 
6323
 
  mysql_mutex_unlock(&LOCK_plugin_delete);
 
6377
  if (thd->fill_variables_recursion_level-- == 1)
 
6378
  {
 
6379
    mysql_mutex_unlock(&LOCK_plugin_delete);
 
6380
  }
 
6381
 
6324
6382
  DBUG_RETURN(res);
6325
6383
}
6326
6384