From 2412446cd489675ffab7bcd3cc54a610fb0e74e1 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 7 Jun 2007 19:35:29 +0400 Subject: [PATCH] Add test case for BUG#27592: stack overrun when storing datetime value using prepared statements. tests/mysql_client_test.c: Test case. --- tests/mysql_client_test.c | 54 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index e56dd693287..d3aa31a9400 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -15623,6 +15623,59 @@ static void test_bug27876() } +/* + Bug#27592 (stack overrun when storing datetime value using prepared statements) +*/ + +static void test_bug27592() +{ + const int NUM_ITERATIONS= 40; + int i; + int rc; + MYSQL_STMT *stmt= NULL; + MYSQL_BIND bind[1]; + MYSQL_TIME time_val; + + DBUG_ENTER("test_bug27592"); + myheader("test_bug27592"); + + mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + mysql_query(mysql, "CREATE TABLE t1(c2 DATETIME)"); + + stmt= mysql_simple_prepare(mysql, "INSERT INTO t1 VALUES (?)"); + DIE_UNLESS(stmt); + + memset(bind, 0, sizeof(bind)); + + bind[0].buffer_type= MYSQL_TYPE_DATETIME; + bind[0].buffer= (char *) &time_val; + bind[0].length= NULL; + + for (i= 0; i < NUM_ITERATIONS; i++) + { + time_val.year=1000+lrand48()%1000; + time_val.month=1+lrand48()%12; + time_val.day=1+lrand48()%31; + time_val.hour=lrand48()%23; + time_val.minute=lrand48()%59; + time_val.second=lrand48()%59; + + time_val.second_part=0; + time_val.neg=0; + + rc= mysql_stmt_bind_param(stmt, bind); + check_execute(stmt, rc); + + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + } + + mysql_stmt_close(stmt); + + DBUG_VOID_RETURN; +} + + /* Read and parse arguments and MySQL options from my.cnf */ @@ -15904,6 +15957,7 @@ static struct my_tests_st my_tests[]= { { "test_bug21635", test_bug21635 }, { "test_bug24179", test_bug24179 }, { "test_bug27876", test_bug27876 }, + { "test_bug27592", test_bug27592 }, { 0, 0 } };