summaryrefslogtreecommitdiff
path: root/sql/sql_lex.cc
diff options
context:
space:
mode:
authorDavi Arnaut <Davi.Arnaut@Sun.COM>2008-10-15 18:34:51 -0300
committerDavi Arnaut <Davi.Arnaut@Sun.COM>2008-10-15 18:34:51 -0300
commit4ab10baace0960f18a843beb880c99b6cd9ca2e3 (patch)
tree7bffc9fc29b23db812377eacd41db43c69d03850 /sql/sql_lex.cc
parentd4c75b7d0fbc316e8baae96aa33cd202daecb0f1 (diff)
downloadmariadb-git-4ab10baace0960f18a843beb880c99b6cd9ca2e3.tar.gz
Bug#37075: offset of limit clause might be truncated on 32-bits server w/o big tables
The problem is that the offset argument of the limit clause might be truncated on a 32-bits server built without big tables support. The truncation was happening because the original 64-bits long argument was being cast to a 32-bits (ha_rows) offset counter. The solution is to check if the conversing resulted in value truncation and if so, the offset is set to the maximum possible value that can fit on the type.
Diffstat (limited to 'sql/sql_lex.cc')
-rw-r--r--sql/sql_lex.cc22
1 files changed, 18 insertions, 4 deletions
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index ba9c0e93134..71aa80b8170 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -2041,12 +2041,26 @@ st_lex::copy_db_to(char **p_db, uint *p_db_length) const
void st_select_lex_unit::set_limit(SELECT_LEX *sl)
{
ha_rows select_limit_val;
+ ulonglong val;
DBUG_ASSERT(! thd->stmt_arena->is_stmt_prepare());
- select_limit_val= (ha_rows)(sl->select_limit ? sl->select_limit->val_uint() :
- HA_POS_ERROR);
- offset_limit_cnt= (ha_rows)(sl->offset_limit ? sl->offset_limit->val_uint() :
- ULL(0));
+ val= sl->select_limit ? sl->select_limit->val_uint() : HA_POS_ERROR;
+ select_limit_val= (ha_rows)val;
+#ifndef BIG_TABLES
+ /*
+ Check for overflow : ha_rows can be smaller then ulonglong if
+ BIG_TABLES is off.
+ */
+ if (val != (ulonglong)select_limit_val)
+ select_limit_val= HA_POS_ERROR;
+#endif
+ val= sl->offset_limit ? sl->offset_limit->val_uint() : ULL(0);
+ offset_limit_cnt= (ha_rows)val;
+#ifndef BIG_TABLES
+ /* Check for truncation. */
+ if (val != (ulonglong)offset_limit_cnt)
+ offset_limit_cnt= HA_POS_ERROR;
+#endif
select_limit_cnt= select_limit_val + offset_limit_cnt;
if (select_limit_cnt < select_limit_val)
select_limit_cnt= HA_POS_ERROR; // no limit