diff --git a/src/sql/parser/sql_parser_base.h b/src/sql/parser/sql_parser_base.h index 7ef6ab9491..2953c135de 100644 --- a/src/sql/parser/sql_parser_base.h +++ b/src/sql/parser/sql_parser_base.h @@ -739,4 +739,17 @@ extern int setup_token_pos_info_and_dup_string(ParseNode* node, ParseResult* p, int add_comment_list(ParseResult* p, const TokenPosInfo* info); #endif +// avoid '\0' in the middle of a str. +#define CHECK_STR_LEN_MATCH(src_str, str_len) \ + do { \ + if (OB_UNLIKELY(src_str == NULL)) { \ + } else { \ + for (int64_t i = 0; i < str_len; i++) { \ + if (OB_UNLIKELY(src_str[i] == '\0')) { \ + yyerror(yylloc, yyextra, "mismatch strlen, may cased by '\0' in str"); \ + } \ + } \ + } \ + } while (0); + #endif /* OCEANBASE_SRC_SQL_PARSER_SQL_PARSER_BASE_H_ */ diff --git a/src/sql/parser/sql_parser_mysql_mode.l b/src/sql/parser/sql_parser_mysql_mode.l index f331836ea7..5e72e40a3f 100644 --- a/src/sql/parser/sql_parser_mysql_mode.l +++ b/src/sql/parser/sql_parser_mysql_mode.l @@ -865,6 +865,7 @@ FALSE { yylloc->first_column = p->start_col_; char *tmp_literal = p->tmp_literal_; tmp_literal[yylval->node->str_len_] = '\0'; + CHECK_STR_LEN_MATCH(tmp_literal, yylval->node->str_len_); char *dup_value = NULL; if (p->is_not_utf8_connection_) {