From f4877a782639202770e71771d927129ff8fa2085 Mon Sep 17 00:00:00 2001 From: Deven Bansod Date: Thu, 22 Sep 2016 11:49:40 +0530 Subject: [PATCH] Assign LIMIT clause only to syntactically correct queries Assigning LIMIT clause to an syntactically-wrong query is not needed. Also we would want to show the true query and the true error message to the query executor Fix #12321 Signed-off-by: Deven Bansod --- libraries/sql.lib.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index 5ed4e8de54..d824586083 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -2131,9 +2131,16 @@ function PMA_executeQueryAndGetQueryResponse($analyzed_sql_results, // assign default full_sql_query $full_sql_query = $sql_query; - // Do append a "LIMIT" clause? - if (PMA_isAppendLimitClause($analyzed_sql_results)) { - $full_sql_query = PMA_getSqlWithLimitClause($analyzed_sql_results); + // Assigning LIMIT clause to an syntactically-wrong query + // is not needed. Also we would want to show the true query + // and the true error message to the query executor + if (isset($analyzed_sql_results['parser']) + && count($analyzed_sql_results['parser']->errors) === 0 + ) { + // Do append a "LIMIT" clause? + if (PMA_isAppendLimitClause($analyzed_sql_results)) { + $full_sql_query = PMA_getSqlWithLimitClause($analyzed_sql_results); + } } $GLOBALS['reload'] = PMA_hasCurrentDbChanged($db);