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

« back to all changes in this revision

Viewing changes to sql/mysqld.cc

  • 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:
640
640
 
641
641
pthread_key(MEM_ROOT**,THR_MALLOC);
642
642
pthread_key(THD*, THR_THD);
 
643
mysql_mutex_t LOCK_thread_created;
643
644
mysql_mutex_t LOCK_thread_count;
644
645
mysql_mutex_t
645
646
  LOCK_status, LOCK_error_log, LOCK_uuid_generator,
993
994
static int test_if_case_insensitive(const char *dir_name);
994
995
 
995
996
#ifndef EMBEDDED_LIBRARY
 
997
static bool pid_file_created= false;
996
998
static void usage(void);
997
999
static void start_signal_handler(void);
998
1000
static void close_server_sock();
1001
1003
static void create_pid_file();
1002
1004
static void mysqld_exit(int exit_code) __attribute__((noreturn));
1003
1005
#endif
 
1006
static void delete_pid_file(myf flags);
1004
1007
static void end_ssl();
1005
1008
 
1006
1009
 
1476
1479
  item_user_lock_free();
1477
1480
  lex_free();                           /* Free some memory */
1478
1481
  item_create_cleanup();
1479
 
  free_charsets();
1480
1482
  if (!opt_noacl)
1481
1483
  {
1482
1484
#ifdef HAVE_DLOPEN
1516
1518
  debug_sync_end();
1517
1519
#endif /* defined(ENABLED_DEBUG_SYNC) */
1518
1520
 
1519
 
#if !defined(EMBEDDED_LIBRARY)
1520
 
  if (!opt_bootstrap)
1521
 
    mysql_file_delete(key_file_pid, pidfile_name, MYF(0)); // This may not always exist
1522
 
#endif
 
1521
  delete_pid_file(MYF(0));
 
1522
 
1523
1523
  if (print_message && my_default_lc_messages && server_start_time)
1524
1524
    sql_print_information(ER_DEFAULT(ER_SHUTDOWN_COMPLETE),my_progname);
1525
1525
  cleanup_errmsgs();
1532
1532
  logger.cleanup_end();
1533
1533
  my_atomic_rwlock_destroy(&global_query_id_lock);
1534
1534
  my_atomic_rwlock_destroy(&thread_running_lock);
 
1535
  free_charsets();
1535
1536
  mysql_mutex_lock(&LOCK_thread_count);
1536
1537
  DBUG_PRINT("quit", ("got thread count lock"));
1537
1538
  ready_to_exit=1;
1574
1575
{
1575
1576
  mysql_rwlock_destroy(&LOCK_grant);
1576
1577
  mysql_mutex_destroy(&LOCK_thread_count);
 
1578
  mysql_mutex_destroy(&LOCK_thread_created);
1577
1579
  mysql_mutex_destroy(&LOCK_status);
1578
1580
  mysql_mutex_destroy(&LOCK_delayed_insert);
1579
1581
  mysql_mutex_destroy(&LOCK_delayed_status);
2259
2261
        this thread for handling of new THD object/connection.
2260
2262
      */
2261
2263
      thd->mysys_var->abort= 0;
2262
 
      thd->thr_create_utime= my_micro_time();
 
2264
      thd->thr_create_utime= thd->start_utime= my_micro_time();
2263
2265
      threads.append(thd);
2264
2266
      return(1);
2265
2267
    }
2881
2883
 
2882
2884
 
2883
2885
#ifndef EMBEDDED_LIBRARY
2884
 
static
2885
 
int
2886
 
check_enough_stack_size()
 
2886
/**
 
2887
  This function is used to check for stack overrun for pathological
 
2888
  cases of  regular expressions and 'like' expressions.
 
2889
  The call to current_thd is  quite expensive, so we try to avoid it
 
2890
  for the normal cases.
 
2891
  The size of  each stack frame for the wildcmp() routines is ~128 bytes,
 
2892
  so checking  *every* recursive call is not necessary.
 
2893
 */
 
2894
extern "C" int
 
2895
check_enough_stack_size(int recurse_level)
2887
2896
{
2888
2897
  uchar stack_top;
 
2898
  if (recurse_level % 16 != 0)
 
2899
    return 0;
2889
2900
 
2890
 
  return check_stack_overrun(current_thd, STACK_MIN_SIZE,
2891
 
                             &stack_top);
 
2901
  THD *my_thd= current_thd;
 
2902
  if (my_thd != NULL)
 
2903
    return check_stack_overrun(my_thd, STACK_MIN_SIZE * 2, &stack_top);
 
2904
  return 0;
2892
2905
}
2893
2906
#endif
2894
2907
 
3367
3380
  item_init();
3368
3381
#ifndef EMBEDDED_LIBRARY
3369
3382
  my_regex_init(&my_charset_latin1, check_enough_stack_size);
 
3383
  my_string_stack_guard= check_enough_stack_size;
3370
3384
#else
3371
3385
  my_regex_init(&my_charset_latin1, NULL);
3372
3386
#endif
3530
3544
 
3531
3545
static int init_thread_environment()
3532
3546
{
 
3547
  mysql_mutex_init(key_LOCK_thread_created, &LOCK_thread_created, MY_MUTEX_INIT_FAST);
3533
3548
  mysql_mutex_init(key_LOCK_thread_count, &LOCK_thread_count, MY_MUTEX_INIT_FAST);
3534
3549
  mysql_mutex_init(key_LOCK_status, &LOCK_status, MY_MUTEX_INIT_FAST);
3535
3550
  mysql_mutex_init(key_LOCK_delayed_insert,
4507
4522
    After this we can't quit by a simple unireg_abort
4508
4523
  */
4509
4524
  error_handler_hook= my_message_sql;
 
4525
  sql_print_warning_hook = sql_print_warning;
4510
4526
  start_signal_handler();                               // Creates pidfile
4511
4527
 
4512
4528
  if (mysql_rm_tmp_tables() || acl_init(opt_noacl) ||
4517
4533
 
4518
4534
    (void) pthread_kill(signal_thread, MYSQL_KILL_SIGNAL);
4519
4535
 
4520
 
 
4521
 
    if (!opt_bootstrap)
4522
 
      mysql_file_delete(key_file_pid, pidfile_name, MYF(MY_WME)); // Not needed anymore
 
4536
    delete_pid_file(MYF(MY_WME));
4523
4537
 
4524
4538
    if (unix_sock != INVALID_SOCKET)
4525
4539
      unlink(mysqld_unix_port);
4939
4953
*/
4940
4954
void inc_thread_created(void)
4941
4955
{
 
4956
  mysql_mutex_lock(&LOCK_thread_created);
4942
4957
  thread_created++;
 
4958
  mysql_mutex_unlock(&LOCK_thread_created);
4943
4959
}
4944
4960
 
4945
4961
#ifndef EMBEDDED_LIBRARY
7676
7692
  if ((file= mysql_file_create(key_file_pid, pidfile_name, 0664,
7677
7693
                               O_WRONLY | O_TRUNC, MYF(MY_WME))) >= 0)
7678
7694
  {
7679
 
    char buff[21], *end;
 
7695
    char buff[MAX_BIGINT_WIDTH + 1], *end;
7680
7696
    end= int10_to_str((long) getpid(), buff, 10);
7681
7697
    *end++= '\n';
7682
7698
    if (!mysql_file_write(file, (uchar*) buff, (uint) (end-buff),
7683
7699
                          MYF(MY_WME | MY_NABP)))
7684
7700
    {
7685
7701
      mysql_file_close(file, MYF(0));
 
7702
      pid_file_created= true;
7686
7703
      return;
7687
7704
    }
7688
7705
    mysql_file_close(file, MYF(0));
7692
7709
}
7693
7710
#endif /* EMBEDDED_LIBRARY */
7694
7711
 
 
7712
 
 
7713
/**
 
7714
  Remove the process' pid file.
 
7715
  
 
7716
  @param  flags  file operation flags
 
7717
*/
 
7718
 
 
7719
static void delete_pid_file(myf flags)
 
7720
{
 
7721
#ifndef EMBEDDED_LIBRARY
 
7722
  File file;
 
7723
  if (opt_bootstrap ||
 
7724
      !pid_file_created ||
 
7725
      !(file= mysql_file_open(key_file_pid, pidfile_name,
 
7726
                              O_RDONLY, flags)))
 
7727
    return;
 
7728
 
 
7729
  /* Make sure that the pid file was created by the same process. */    
 
7730
  uchar buff[MAX_BIGINT_WIDTH + 1];
 
7731
  size_t error= mysql_file_read(file, buff, sizeof(buff), flags);
 
7732
  mysql_file_close(file, flags);
 
7733
  buff[sizeof(buff) - 1]= '\0'; 
 
7734
  if (error != MY_FILE_ERROR &&
 
7735
      atol((char *) buff) == (long) getpid())
 
7736
  {
 
7737
    mysql_file_delete(key_file_pid, pidfile_name, flags);
 
7738
    pid_file_created= false;
 
7739
  }
 
7740
#endif /* EMBEDDED_LIBRARY */
 
7741
  return;
 
7742
}
 
7743
 
 
7744
 
7695
7745
/** Clear most status variables. */
7696
7746
void refresh_status(THD *thd)
7697
7747
{
7770
7820
  key_LOCK_error_messages, key_LOG_INFO_lock, key_LOCK_thread_count,
7771
7821
  key_PARTITION_LOCK_auto_inc;
7772
7822
PSI_mutex_key key_RELAYLOG_LOCK_index;
 
7823
PSI_mutex_key key_LOCK_thread_created;
7773
7824
 
7774
7825
static PSI_mutex_info all_server_mutexes[]=
7775
7826
{
7822
7873
  { &key_LOCK_error_messages, "LOCK_error_messages", PSI_FLAG_GLOBAL},
7823
7874
  { &key_LOG_INFO_lock, "LOG_INFO::lock", 0},
7824
7875
  { &key_LOCK_thread_count, "LOCK_thread_count", PSI_FLAG_GLOBAL},
7825
 
  { &key_PARTITION_LOCK_auto_inc, "HA_DATA_PARTITION::LOCK_auto_inc", 0}
 
7876
  { &key_PARTITION_LOCK_auto_inc, "HA_DATA_PARTITION::LOCK_auto_inc", 0},
 
7877
  { &key_LOCK_thread_created, "LOCK_thread_created", PSI_FLAG_GLOBAL }
7826
7878
};
7827
7879
 
7828
7880
PSI_rwlock_key key_rwlock_LOCK_grant, key_rwlock_LOCK_logger,