Skip to content

Commit 07e9762

Browse files
committed
MDEV-8615: Assertion `m_cpp_buf <= begin_ptr && begin_ptr <= m_cpp_buf + m_buf_length' failed in Lex_input_stream::body_utf8_start
Nothing should be done before any keyword recognized.
1 parent eb15566 commit 07e9762

File tree

3 files changed

+133
-57
lines changed

3 files changed

+133
-57
lines changed

mysql-test/r/compound.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,10 @@ a
162162
begin not atomic select a from t1 having a > 1; end|
163163
a
164164
drop table t1|
165+
#
166+
# MDEV-8615: Assertion `m_cpp_buf <= begin_ptr &&
167+
# begin_ptr <= m_cpp_buf + m_buf_length' failed in
168+
# Lex_input_stream::body_utf8_start
169+
#
170+
b'|
171+
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'b'' at line 1

mysql-test/t/compound.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,10 @@ select a from t1 having a > 1|
150150
begin not atomic select a from t1 having a > 1; end|
151151
drop table t1|
152152

153+
--echo #
154+
--echo # MDEV-8615: Assertion `m_cpp_buf <= begin_ptr &&
155+
--echo # begin_ptr <= m_cpp_buf + m_buf_length' failed in
156+
--echo # Lex_input_stream::body_utf8_start
157+
--echo #
158+
--error ER_PARSE_ERROR
159+
--query b'

sql/sql_yacc.yy

Lines changed: 119 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,35 @@ static bool maybe_start_compound_statement(THD *thd)
248248
return 0;
249249
}
250250

251+
static bool push_sp_label(THD *thd, LEX_STRING label)
252+
{
253+
sp_pcontext *ctx= thd->lex->spcont;
254+
sp_label *lab= ctx->find_label(label);
255+
256+
if (lab)
257+
{
258+
my_error(ER_SP_LABEL_REDEFINE, MYF(0), label.str);
259+
return 1;
260+
}
261+
else
262+
{
263+
lab= thd->lex->spcont->push_label(thd, label,
264+
thd->lex->sphead->instructions());
265+
lab->type= sp_label::ITERATION;
266+
}
267+
return 0;
268+
}
269+
270+
static bool push_sp_empty_label(THD *thd)
271+
{
272+
if (maybe_start_compound_statement(thd))
273+
return 1;
274+
/* Unlabeled controls get an empty label. */
275+
thd->lex->spcont->push_label(thd, empty_lex_str,
276+
thd->lex->sphead->instructions());
277+
return 0;
278+
}
279+
251280
/**
252281
Helper action for a case expression statement (the expr in 'CASE expr').
253282
This helper is used for 'searched' cases only.
@@ -997,7 +1026,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
9971026
Currently there are 160 shift/reduce conflicts.
9981027
We should not introduce new conflicts any more.
9991028
*/
1000-
%expect 160
1029+
%expect 162
10011030

10021031
/*
10031032
Comments for TOKENS.
@@ -1934,6 +1963,7 @@ END_OF_INPUT
19341963
%type <NONE> sp_proc_stmt_iterate
19351964
%type <NONE> sp_proc_stmt_open sp_proc_stmt_fetch sp_proc_stmt_close
19361965
%type <NONE> case_stmt_specification
1966+
%type <NONE> loop_body while_body repeat_body
19371967

19381968
%type <num> sp_decl_idents sp_handler_type sp_hcond_list
19391969
%type <spcondvalue> sp_cond sp_hcond sqlstate signal_value opt_signal_value
@@ -3768,20 +3798,6 @@ sp_proc_stmt_return:
37683798
}
37693799
;
37703800

3771-
sp_unlabeled_control:
3772-
{
3773-
if (maybe_start_compound_statement(thd))
3774-
MYSQL_YYABORT;
3775-
/* Unlabeled controls get an empty label. */
3776-
Lex->spcont->push_label(thd, empty_lex_str,
3777-
Lex->sphead->instructions());
3778-
}
3779-
sp_control_content
3780-
{
3781-
Lex->sphead->backpatch(Lex->spcont->pop_label());
3782-
}
3783-
;
3784-
37853801
sp_proc_stmt_leave:
37863802
LEAVE_SYM label_ident
37873803
{
@@ -4200,41 +4216,6 @@ else_clause_opt:
42004216
| ELSE sp_proc_stmts1
42014217
;
42024218

4203-
sp_labeled_control:
4204-
label_ident ':'
4205-
{
4206-
LEX *lex= Lex;
4207-
sp_pcontext *ctx= lex->spcont;
4208-
sp_label *lab= ctx->find_label($1);
4209-
4210-
if (lab)
4211-
{
4212-
my_error(ER_SP_LABEL_REDEFINE, MYF(0), $1.str);
4213-
MYSQL_YYABORT;
4214-
}
4215-
else
4216-
{
4217-
lab= lex->spcont->push_label(thd, $1, lex->sphead->instructions());
4218-
lab->type= sp_label::ITERATION;
4219-
}
4220-
}
4221-
sp_control_content sp_opt_label
4222-
{
4223-
LEX *lex= Lex;
4224-
sp_label *lab= lex->spcont->pop_label();
4225-
4226-
if ($5.str)
4227-
{
4228-
if (my_strcasecmp(system_charset_info, $5.str, lab->name.str) != 0)
4229-
{
4230-
my_error(ER_SP_LABEL_MISMATCH, MYF(0), $5.str);
4231-
MYSQL_YYABORT;
4232-
}
4233-
}
4234-
lex->sphead->backpatch(lab);
4235-
}
4236-
;
4237-
42384219
sp_opt_label:
42394220
/* Empty */ { $$= null_lex_str; }
42404221
| label_ident { $$= $1; }
@@ -4327,8 +4308,7 @@ sp_block_content:
43274308
}
43284309
;
43294310

4330-
sp_control_content:
4331-
LOOP_SYM
4311+
loop_body:
43324312
sp_proc_stmts1 END LOOP_SYM
43334313
{
43344314
LEX *lex= Lex;
@@ -4340,15 +4320,16 @@ sp_control_content:
43404320
lex->sphead->add_instr(i))
43414321
MYSQL_YYABORT;
43424322
}
4343-
| WHILE_SYM
4344-
{ Lex->sphead->reset_lex(thd); }
4323+
;
4324+
4325+
while_body:
43454326
expr DO_SYM
43464327
{
43474328
LEX *lex= Lex;
43484329
sp_head *sp= lex->sphead;
43494330
uint ip= sp->instructions();
43504331
sp_instr_jump_if_not *i= new (lex->thd->mem_root)
4351-
sp_instr_jump_if_not(ip, lex->spcont, $3, lex);
4332+
sp_instr_jump_if_not(ip, lex->spcont, $1, lex);
43524333
if (i == NULL ||
43534334
/* Jumping forward */
43544335
sp->push_backpatch(i, lex->spcont->last_label()) ||
@@ -4370,15 +4351,18 @@ sp_control_content:
43704351
MYSQL_YYABORT;
43714352
lex->sphead->do_cont_backpatch();
43724353
}
4373-
| REPEAT_SYM sp_proc_stmts1 UNTIL_SYM
4354+
;
4355+
4356+
repeat_body:
4357+
sp_proc_stmts1 UNTIL_SYM
43744358
{ Lex->sphead->reset_lex(thd); }
43754359
expr END REPEAT_SYM
43764360
{
43774361
LEX *lex= Lex;
43784362
uint ip= lex->sphead->instructions();
43794363
sp_label *lab= lex->spcont->last_label(); /* Jumping back */
43804364
sp_instr_jump_if_not *i= new (lex->thd->mem_root)
4381-
sp_instr_jump_if_not(ip, lex->spcont, $5, lab->ip, lex);
4365+
sp_instr_jump_if_not(ip, lex->spcont, $4, lab->ip, lex);
43824366
if (i == NULL ||
43834367
lex->sphead->add_instr(i))
43844368
MYSQL_YYABORT;
@@ -4389,6 +4373,84 @@ sp_control_content:
43894373
}
43904374
;
43914375

4376+
pop_sp_label:
4377+
sp_opt_label
4378+
{
4379+
sp_label *lab;
4380+
Lex->sphead->backpatch(lab= Lex->spcont->pop_label());
4381+
if ($1.str)
4382+
{
4383+
if (my_strcasecmp(system_charset_info, $1.str,
4384+
lab->name.str) != 0)
4385+
{
4386+
my_error(ER_SP_LABEL_MISMATCH, MYF(0), $1.str);
4387+
MYSQL_YYABORT;
4388+
}
4389+
}
4390+
}
4391+
;
4392+
4393+
pop_sp_empty_label:
4394+
{
4395+
sp_label *lab;
4396+
Lex->sphead->backpatch(lab= Lex->spcont->pop_label());
4397+
DBUG_ASSERT(lab->name.length == 0);
4398+
}
4399+
;
4400+
4401+
sp_labeled_control:
4402+
label_ident ':' LOOP_SYM
4403+
{
4404+
if (push_sp_label(thd, $1))
4405+
MYSQL_YYABORT;
4406+
}
4407+
loop_body pop_sp_label
4408+
{ }
4409+
| label_ident ':' WHILE_SYM
4410+
{
4411+
if (push_sp_label(thd, $1))
4412+
MYSQL_YYABORT;
4413+
Lex->sphead->reset_lex(thd);
4414+
}
4415+
while_body pop_sp_label
4416+
{ }
4417+
| label_ident ':' REPEAT_SYM
4418+
{
4419+
if (push_sp_label(thd, $1))
4420+
MYSQL_YYABORT;
4421+
}
4422+
repeat_body pop_sp_label
4423+
{ }
4424+
;
4425+
4426+
sp_unlabeled_control:
4427+
LOOP_SYM
4428+
{
4429+
if (push_sp_empty_label(thd))
4430+
MYSQL_YYABORT;
4431+
}
4432+
loop_body
4433+
pop_sp_empty_label
4434+
{ }
4435+
| WHILE_SYM
4436+
{
4437+
if (push_sp_empty_label(thd))
4438+
MYSQL_YYABORT;
4439+
Lex->sphead->reset_lex(thd);
4440+
}
4441+
while_body
4442+
pop_sp_empty_label
4443+
{ }
4444+
| REPEAT_SYM
4445+
{
4446+
if (push_sp_empty_label(thd))
4447+
MYSQL_YYABORT;
4448+
}
4449+
repeat_body
4450+
pop_sp_empty_label
4451+
{ }
4452+
;
4453+
43924454
trg_action_time:
43934455
BEFORE_SYM
43944456
{ Lex->trg_chistics.action_time= TRG_ACTION_BEFORE; }

0 commit comments

Comments
 (0)