Skip to content

Commit

Permalink
MDEV-32458 ASAN unknown-crash in Inet6::ascii_to_fbt when casting cha…
Browse files Browse the repository at this point in the history
…racter string to inet6

The condition checked the value of the leftmost byte before checking if
at least one byte is still available in the buffer.
Changing the order in the condition: check for a byte availability before
checking the byte value.
  • Loading branch information
abarkov committed Apr 10, 2024
1 parent 2d2172a commit 37fd497
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
11 changes: 11 additions & 0 deletions plugin/type_inet/mysql-test/type_inet/type_inet6.result
Original file line number Diff line number Diff line change
Expand Up @@ -2330,3 +2330,14 @@ Warning 1292 Incorrect inet6 value: ''
Warning 1292 Incorrect inet6 value: ''
Warning 1292 Incorrect inet6 value: ''
DROP TABLE t1;
#
# MDEV-32458 ASAN unknown-crash in Inet6::ascii_to_fbt when casting character string to inet6
#
CREATE TABLE t1 (c CHAR(3));
INSERT INTO t1 VALUES ('1:0'),('00:');
SELECT * FROM t1 WHERE c>CAST('::1' AS INET6);
c
Warnings:
Warning 1292 Incorrect inet6 value: '1:0'
Warning 1292 Incorrect inet6 value: '00:'
DROP TABLE t1;
10 changes: 10 additions & 0 deletions plugin/type_inet/mysql-test/type_inet/type_inet6.test
Original file line number Diff line number Diff line change
Expand Up @@ -1686,3 +1686,13 @@ SELECT 1.00 + (b = a) AS f FROM t1 ORDER BY f;
SELECT 1.00 + (b BETWEEN a AND '') AS f FROM t1 ORDER BY f;
SELECT 1.00 + (b IN (a,'')) AS f FROM t1 ORDER BY f;
DROP TABLE t1;


--echo #
--echo # MDEV-32458 ASAN unknown-crash in Inet6::ascii_to_fbt when casting character string to inet6
--echo #

CREATE TABLE t1 (c CHAR(3));
INSERT INTO t1 VALUES ('1:0'),('00:');
SELECT * FROM t1 WHERE c>CAST('::1' AS INET6);
DROP TABLE t1;
2 changes: 1 addition & 1 deletion plugin/type_inet/sql_type_inet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ bool Inet6::ascii_to_ipv6(const char *str, size_t str_length)
continue;
}

if (!*p || p >= str_end)
if (p >= str_end || !*p)
{
DBUG_PRINT("error", ("ascii_to_ipv6(%.*s): invalid IPv6 address: "
"ending at ':'.", (int) str_length, str));
Expand Down

0 comments on commit 37fd497

Please sign in to comment.