Skip to content

Commit 49098bf

Browse files
committed
MDEV-26732 Assertion `0' failed in Item::val_native
Also fixes MDEV-24619 Wrong result or Assertion `0' in Item::val_native / Type_handler_inet6::Item_val_native_with_conversion Type_handler_inet6::create_item_copy() created a generic Item_copy_string, which does not implement val_native() - it has a dummy implementation with DBUG_ASSERT(0), which made the server crash. Fix: - Adding a new class Type_handler_inet6 which implements val_native(). - Fixing Type_handler_inet6::create_item_copy() to make Item_copy_inet6 instead of Item_copy_string.
1 parent 395a033 commit 49098bf

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
lines changed

plugin/type_inet/mysql-test/type_inet/type_inet6.result

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,3 +2159,38 @@ IFNULL(c, '::1')
21592159
::1
21602160
DROP TABLE t2;
21612161
DROP TABLE t1;
2162+
#
2163+
# MDEV-26732 Assertion `0' failed in Item::val_native
2164+
#
2165+
SELECT CAST(CONCAT('::', REPEAT('',RAND())) AS INET6) AS f, var_pop('x') FROM dual HAVING f > '';
2166+
f var_pop('x')
2167+
Warnings:
2168+
Warning 1292 Truncated incorrect DOUBLE value: 'x'
2169+
Warning 1292 Incorrect inet6 value: ''
2170+
SELECT CAST(CONCAT('::', REPEAT('',RAND())) AS INET6) AS f, var_pop(1) FROM dual HAVING f >= '::';
2171+
f var_pop(1)
2172+
:: 0.0000
2173+
CREATE TABLE t1(id INET6 NOT NULL PRIMARY KEY, dsc INET6);
2174+
INSERT INTO t1 VALUES ('::1', '1::1'),('::3', '1::3'),('::4', NULL);
2175+
CREATE TABLE t2 SELECT COALESCE(t1.dsc), COUNT(*) FROM t1 GROUP BY t1.id;
2176+
SELECT * FROM t2 ORDER BY 1,2;
2177+
COALESCE(t1.dsc) COUNT(*)
2178+
NULL 1
2179+
1::1 1
2180+
1::3 1
2181+
DROP TABLE t1, t2;
2182+
#
2183+
# MDEV-24619 Wrong result or Assertion `0' in Item::val_native / Type_handler_inet6::Item_val_native_with_conversion
2184+
#
2185+
CREATE TABLE t1 (a INET6);
2186+
INSERT INTO t1 VALUES ('::'),('::');
2187+
SELECT IF(1, '::', a) AS f FROM t1 GROUP BY 'foo' HAVING f != '';
2188+
f
2189+
Warnings:
2190+
Warning 1292 Incorrect inet6 value: ''
2191+
SELECT IF(1, '::', a) AS f FROM t1 GROUP BY 'foo' HAVING f != '::';
2192+
f
2193+
SELECT IF(1, '::', a) AS f FROM t1 GROUP BY 'foo' HAVING f != '::1';
2194+
f
2195+
::
2196+
DROP TABLE t1;

plugin/type_inet/mysql-test/type_inet/type_inet6.test

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,3 +1586,29 @@ SELECT * FROM t2;
15861586
DROP TABLE t2;
15871587

15881588
DROP TABLE t1;
1589+
1590+
--echo #
1591+
--echo # MDEV-26732 Assertion `0' failed in Item::val_native
1592+
--echo #
1593+
1594+
# This tests Item_copy_inet6::val_native()
1595+
SELECT CAST(CONCAT('::', REPEAT('',RAND())) AS INET6) AS f, var_pop('x') FROM dual HAVING f > '';
1596+
SELECT CAST(CONCAT('::', REPEAT('',RAND())) AS INET6) AS f, var_pop(1) FROM dual HAVING f >= '::';
1597+
1598+
# This tests Item_copy_inet6::save_in_field()
1599+
CREATE TABLE t1(id INET6 NOT NULL PRIMARY KEY, dsc INET6);
1600+
INSERT INTO t1 VALUES ('::1', '1::1'),('::3', '1::3'),('::4', NULL);
1601+
CREATE TABLE t2 SELECT COALESCE(t1.dsc), COUNT(*) FROM t1 GROUP BY t1.id;
1602+
SELECT * FROM t2 ORDER BY 1,2;
1603+
DROP TABLE t1, t2;
1604+
1605+
--echo #
1606+
--echo # MDEV-24619 Wrong result or Assertion `0' in Item::val_native / Type_handler_inet6::Item_val_native_with_conversion
1607+
--echo #
1608+
1609+
CREATE TABLE t1 (a INET6);
1610+
INSERT INTO t1 VALUES ('::'),('::');
1611+
SELECT IF(1, '::', a) AS f FROM t1 GROUP BY 'foo' HAVING f != '';
1612+
SELECT IF(1, '::', a) AS f FROM t1 GROUP BY 'foo' HAVING f != '::';
1613+
SELECT IF(1, '::', a) AS f FROM t1 GROUP BY 'foo' HAVING f != '::1';
1614+
DROP TABLE t1;

plugin/type_inet/sql_type_inet.cc

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,57 @@ class Item_literal_inet6: public Item_literal
12271227
};
12281228

12291229

1230+
class Item_copy_inet6: public Item_copy
1231+
{
1232+
NativeBufferInet6 m_value;
1233+
public:
1234+
Item_copy_inet6(THD *thd, Item *item_arg): Item_copy(thd, item_arg) {}
1235+
1236+
bool val_native(THD *thd, Native *to) override
1237+
{
1238+
if (null_value)
1239+
return true;
1240+
return to->copy(m_value.ptr(), m_value.length());
1241+
}
1242+
String *val_str(String *to) override
1243+
{
1244+
if (null_value)
1245+
return NULL;
1246+
Inet6_null tmp(m_value.ptr(), m_value.length());
1247+
return tmp.is_null() || tmp.to_string(to) ? NULL : to;
1248+
}
1249+
my_decimal *val_decimal(my_decimal *to) override
1250+
{
1251+
my_decimal_set_zero(to);
1252+
return to;
1253+
}
1254+
double val_real() override
1255+
{
1256+
return 0;
1257+
}
1258+
longlong val_int() override
1259+
{
1260+
return 0;
1261+
}
1262+
bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) override
1263+
{
1264+
set_zero_time(ltime, MYSQL_TIMESTAMP_TIME);
1265+
return null_value;
1266+
}
1267+
void copy() override
1268+
{
1269+
null_value= item->val_native(current_thd, &m_value);
1270+
DBUG_ASSERT(null_value == item->null_value);
1271+
}
1272+
int save_in_field(Field *field, bool no_conversions) override
1273+
{
1274+
return Item::save_in_field(field, no_conversions);
1275+
}
1276+
Item *get_copy(THD *thd) override
1277+
{ return get_item_copy<Item_copy_inet6>(thd, this); }
1278+
};
1279+
1280+
12301281
class in_inet6 :public in_vector
12311282
{
12321283
Inet6 m_value;
@@ -1465,6 +1516,12 @@ Item_cache *Type_handler_inet6::Item_get_cache(THD *thd, const Item *item) const
14651516
}
14661517

14671518

1519+
Item_copy *Type_handler_inet6::create_item_copy(THD *thd, Item *item) const
1520+
{
1521+
return new (thd->mem_root) Item_copy_inet6(thd, item);
1522+
}
1523+
1524+
14681525
Item *
14691526
Type_handler_inet6::make_const_item_for_comparison(THD *thd,
14701527
Item *src,

plugin/type_inet/sql_type_inet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ class Type_handler_inet6: public Type_handler
691691
Item *create_typecast_item(THD *thd, Item *item,
692692
const Type_cast_attributes &attr) const override;
693693

694+
Item_copy *create_item_copy(THD *thd, Item *item) const override;
694695
int cmp_native(const Native &a, const Native &b) const override
695696
{
696697
DBUG_ASSERT(a.length() == Inet6::binary_length());

0 commit comments

Comments
 (0)