~ubuntu-branches/ubuntu/hardy/mysql-dfsg-5.0/hardy-proposed

« back to all changes in this revision

Viewing changes to client/mysqlcheck.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-23 11:21:11 UTC
  • mfrom: (1.1.16) (38.1.4 hardy-security)
  • Revision ID: package-import@ubuntu.com-20120223112111-rn9ruzg86juli2ec
Tags: 5.0.95-0ubuntu1
* SECURITY UPDATE: Update to 5.0.95 to fix multiple security issues
  (LP: #937869)
  - http://www.oracle.com/technetwork/topics/security/cpujan2012-366304.html
  - CVE-2012-0075
  - CVE-2012-0087
  - CVE-2012-0101
  - CVE-2012-0102
  - CVE-2012-0114
  - CVE-2012-0484
  - CVE-2012-0490
* Dropped patches unnecessary with 5.0.95:
  - debian/patches/91_SECURITY_CVE-2007-5925.dpatch
  - debian/patches/95_SECURITY_CVE-2008-3963.dpatch
  - debian/patches/96_SECURITY_CVE-2008-4098.dpatch
  - debian/patches/97_CVE-2008-4456.dpatch
  - debian/patches/97_CVE-2009-2446.dpatch
  - debian/patches/97_CVE-2009-4019.dpatch
  - debian/patches/97_CVE-2009-4030.dpatch
  - debian/patches/98_CVE-2009-4484.dpatch
  - debian/patches/99_ssl_test_certs.dpatch
  - debian/patches/100_CVE-2010-1850.dpatch
  - debian/patches/101_CVE-2010-1849.dpatch
  - debian/patches/102_CVE-2010-1848.dpatch
  - debian/patches/103_CVE-2010-1626.dpatch
  - debian/patches/98_CVE-2010-3677.dpatch
  - debian/patches/98_CVE-2010-3680.dpatch
  - debian/patches/98_CVE-2010-3681.dpatch
  - debian/patches/98_CVE-2010-3682.dpatch
  - debian/patches/98_CVE-2010-3833.dpatch
  - debian/patches/98_CVE-2010-3834.dpatch
  - debian/patches/98_CVE-2010-3835.dpatch
  - debian/patches/98_CVE-2010-3836.dpatch
  - debian/patches/98_CVE-2010-3837.dpatch
  - debian/patches/98_CVE-2010-3838.dpatch
  - debian/patches/98_CVE-2010-3840.dpatch
  - debian/patches/45_warn-CLI-passwords.dpatch
  - debian/patches/50_fix_mysqldump.dpatch
  - debian/patches/51_incorrect-order.dpatch
  - debian/patches/52_ndb-gcc-4.2.dpatch
  - debian/patches/53_integer-gcc-4.2.dpatch
  - debian/patches/54_ssl-client-support.dpatch
  - debian/patches/55_testsuite-2008.dpatch
  - debian/patches/58-disable-ndb-backup-print.dpatch
  - debian/patches/59-fix-mysql-replication-logs.dpatch
  - debian/patches/86_PATH_MAX.dpatch
  - debian/patches/90_upstreamdebiandir.dpatch
  - debian/patches/92_fix_order_by32202.dpatch
  - debian/patches/93_fix_user_setup_on_localhost.dpatch
  - debian/patches/94_fix_mysqldump_with_old_versions.dpatch
  - debian/patches/56-mysqlhotcopy-invalid-dbtable.dpatch
  - debian/patches/57-fix-mysqlslowdump-config.dpatch
* debian/mysql-client-5.0.docs, debian/mysql-server-5.0.docs: removed
  EXCEPTIONS-CLIENT file
* debian/libmysqlclient15-dev.docs, debian/libmysqlclient15off.docs:
  removed, no longer necessary.
* debian/patches/25_mysys__default.c.dpatch: updated for 5.0.95.
* debian/mysql-server-5.0.files: change ndb_mgmd and ndbd manpage
  locations. Removed mysqlmanagerc.1 and mysqlmanager-pwgen.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000 MySQL AB
 
1
/*
 
2
   Copyright (c) 2001, 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
 
 
16
 
/* By Jani Tolonen, 2001-04-20, MySQL Development Team */
 
15
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
 
16
*/
17
17
 
18
18
#define CHECK_VERSION "2.4.4"
19
19
 
22
22
#include <mysql_version.h>
23
23
#include <mysqld_error.h>
24
24
#include <sslopt-vars.h>
 
25
#include <welcome_copyright_notice.h> /* ORACLE_WELCOME_COPYRIGHT_NOTICE */
25
26
 
26
27
/* Exit codes */
27
28
 
123
124
  {"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG,
124
125
   NO_ARG, 0, 0, 0, 0, 0, 0},
125
126
#endif
126
 
  {"port", 'P', "Port number to use for connection.", (gptr*) &opt_mysql_port,
 
127
  {"port", 'P', "Port number to use for connection or 0 for default to, in "
 
128
   "order of preference, my.cnf, $MYSQL_TCP_PORT, "
 
129
#if MYSQL_PORT_DEFAULT == 0
 
130
   "/etc/services, "
 
131
#endif
 
132
   "built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
 
133
   (gptr*) &opt_mysql_port,
127
134
   (gptr*) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
128
135
   0},
129
136
  {"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
180
187
static void DBerror(MYSQL *mysql, const char *when);
181
188
static void safe_exit(int error);
182
189
static void print_result();
 
190
static uint fixed_name_length(const char *name);
183
191
static char *fix_table_name(char *dest, char *src);
184
192
int what_to_do = 0;
185
193
 
196
204
static void usage(void)
197
205
{
198
206
  print_version();
199
 
  puts("By Jani Tolonen, 2001-04-20, MySQL Development Team\n");
200
 
  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n");
201
 
  puts("and you are welcome to modify and redistribute it under the GPL license.\n");
 
207
  puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000, 2011"));
202
208
  puts("This program can be used to CHECK (-c,-m,-C), REPAIR (-r), ANALYZE (-a)");
203
209
  puts("or OPTIMIZE (-o) tables. Some of the options (like -e or -q) can be");
204
210
  puts("used at the same time. Not all options are supported by all storage engines.");
321
327
 
322
328
  if (!what_to_do)
323
329
  {
324
 
    int pnlen = strlen(my_progname);
 
330
    size_t pnlen= strlen(my_progname);
325
331
 
326
332
    if (pnlen < 6) /* name too short */
327
333
      what_to_do = DO_CHECK;
403
409
  {
404
410
    /* 
405
411
      We need table list in form `a`, `b`, `c`
406
 
      that's why we need 4 more chars added to to each table name
 
412
      that's why we need 2 more chars added to to each table name
407
413
      space is for more readable output in logs and in case of error
408
414
    */    
409
415
    char *table_names_comma_sep, *end;
410
 
    int i, tot_length = 0;
 
416
    size_t tot_length= 0;
 
417
    int             i= 0;
411
418
 
412
419
    for (i = 0; i < tables; i++)
413
 
      tot_length += strlen(*(table_names + i)) + 4;
 
420
      tot_length+= fixed_name_length(*(table_names + i)) + 2;
414
421
 
415
422
    if (!(table_names_comma_sep = (char *)
416
423
          my_malloc((sizeof(char) * tot_length) + 4, MYF(MY_WME))))
423
430
      *end++= ',';
424
431
    }
425
432
    *--end = 0;
426
 
    handle_request_for_tables(table_names_comma_sep + 1, tot_length - 1);
 
433
    handle_request_for_tables(table_names_comma_sep + 1, (uint) (tot_length - 1));
427
434
    my_free(table_names_comma_sep, MYF(0));
428
435
  }
429
436
  else
430
437
    for (; tables > 0; tables--, table_names++)
431
 
      handle_request_for_tables(*table_names, strlen(*table_names));
 
438
      handle_request_for_tables(*table_names, fixed_name_length(*table_names));
432
439
  return 0;
433
440
} /* process_selected_tables */
434
441
 
435
442
 
 
443
static uint fixed_name_length(const char *name)
 
444
{
 
445
  const char *p;
 
446
  uint extra_length= 2;  /* count the first/last backticks */
 
447
  
 
448
  for (p= name; *p; p++)
 
449
  {
 
450
    if (*p == '`')
 
451
      extra_length++;
 
452
    else if (*p == '.')
 
453
      extra_length+= 2;
 
454
  }
 
455
  return (uint) ((p - name) + extra_length);
 
456
}
 
457
 
 
458
 
436
459
static char *fix_table_name(char *dest, char *src)
437
460
{
438
 
  char *db_sep;
439
 
 
440
461
  *dest++= '`';
441
 
  if ((db_sep= strchr(src, '.')))
 
462
  for (; *src; src++)
442
463
  {
443
 
    dest= strmake(dest, src, (uint) (db_sep - src));
444
 
    dest= strmov(dest, "`.`");
445
 
    src= db_sep + 1;
 
464
    switch (*src) {
 
465
    case '.':            /* add backticks around '.' */
 
466
      *dest++= '`';
 
467
      *dest++= '.';
 
468
      *dest++= '`';
 
469
      break;
 
470
    case '`':            /* escape backtick character */
 
471
      *dest++= '`';
 
472
      /* fall through */
 
473
    default:
 
474
      *dest++= *src;
 
475
    }
446
476
  }
447
 
  dest= strxmov(dest, src, "`", NullS);
 
477
  *dest++= '`';
448
478
  return dest;
449
479
}
450
480
 
458
488
  LINT_INIT(res);
459
489
  if (use_db(database))
460
490
    return 1;
461
 
  if (mysql_query(sock, "SHOW /*!50002 FULL*/ TABLES") ||
462
 
        !((res= mysql_store_result(sock))))
 
491
  if ((mysql_query(sock, "SHOW /*!50002 FULL*/ TABLES") &&
 
492
       mysql_query(sock, "SHOW TABLES")) ||
 
493
      !(res= mysql_store_result(sock)))
 
494
  {
 
495
    my_printf_error(0, "Error: Couldn't get table list for database %s: %s",
 
496
                    MYF(0), database, mysql_error(sock));
463
497
    return 1;
 
498
  }
464
499
 
465
500
  num_columns= mysql_num_fields(res);
466
501
 
468
503
  {
469
504
    /*
470
505
      We need table list in form `a`, `b`, `c`
471
 
      that's why we need 4 more chars added to to each table name
 
506
      that's why we need 2 more chars added to to each table name
472
507
      space is for more readable output in logs and in case of error
473
508
     */
474
509
 
476
511
    uint tot_length = 0;
477
512
 
478
513
    while ((row = mysql_fetch_row(res)))
479
 
      tot_length += strlen(row[0]) + 4;
 
514
      tot_length+= fixed_name_length(row[0]) + 2;
480
515
    mysql_data_seek(res, 0);
481
516
 
482
517
    if (!(tables=(char *) my_malloc(sizeof(char)*tot_length+4, MYF(MY_WME))))
500
535
  else
501
536
  {
502
537
    while ((row = mysql_fetch_row(res)))
503
 
    {
504
 
      if ((num_columns == 2) && (strcmp(row[1], "VIEW") == 0))
505
 
        continue;
506
 
 
507
 
      handle_request_for_tables(row[0], strlen(row[0]));
508
 
    }
 
538
      /* Skip tables with an engine of NULL (probably a view). */
 
539
      if (row[1])
 
540
      {
 
541
        if ((num_columns == 2) && (strcmp(row[1], "VIEW") == 0))
 
542
          continue;
 
543
        
 
544
        handle_request_for_tables(row[0], fixed_name_length(row[0]));
 
545
      }
509
546
  }
510
547
  mysql_free_result(res);
511
548
  return 0;
738
775
    for (i = 0; i < tables4repair.elements ; i++)
739
776
    {
740
777
      char *name= (char*) dynamic_array_ptr(&tables4repair, i);
741
 
      handle_request_for_tables(name, strlen(name));
 
778
      handle_request_for_tables(name, fixed_name_length(name));
742
779
    }
743
780
  }
744
781
 end: