Commit 51d7e803 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-4285 Server crashes in ptr_compare on NOW and CAST in ORDER BY

skip qsort if the sort key has zero length
parent 17956118
create table t1 (pk int primary key);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
select * from t1 order by now(), cast(pk as char(0));
pk
1
2
3
4
5
6
7
8
9
10
Warnings:
Warning 1292 Truncated incorrect CHAR(0) value: '1'
Warning 1292 Truncated incorrect CHAR(0) value: '2'
Warning 1292 Truncated incorrect CHAR(0) value: '3'
Warning 1292 Truncated incorrect CHAR(0) value: '4'
Warning 1292 Truncated incorrect CHAR(0) value: '5'
Warning 1292 Truncated incorrect CHAR(0) value: '6'
Warning 1292 Truncated incorrect CHAR(0) value: '7'
Warning 1292 Truncated incorrect CHAR(0) value: '8'
Warning 1292 Truncated incorrect CHAR(0) value: '9'
Warning 1292 Truncated incorrect CHAR(0) value: '10'
drop table t1;
#
# MDEV-4285 Server crashes in ptr_compare on NOW and CAST in ORDER BY
#
create table t1 (pk int primary key);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);
select * from t1 order by now(), cast(pk as char(0));
drop table t1;
...@@ -125,7 +125,8 @@ void Filesort_buffer::free_sort_buffer() ...@@ -125,7 +125,8 @@ void Filesort_buffer::free_sort_buffer()
void Filesort_buffer::sort_buffer(const Sort_param *param, uint count) void Filesort_buffer::sort_buffer(const Sort_param *param, uint count)
{ {
if (count <= 1) size_t size= param->sort_length;
if (count <= 1 || size == 0)
return; return;
uchar **keys= get_sort_keys(); uchar **keys= get_sort_keys();
uchar **buffer= NULL; uchar **buffer= NULL;
...@@ -138,6 +139,5 @@ void Filesort_buffer::sort_buffer(const Sort_param *param, uint count) ...@@ -138,6 +139,5 @@ void Filesort_buffer::sort_buffer(const Sort_param *param, uint count)
return; return;
} }
size_t size= param->sort_length;
my_qsort2(keys, count, sizeof(uchar*), get_ptr_compare(size), &size); my_qsort2(keys, count, sizeof(uchar*), get_ptr_compare(size), &size);
} }
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