diff --git a/test/prepare.c b/test/prepare.c index 7cd5b7b..16df58f 100644 --- a/test/prepare.c +++ b/test/prepare.c @@ -1218,6 +1218,37 @@ ODBC_TEST(t_odbc141) return OK; } +ODBC_TEST(t_expect_need_data) +{ + //craches mdb (20 bytes) + const char charvalue[] = "01234567890123456789"; + // doesnt't crash mdb (19 bytes) + //const char charvalue[] = "0123456789012345678"; + + SQLINTEGER len = -2; + + OK_SIMPLE_STMT(Stmt, "DROP TABLE IF EXISTS crash_after_invalid_command"); + + OK_SIMPLE_STMT(Stmt, "CREATE TABLE crash_after_invalid_command(charfield char(15), textfield text)"); + + CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE)); + + rc = SQLBindParameter(Stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 15, 0, charvalue, 20, NULL); + EXPECT_STMT(Stmt, SQLExecDirect(Stmt, "any invalid command with parameter ?", SQL_NTS), SQL_ERROR); + CHECK_STMT_RC(Stmt, SQLCancel(Stmt)); + + CHECK_STMT_RC(Stmt, SQLBindParameter(Stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 15, 0, charvalue, 20, NULL)); + CHECK_STMT_RC(Stmt, SQLBindParameter(Stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 15, 0, 0x00000001, 0, &len)); + + /* The following command-line causes mariadb-server 10.3.16 to crash + if [charvalue] is 20 or more bytes long, producing different kinds of stack-traces */ + EXPECT_STMT(Stmt, SQLExecDirect(Stmt, "INSERT INTO crash_after_invalid_command(charfield, textfield) VALUES (?, ?)", SQL_NTS), + SQL_NEED_DATA); + + CHECK_STMT_RC(Stmt, SQLCancel(Stmt)); + CHECK_STMT_RC(Stmt, SQLFreeStmt(Stmt, SQL_CLOSE)); + return OK; +} MA_ODBC_TESTS my_tests[]= { @@ -1238,7 +1269,8 @@ MA_ODBC_TESTS my_tests[]= {t_bug67340, "t_bug67340"}, {t_bug67702, "t_bug67702"}, {t_odbc57, "odbc-57-query_in_parenthesis" }, - {t_odbc141, "odbc-141-load_data_infile" }, + {t_expect_need_data, "t_expect_need_data" }, + {t_odbc141, "odbc-141-load_data_infile" }, {NULL, NULL} };