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

« back to all changes in this revision

Viewing changes to tests/mysql_client_test.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 08:30:45 UTC
  • mfrom: (1.4.1)
  • Revision ID: package-import@ubuntu.com-20120222083045-2rd53r4bnyx7qus4
Tags: 5.1.61-0ubuntu0.11.04.1
* SECURITY UPDATE: Update to 5.1.61 to fix multiple security issues
  (LP: #937869)
  - http://www.oracle.com/technetwork/topics/security/cpujan2012-366304.html
  - CVE-2011-2262
  - CVE-2012-0075
  - CVE-2012-0112
  - CVE-2012-0113
  - CVE-2012-0114
  - CVE-2012-0115
  - CVE-2012-0116
  - CVE-2012-0117
  - CVE-2012-0118
  - CVE-2012-0119
  - CVE-2012-0120
  - CVE-2012-0484
  - CVE-2012-0485
  - CVE-2012-0486
  - CVE-2012-0487
  - CVE-2012-0488
  - CVE-2012-0489
  - CVE-2012-0490
  - CVE-2012-0491
  - CVE-2012-0492
  - CVE-2012-0493
  - CVE-2012-0494
  - CVE-2012-0495
  - CVE-2012-0496

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2003-2004 MySQL AB
 
1
/* Copyright (c) 2002, 2011, 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
17125
17125
 
17126
17126
  /* Set MAX_JOIN_SIZE to the default value (-1). */
17127
17127
 
17128
 
  DIE_IF(mysql_query(&con, "SET @@global.max_join_size = -1"));
 
17128
  DIE_IF(mysql_query(&con, "SET @@global.max_join_size = 18446744073709551615"));
17129
17129
  DIE_IF(mysql_query(&con, "SET @@session.max_join_size = default"));
17130
17130
 
17131
17131
  /* Issue COM_CHANGE_USER. */
17156
17156
 
17157
17157
  DIE_IF(mysql_query(&con, query_buffer));
17158
17158
 
17159
 
  DIE_IF(mysql_query(&con, "SET @@global.max_join_size = -1"));
 
17159
  DIE_IF(mysql_query(&con, "SET @@global.max_join_size = 18446744073709551615"));
17160
17160
  DIE_IF(mysql_query(&con, "SET @@session.max_join_size = default"));
17161
17161
 
17162
17162
  /* Issue COM_CHANGE_USER. */
18399
18399
 
18400
18400
 
18401
18401
/*
 
18402
  Bug#58036 client utf32, utf16, ucs2 should be disallowed, they crash server
 
18403
*/
 
18404
static void test_bug58036()
 
18405
{
 
18406
  MYSQL *conn;
 
18407
  DBUG_ENTER("test_bug47485");
 
18408
  myheader("test_bug58036");
 
18409
 
 
18410
  /* Part1: try to connect with ucs2 client character set */
 
18411
  conn= mysql_client_init(NULL);
 
18412
  mysql_options(conn, MYSQL_SET_CHARSET_NAME, "ucs2");
 
18413
  if (mysql_real_connect(conn, opt_host, opt_user,
 
18414
                         opt_password,  opt_db ? opt_db : "test",
 
18415
                         opt_port, opt_unix_socket, 0))
 
18416
  {
 
18417
    if (!opt_silent)
 
18418
      printf("mysql_real_connect() succeeded (failure expected)\n");
 
18419
    mysql_close(conn);
 
18420
    DIE("");
 
18421
  }
 
18422
 
 
18423
  if (!opt_silent)
 
18424
    printf("Got mysql_real_connect() error (expected): %s (%d)\n",
 
18425
           mysql_error(conn), mysql_errno(conn));  
 
18426
  DIE_UNLESS(mysql_errno(conn) == ER_WRONG_VALUE_FOR_VAR);
 
18427
  mysql_close(conn);
 
18428
 
 
18429
 
 
18430
  /*
 
18431
    Part2:
 
18432
    - connect with latin1
 
18433
    - then change client character set to ucs2
 
18434
    - then try mysql_change_user()
 
18435
  */
 
18436
  conn= mysql_client_init(NULL);
 
18437
  mysql_options(conn, MYSQL_SET_CHARSET_NAME, "latin1");
 
18438
  if (!mysql_real_connect(conn, opt_host, opt_user,
 
18439
                         opt_password, opt_db ? opt_db : "test",
 
18440
                         opt_port, opt_unix_socket, 0))
 
18441
  {
 
18442
    if (!opt_silent)
 
18443
      printf("mysql_real_connect() failed: %s (%d)\n",
 
18444
             mysql_error(conn), mysql_errno(conn));
 
18445
    mysql_close(conn);
 
18446
    DIE("");
 
18447
  }
 
18448
 
 
18449
  mysql_options(conn, MYSQL_SET_CHARSET_NAME, "ucs2");
 
18450
  if (!mysql_change_user(conn, opt_user, opt_password, NULL))
 
18451
  {
 
18452
    if (!opt_silent)
 
18453
      printf("mysql_change_user() succedded, error expected!");
 
18454
    mysql_close(conn);
 
18455
    DIE("");
 
18456
  }
 
18457
 
 
18458
  if (!opt_silent)
 
18459
    printf("Got mysql_change_user() error (expected): %s (%d)\n",
 
18460
           mysql_error(conn), mysql_errno(conn));
 
18461
  mysql_close(conn);
 
18462
 
 
18463
  DBUG_VOID_RETURN;
 
18464
}
 
18465
 
 
18466
 
 
18467
/*
 
18468
  Bug #56976:   Severe Denial Of Service in prepared statements
 
18469
*/
 
18470
static void test_bug56976()
 
18471
{
 
18472
  MYSQL_STMT   *stmt;
 
18473
  MYSQL_BIND    bind[1];
 
18474
  int           rc;
 
18475
  const char*   query = "SELECT LENGTH(?)";
 
18476
  char *long_buffer;
 
18477
  unsigned long i, packet_len = 256 * 1024L;
 
18478
  unsigned long dos_len    = 2 * 1024 * 1024L;
 
18479
 
 
18480
  DBUG_ENTER("test_bug56976");
 
18481
  myheader("test_bug56976");
 
18482
 
 
18483
  stmt= mysql_stmt_init(mysql);
 
18484
  check_stmt(stmt);
 
18485
 
 
18486
  rc= mysql_stmt_prepare(stmt, query, strlen(query));
 
18487
  check_execute(stmt, rc);
 
18488
 
 
18489
  memset(bind, 0, sizeof(bind));
 
18490
  bind[0].buffer_type = MYSQL_TYPE_TINY_BLOB;
 
18491
 
 
18492
  rc= mysql_stmt_bind_param(stmt, bind);
 
18493
  check_execute(stmt, rc);
 
18494
 
 
18495
  long_buffer= (char*) my_malloc(packet_len, MYF(0));
 
18496
  DIE_UNLESS(long_buffer);
 
18497
 
 
18498
  memset(long_buffer, 'a', packet_len);
 
18499
 
 
18500
  for (i= 0; i < dos_len / packet_len; i++)
 
18501
  {
 
18502
    rc= mysql_stmt_send_long_data(stmt, 0, long_buffer, packet_len);
 
18503
    check_execute(stmt, rc);
 
18504
  }
 
18505
 
 
18506
  my_free(long_buffer, MYF(0));
 
18507
  rc= mysql_stmt_execute(stmt);
 
18508
 
 
18509
  DIE_UNLESS(rc && mysql_stmt_errno(stmt) == ER_UNKNOWN_ERROR);
 
18510
 
 
18511
  mysql_stmt_close(stmt);
 
18512
 
 
18513
  DBUG_VOID_RETURN;
 
18514
}
 
18515
 
 
18516
/*
 
18517
  Bug#13001491: MYSQL_REFRESH CRASHES WHEN STORED ROUTINES ARE RUN CONCURRENTLY.
 
18518
*/
 
18519
static void test_bug13001491()
 
18520
{
 
18521
  int rc;
 
18522
  char query[MAX_TEST_QUERY_LENGTH];
 
18523
  MYSQL *c;
 
18524
 
 
18525
  myheader("test_bug13001491");
 
18526
 
 
18527
  my_snprintf(query, MAX_TEST_QUERY_LENGTH,
 
18528
           "GRANT ALL PRIVILEGES ON *.* TO mysqltest_u1@%s",
 
18529
           opt_host ? opt_host : "'localhost'");
 
18530
           
 
18531
  rc= mysql_query(mysql, query);
 
18532
  myquery(rc);
 
18533
 
 
18534
  my_snprintf(query, MAX_TEST_QUERY_LENGTH,
 
18535
           "GRANT RELOAD ON *.* TO mysqltest_u1@%s",
 
18536
           opt_host ? opt_host : "'localhost'");
 
18537
           
 
18538
  rc= mysql_query(mysql, query);
 
18539
  myquery(rc);
 
18540
 
 
18541
  c= mysql_client_init(NULL);
 
18542
 
 
18543
  DIE_UNLESS(mysql_real_connect(c, opt_host, "mysqltest_u1", NULL,
 
18544
                                current_db, opt_port, opt_unix_socket,
 
18545
                                CLIENT_MULTI_STATEMENTS |
 
18546
                                CLIENT_MULTI_RESULTS));
 
18547
 
 
18548
  rc= mysql_query(c, "DROP PROCEDURE IF EXISTS p1");
 
18549
  myquery(rc);
 
18550
 
 
18551
  rc= mysql_query(c,
 
18552
    "CREATE PROCEDURE p1() "
 
18553
    "BEGIN "
 
18554
    " DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END; "
 
18555
    " SELECT COUNT(*) "
 
18556
    " FROM INFORMATION_SCHEMA.PROCESSLIST "
 
18557
    " GROUP BY user "
 
18558
    " ORDER BY NULL "
 
18559
    " INTO @a; "
 
18560
    "END");
 
18561
  myquery(rc);
 
18562
 
 
18563
  rc= mysql_query(c, "CALL p1()");
 
18564
  myquery(rc);
 
18565
 
 
18566
  mysql_free_result(mysql_store_result(c));
 
18567
 
 
18568
  /* Check that mysql_refresh() succeeds without REFRESH_LOG. */
 
18569
  rc= mysql_refresh(c, REFRESH_GRANT |
 
18570
                       REFRESH_TABLES | REFRESH_HOSTS |
 
18571
                       REFRESH_STATUS | REFRESH_THREADS);
 
18572
  myquery(rc);
 
18573
 
 
18574
  /*
 
18575
    Check that mysql_refresh(REFRESH_LOG) does not crash the server even if it
 
18576
    fails. mysql_refresh(REFRESH_LOG) fails when error log points to unavailable
 
18577
    location.
 
18578
  */
 
18579
  mysql_refresh(c, REFRESH_LOG);
 
18580
 
 
18581
  rc= mysql_query(c, "DROP PROCEDURE p1");
 
18582
  myquery(rc);
 
18583
 
 
18584
  mysql_close(c);
 
18585
  c= NULL;
 
18586
 
 
18587
  my_snprintf(query, MAX_TEST_QUERY_LENGTH,
 
18588
           "DROP USER mysqltest_u1@%s",
 
18589
           opt_host ? opt_host : "'localhost'");
 
18590
           
 
18591
  rc= mysql_query(mysql, query);
 
18592
  myquery(rc);
 
18593
}
 
18594
 
 
18595
 
 
18596
/*
18402
18597
  Read and parse arguments and MySQL options from my.cnf
18403
18598
*/
18404
18599
 
18724
18919
  { "test_bug42373", test_bug42373 },
18725
18920
  { "test_bug54041", test_bug54041 },
18726
18921
  { "test_bug47485", test_bug47485 },
 
18922
  { "test_bug58036", test_bug58036 },
 
18923
  { "test_bug56976", test_bug56976 },
 
18924
  { "test_bug13001491", test_bug13001491 },
18727
18925
  { 0, 0 }
18728
18926
};
18729
18927