Commit abc14800 authored by jimw@rama.(none)'s avatar jimw@rama.(none)

Bug #21288: mysqldump segmentation fault when using --where

  The problem was that the error handling was using a too-small buffer to
  print the error message generated. We fix this by not using a buffer at
  all, but by using fprintf() directly. There were also some problems with
  the error handling in table dumping that was exposed by this fix that were
  also corrected.
parent 5fc215e2
......@@ -783,8 +783,8 @@ static int get_options(int *argc, char ***argv)
static void DBerror(MYSQL *mysql, const char *when)
{
DBUG_ENTER("DBerror");
my_printf_error(0,"Got error: %d: %s %s", MYF(0),
mysql_errno(mysql), mysql_error(mysql), when);
fprintf(stderr, "%s: Got error: %d: %s %s\n", my_progname,
mysql_errno(mysql), mysql_error(mysql), when);
safe_exit(EX_MYSQLERR);
DBUG_VOID_RETURN;
} /* DBerror */
......@@ -811,9 +811,9 @@ static int mysql_query_with_error_report(MYSQL *mysql_con, MYSQL_RES **res,
if (mysql_query(mysql_con, query) ||
(res && !((*res)= mysql_store_result(mysql_con))))
{
my_printf_error(0, "%s: Couldn't execute '%s': %s (%d)",
MYF(0), my_progname, query,
mysql_error(mysql_con), mysql_errno(mysql_con));
fprintf(stderr, "%s: Couldn't execute '%s': %s (%d)\n",
my_progname, query,
mysql_error(mysql_con), mysql_errno(mysql_con));
return 1;
}
return 0;
......@@ -1705,13 +1705,19 @@ static void dumpTable(uint numFields, char *table)
check_io(md_result_file);
}
if (mysql_query_with_error_report(sock, 0, query))
{
DBerror(sock, "when retrieving data from server");
goto err;
}
if (quick)
res=mysql_use_result(sock);
else
res=mysql_store_result(sock);
if (!res)
{
DBerror(sock, "when retrieving data from server");
goto err;
}
if (verbose)
fprintf(stderr, "-- Retrieving rows...\n");
if (mysql_num_fields(res) != numFields)
......
......@@ -1557,4 +1557,31 @@ CREATE TABLE `t2` (
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
drop table t1, t2, t3;
create table t1 (a int);
mysqldump: Couldn't execute 'SELECT /*!40001 SQL_NO_CACHE */ * FROM `t1` WHERE xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx': You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' at line 1 (1064)
mysqldump: Got error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' at line 1 when retrieving data from server
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
DROP TABLE IF EXISTS `t1`;
CREATE TABLE `t1` (
`a` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
drop table t1;
End of 4.1 tests
......@@ -694,4 +694,12 @@ create table t3(a int);
--exec $MYSQL_DUMP --skip-comments --force --no-data test t3 t1 non_existing t2
drop table t1, t2, t3;
#
# Bug #21288: mysqldump segmentation fault when using --where
#
create table t1 (a int);
--error 2
--exec $MYSQL_DUMP --skip-comments --force test t1 --where='xx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' 2>&1
drop table t1;
--echo End of 4.1 tests
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment