Skip to content

Commit

Permalink
[MySQL] Avoid confusing label and IPv6 address (#3606)
Browse files Browse the repository at this point in the history
Some label combined with some keywords (when written without a space
in between, which is valid for MySQL) can look like beginning of an IPv6
address, e.g.

    aaa:BEGIN

is currectly parsed as IPv6 address `aaa:be` and leads to a parsing
failure.

Make parsing of IPv6 address more robust and require at least two `:`
to make sure there is no confusion with labels.
  • Loading branch information
vjuranek authored Jul 12, 2023
1 parent 3f91b22 commit 6ce408a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sql/mysql/Positive-Technologies/MySqlLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ STRING_USER_NAME: (
);
IP_ADDRESS: (
[0-9]+ '.' [0-9.]+
| [0-9A-F:]+ ':' [0-9A-F:]+
| [0-9A-F]* ':' [0-9A-F]* ':' [0-9A-F:]+
);
LOCAL_ID: '@'
(
Expand Down
2 changes: 2 additions & 0 deletions sql/mysql/Positive-Technologies/examples/ddl_alter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ alter definer = current_user sql security invoker view my_view4(c1, 1c, _, c1_2)
-- Alter user
ALTER USER 'mattias.hultman' DEFAULT ROLE `prod-spain-mysql-read-only`@`%`;
rename user user1@100.200.1.1 to user2@100.200.1.2;
rename user user1@100.200.1.1 to user2@2001:0db8:85a3:0000:0000:8a2e:0370:7334;
rename user user1@100.200.1.1 to user2@::1;
alter user 'user'@'%' IDENTIFIED BY 'newpassword' RETAIN CURRENT PASSWORD;
ALTER USER 'test_dual_pass'@'%' IDENTIFIED BY RANDOM PASSWORD RETAIN CURRENT PASSWORD;
ALTER USER 'test_dual_pass'@'%' IDENTIFIED BY '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' RETAIN CURRENT PASSWORD;
Expand Down
14 changes: 13 additions & 1 deletion sql/mysql/Positive-Technologies/examples/ddl_create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,18 @@ BEGIN
END -- //-- delimiter ;
#end
#begin
-- delimiter //
CREATE PROCEDURE doiterate(p1 INT)
-- label which can be parsed as a beginning of IPv6 address
aaa:BEGIN
label1:LOOP
SET p1 = p1 + 1;
IF p1 < 10 THEN ITERATE label1; END IF;
LEAVE label1;
END LOOP label1;
END -- //-- delimiter ;
#end
#begin
CREATE DEFINER=`system_user`@`%` PROCEDURE `update_order`(IN orderID bigint(11))
BEGIN insert into order_config(order_id, attribute, value, performer)
SELECT orderID, 'first_attr', 'true', 'AppConfig'
Expand Down Expand Up @@ -659,4 +671,4 @@ DECLARE array VARCHAR(50);
SELECT 1;

END
#end
#end

0 comments on commit 6ce408a

Please sign in to comment.