提交 d1aa3c5d 编写于 作者: M Monk-Liu 提交者: wangzelin.wzl

[CP] [bugfix][errcode]: avoid -4013 errcode being overwritten in parser.

上级 d647b8f1
......@@ -63,7 +63,7 @@ int add_word(t_node* root, const char* str, const int32_t idx)
if (ch_id >= 0 && NULL == pt->next[ch_id]) {
t_node* new_node = (t_node*)calloc(1, sizeof(t_node));
if (OB_UNLIKELY(NULL == new_node)) {
ret = 1;
ret = OB_PARSER_ERR_NO_MEMORY;
printf("ERROR malloc memory failed! \n");
} else {
new_node->idx = -1;
......
......@@ -59,13 +59,15 @@ int ObSQLParser::parse_and_gen_sqlid(
int64_t new_length = str_len + 1;
char* buf = (char*)parse_malloc(new_length, parse_result->malloc_pool_);
parse_result->param_nodes_ = NULL;
parse_result->tail_param_node_ = NULL;
parse_result->no_param_sql_ = buf;
parse_result->no_param_sql_buf_len_ = new_length;
ret = parse(str_ptr, new_length, *parse_result);
if (OB_UNLIKELY(NULL == buf)) {
ret = OB_ALLOCATE_MEMORY_FAILED;
} else {
parse_result->param_nodes_ = NULL;
parse_result->tail_param_node_ = NULL;
parse_result->no_param_sql_ = buf;
parse_result->no_param_sql_buf_len_ = new_length;
ret = parse(str_ptr, new_length, *parse_result);
}
if (OB_SUCC(ret)) {
ret = gen_sqlid(parse_result->no_param_sql_, parse_result->no_param_sql_len_, len, sql_id);
......
......@@ -377,7 +377,7 @@ extern ParseNode* new_node(void* malloc_pool, ObItemType type, int num);
char* dest = NULL; \
size_t len = end - begin - 1; \
dest = parse_strndup(begin + 1, len, malloc_pool); \
check_value(dest); \
check_malloc(dest); \
node->str_value_ = dest; \
node->str_len_ = len; \
check_value(yylval); \
......@@ -396,13 +396,13 @@ extern ParseNode* new_node(void* malloc_pool, ObItemType type, int num);
} \
} while (0);
#define check_malloc(val_ptr, nbyte) \
do { \
if (OB_UNLIKELY(NULL == val_ptr)) { \
((ParseResult*)yyextra)->extra_errno_ = OB_PARSER_ERR_NO_MEMORY; \
yyerror(yylloc, yyextra, "No more space for malloc(size: %ld)\n", (size_t)nbyte); \
return ERROR; \
} \
#define check_malloc(val_ptr) \
do { \
if (OB_UNLIKELY(NULL == val_ptr)) { \
((ParseResult *)yyextra)->extra_errno_ = OB_PARSER_ERR_NO_MEMORY; \
yyerror(yylloc, yyextra, "No more space for malloc\n"); \
return ERROR; \
} \
} while (0);
#define check_identifier_convert_result(errno) \
......@@ -424,7 +424,7 @@ extern ParseNode* new_node(void* malloc_pool, ObItemType type, int num);
} else { \
ParseResult* p = (ParseResult*)yyextra; \
dst = parse_strndup(src, src_len, p->malloc_pool_); \
check_value(dst); \
check_malloc(dst); \
} \
} while (0);
......@@ -434,7 +434,7 @@ extern ParseNode* new_node(void* malloc_pool, ObItemType type, int num);
char** tmp_literal = &(p->tmp_literal_); \
if (NULL == *tmp_literal) { \
*tmp_literal = (char*)parse_malloc(p->input_sql_len_ + 1, p->malloc_pool_); \
check_value(*tmp_literal); \
check_malloc(*tmp_literal); \
} \
if (str_node->str_value_ != NULL) { \
memmove(((ParseResult*)yyextra)->tmp_literal_, str_node->str_value_, str_node->str_len_); \
......@@ -452,7 +452,7 @@ extern ParseNode* new_node(void* malloc_pool, ObItemType type, int num);
char** tmp_literal = &(p->tmp_literal_); \
if (NULL == *tmp_literal) { \
*tmp_literal = (char*)parse_malloc(p->input_sql_len_ + 1, p->malloc_pool_); \
check_value(*tmp_literal); \
check_malloc(*tmp_literal); \
} \
memmove(*tmp_literal + str_node->str_len_, yytext, yyleng); \
str_node->str_len_ += yyleng; \
......@@ -466,7 +466,7 @@ extern ParseNode* new_node(void* malloc_pool, ObItemType type, int num);
char* tmp_literal = p->tmp_literal_; \
tmp_literal[yylval->node->str_len_] = '\0'; \
str_node->str_value_ = parse_strndup(tmp_literal, str_node->str_len_ + 1, p->malloc_pool_); \
check_value(str_node->str_value_); \
check_malloc(str_node->str_value_); \
} \
} while (0);
......@@ -509,8 +509,8 @@ extern ParseNode* new_node(void* malloc_pool, ObItemType type, int num);
} \
p->no_param_sql_[p->no_param_sql_len_] = '\0'; \
size_t alloc_len = sizeof(ParamList); \
ParamList* param = (ParamList*)parse_malloc(alloc_len, p->malloc_pool_); \
check_malloc(param, alloc_len); \
ParamList *param = (ParamList *)parse_malloc(alloc_len, p->malloc_pool_); \
check_malloc(param); \
check_value(yylval); \
check_value(yylval->node); \
yylval->node->pos_ = p->no_param_sql_len_ - 1; \
......@@ -546,9 +546,9 @@ extern ParseNode* new_node(void* malloc_pool, ObItemType type, int num);
yylval->node = node; \
yylval->node->raw_text_ = \
parse_strdup(yytext, ((ParseResult*)yyextra)->malloc_pool_, &(yylval->node->text_len_)); \
check_value(yylval->node->raw_text_); \
check_malloc(yylval->node->raw_text_); \
node->str_value_ = parse_strdup((char*)str_val, ((ParseResult*)yyextra)->malloc_pool_, &(node->str_len_)); \
check_value(node->str_value_); \
check_malloc(node->str_value_); \
node->value_ = strtoll(node->str_value_, NULL, 10); \
STORE_PARAM_NODE() \
} else { \
......@@ -656,6 +656,7 @@ extern ParseNode* new_node(void* malloc_pool, ObItemType type, int num);
if ('-' == param_node->str_value_[0]) { \
char* copied_str = parse_strndup(param_node->str_value_, param_node->str_len_, malloc_pool); \
if (OB_ISNULL(copied_str)) { \
((ParseResult *)yyextra)->extra_errno_ = OB_PARSER_ERR_NO_MEMORY; \
yyerror(NULL, yyextra, "No more space for mallocing"); \
return ERROR; \
} else { \
......
......@@ -435,7 +435,7 @@ NULL {
check_value(yylval);
yylval->node = node;
node->str_value_ = parse_strdup(yytext, p->malloc_pool_, &(node->str_len_));
check_value(node->str_value_);
check_malloc(node->str_value_);
int err_no = 0;
node->value_ = ob_strntoll(node->str_value_, node->str_len_, 10, NULL, &err_no);
if (ERANGE == err_no)
......@@ -619,6 +619,7 @@ FALSE {
malloc_new_node(yylval->node->children_[0], p->malloc_pool_, T_CONCAT_STRING, 0);
(*yylval->node->children_)->str_value_ = parse_strndup(tmp_literal, yylval->node->str_len_ + 1,
p->malloc_pool_);
check_malloc((*yylval->node->children_)->str_value_);
(*yylval->node->children_)->str_len_ = yylval->node->str_len_;
yylval->node->num_child_ = 1;
}
......@@ -648,7 +649,7 @@ FALSE {
if (*tmp_literal == NULL)
{
*tmp_literal = (char*) parse_malloc(p->input_sql_len_ + 1, p->malloc_pool_);
check_value(*tmp_literal);
check_malloc(*tmp_literal);
}
malloc_new_node(yylval->node, p->malloc_pool_, T_IDENT, 0);
yylval->node->str_len_ = 0;
......@@ -660,7 +661,7 @@ FALSE {
if (*tmp_literal == NULL)
{
*tmp_literal = (char*) parse_malloc(p->input_sql_len_ + 1, p->malloc_pool_);
check_value(*tmp_literal);
check_malloc(*tmp_literal);
}
malloc_new_node(yylval->node, p->malloc_pool_, T_VARCHAR, 0);
yylval->node->str_len_ = 0;
......@@ -679,8 +680,10 @@ FALSE {
check_value(yylval);
tmp_literal[yylval->node->str_len_] = '\0';
yylval->node->str_value_ = parse_strndup(tmp_literal, yylval->node->str_len_ + 1, p->malloc_pool_);
check_malloc(yylval->node->str_value_);
yylval->node->text_len_ = yylloc->last_column - p->start_col_ + 1;
yylval->node->raw_text_ = parse_strndup(p->input_sql_ + p->start_col_ - 1, yylval->node->text_len_, p->malloc_pool_);
check_malloc(yylval->node->raw_text_);
if (IS_FAST_PARAMETERIZE) {
STORE_PARAM_NODE();
} else {
......@@ -755,6 +758,7 @@ FALSE {
malloc_new_node(yylval->node->children_[0], p->malloc_pool_, T_CONCAT_STRING, 0);
(*yylval->node->children_)->str_value_ = parse_strndup(tmp_literal, yylval->node->str_len_ + 1,
p->malloc_pool_);
check_malloc((*yylval->node->children_)->str_value_);
(*yylval->node->children_)->str_len_ = yylval->node->str_len_;
yylval->node->num_child_ = 1;
}
......@@ -806,7 +810,7 @@ FALSE {
} else {
dup_value = parse_strndup(tmp_literal, yylval->node->str_len_ + 1, p->malloc_pool_);
}
check_value(dup_value);
check_malloc(dup_value);
yylval->node->str_value_ = dup_value;
setup_token_pos_info(yylval->node, yylloc->first_column, yylval->node->str_len_);
return NAME_OB;
......@@ -830,7 +834,7 @@ FALSE {
if (NULL == *tmp_literal)
{
*tmp_literal = (char *)parse_malloc(p->input_sql_len_ + 1, p->malloc_pool_);
check_value(*tmp_literal);
check_malloc(*tmp_literal);
}
malloc_new_node(yylval->node, p->malloc_pool_, T_IDENT, 0);
yylval->node->str_len_ = 0;
......@@ -875,7 +879,7 @@ FALSE {
} else {
dup_value = parse_strndup(tmp_literal, yylval->node->str_len_ + 1, p->malloc_pool_);
}
check_value(dup_value);
check_malloc(dup_value);
yylval->node->str_value_ = dup_value;
setup_token_pos_info(yylval->node, yylloc->first_column, yylval->node->str_len_);
return NAME_OB;
......@@ -900,7 +904,7 @@ X'([0-9A-F])*'|0X([0-9A-F])+ {
if (len > 0) {
int64_t dest_len = ob_parse_binary_len(len);
char *dest = (char *)parse_malloc(dest_len, p->malloc_pool_);
check_value(dest);
check_malloc(dest);
ob_parse_binary(src, len, dest);
node->str_value_ = dest;
node->str_len_ = dest_len;
......@@ -936,7 +940,7 @@ B'([01])*'|0B([01])+ {
{
int64_t dest_len = ob_parse_bit_string_len(len);
char *dest = (char*)parse_malloc(dest_len, p->malloc_pool_);
check_value(dest);
check_malloc(dest);
ob_parse_bit_string(src, len, dest);
node->str_value_ = dest;
node->str_len_ = dest_len;
......@@ -1050,7 +1054,7 @@ Timestamp{whitespace}?\"[^\"]*\" {
ParseResult *p = (ParseResult *)yyextra;
malloc_new_node(node, p->malloc_pool_, T_HINT, 0);
dest = parse_strdup(yytext + 3, p->malloc_pool_, &out_len);
check_value(dest);
check_malloc(dest);
dest[out_len - 2] = '\0';
node->str_value_ = dest;
......@@ -1208,7 +1212,7 @@ Timestamp{whitespace}?\"[^\"]*\" {
} else {
dup_value = parse_strdup(yytext, p->malloc_pool_, &out_len);
}
check_value(dup_value);
check_malloc(dup_value);
node->str_value_ = str_tolower(dup_value, strlen(dup_value));
node->str_len_ = out_len;
setup_token_pos_info(node, yylloc->first_column - 1, yylval->node->str_len_);
......@@ -1306,7 +1310,7 @@ BEGIN(in_c_comment);
char *dup_value = NULL;
int64_t out_len = 0;
dup_value = parse_strdup(yytext, p->malloc_pool_, &out_len);
check_value(dup_value);
check_malloc(dup_value);
node->str_value_ = str_tolower(dup_value, strlen(dup_value));
node->str_len_ = out_len;
return STRING_VALUE;
......@@ -1414,7 +1418,7 @@ BEGIN(in_c_comment);
}
if (IS_FAST_PARAMETERIZE) {
yylval->node->raw_text_ = parse_strdup(yytext, p->malloc_pool_, &(yylval->node->text_len_));
check_value(yylval->node->raw_text_);
check_malloc(yylval->node->raw_text_);
STORE_PARAM_NODE();
} else {
return QUESTIONMARK;
......@@ -1428,7 +1432,7 @@ BEGIN(in_c_comment);
yylval->node->value_ = get_question_mark(&p->question_mark_ctx_, p->malloc_pool_, yytext);
if (IS_FAST_PARAMETERIZE) {
yylval->node->raw_text_ = parse_strdup(yytext, p->malloc_pool_, &(yylval->node->text_len_));
check_value(yylval->node->raw_text_);
check_malloc(yylval->node->raw_text_);
STORE_PARAM_NODE();
} else {
return QUESTIONMARK;
......@@ -1445,7 +1449,7 @@ BEGIN(in_c_comment);
yylval->node = node;
/* skip '@@' */
node->str_value_ = parse_strdup(yytext + 2, p->malloc_pool_, &(node->str_len_));
check_value(node->str_value_);
check_malloc(node->str_value_);
//node->value_ = 2;
node->value_ = 0;
} else {
......@@ -1465,6 +1469,7 @@ BEGIN(in_c_comment);
yylval->node = node;
/* skip '@' and quotes like '/"/` */
node->str_value_ = parse_strdup(yytext + 1, p->malloc_pool_, &(node->str_len_));
check_malloc(node->str_value_);
if (NULL != node->str_value_
&& node->str_len_ > 1
&& *(yytext + 1) == *(yytext + node->str_len_)
......@@ -1512,7 +1517,7 @@ BEGIN(in_c_comment);
} else {
node->str_value_ = parse_strdup(yytext, p->malloc_pool_, &(node->str_len_));
}
check_value(node->str_value_);
check_malloc(node->str_value_);
setup_token_pos_info(node, yylloc->first_column - 1, node->str_len_);
ret = NAME_OB;
//CHECK_NODE_STRING_VALUE_ASCII(ret, node->str_value_, node->str_len_);
......
......@@ -9549,8 +9549,9 @@ SHOW opt_full TABLES opt_from_or_in_database_clause opt_show_condition
value->str_value_ = parse_strndup("SYS", strlen("SYS") + 1, result->malloc_pool_);
if (NULL == value->str_value_)
{
yyerror(NULL, result, "No more space for mallocing string\n");
YYABORT;
((ParseResult *)yyextra)->extra_errno_ = OB_PARSER_ERR_NO_MEMORY;
yyerror(NULL, result, "No more space for mallocing string\n");
YYABORT;
}
value->str_len_ = strlen("SYS");
malloc_non_terminal_node(sub_where, result->malloc_pool_, T_OP_NE, 2, column, value);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册