Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBRD-25186] [bugfix] Run-time exception of expression BIT_LENGTH('CUBRID') #5650

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/parser/parse_tree_cl.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,13 @@ pt_walk_private (PARSER_CONTEXT * parser, PT_NODE * node, void *void_arg)
* calling pt_apply. */
node_type = node->node_type;

assert (node_type >= PT_NODE_NONE);
if (node_type == PT_NODE_NONE)
{
assert (pt_has_error (parser));
return NULL;
}

ctshim marked this conversation as resolved.
Show resolved Hide resolved
if (node_type >= PT_LAST_NODE_NUMBER || !(apply = pt_apply_f[node_type]))
{
return NULL;
Expand Down
58 changes: 53 additions & 5 deletions src/parser/type_checking.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,23 +529,25 @@ pt_get_expression_definition (const PT_OP_TYPE op, EXPRESSION_DEFINITION * def)
num = 0;

/* two overloads */

/* arg1 */
sig.arg1_type.type = pt_arg_type::GENERIC;
sig.arg1_type.val.generic_type = PT_GENERIC_TYPE_STRING;
/* return type */

/* return type */
sig.return_type.type = pt_arg_type::NORMAL;
sig.return_type.val.type = PT_TYPE_INTEGER;
def->overloads[num++] = sig;

/* arg1 */
sig.arg1_type.type = pt_arg_type::GENERIC;
sig.arg1_type.val.generic_type = PT_GENERIC_TYPE_BIT;
/* return type */
def->overloads[num++] = sig;

/* arg1 */
sig.arg1_type.type = pt_arg_type::NORMAL;
sig.arg1_type.val.type = PT_TYPE_BLOB;
/* return type */
sig.return_type.type = pt_arg_type::NORMAL;
sig.return_type.val.type = PT_TYPE_INTEGER;
def->overloads[num++] = sig;

def->overloads_count = num;
Expand Down Expand Up @@ -6128,8 +6130,8 @@ pt_apply_expressions_definition (PARSER_CONTEXT * parser, PT_NODE ** node)
return NO_ERROR;
}

matches = -1;
best_match = 0;
matches = -1;
for (i = 0; i < def.overloads_count; i++)
{
int match_cnt = 0;
Expand Down Expand Up @@ -15759,6 +15761,24 @@ pt_evaluate_db_value_expr (PARSER_CONTEXT * parser, PT_NODE * expr, PT_OP_TYPE o

if (!PT_IS_STRING_TYPE (o1->type_enum))
{
if (o1->type_enum == PT_TYPE_BLOB)
ctshim marked this conversation as resolved.
Show resolved Hide resolved
{
DB_VALUE tval;

db_make_null (&tval);
dom_status = tp_value_cast (arg1, &tval, &tp_VarBit_domain, false);
if (dom_status != DOMAIN_COMPATIBLE)
{
PT_ERRORmf2 (parser, o1, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CANT_COERCE_TO,
pt_short_print (parser, o1), pt_show_type_enum (rTyp));
db_value_clear (&tval);
return 0;
}
db_make_int (result, db_get_string_size (&tval));
db_value_clear (&tval);
return 1;
}

return 0;
}

Expand All @@ -15774,6 +15794,27 @@ pt_evaluate_db_value_expr (PARSER_CONTEXT * parser, PT_NODE * expr, PT_OP_TYPE o

if (!PT_IS_STRING_TYPE (o1->type_enum))
{
if (o1->type_enum == PT_TYPE_BLOB)
{
DB_VALUE tval;
int len = 0;

db_make_null (&tval);
dom_status = tp_value_cast (arg1, &tval, &tp_VarBit_domain, false);
if (dom_status != DOMAIN_COMPATIBLE)
{
PT_ERRORmf2 (parser, o1, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CANT_COERCE_TO,
pt_short_print (parser, o1), pt_show_type_enum (rTyp));
db_value_clear (&tval);
return 0;
}

db_get_bit (&tval, &len);
db_make_int (result, len);
db_value_clear (&tval);
return 1;
}

return 0;
}

Expand Down Expand Up @@ -19203,6 +19244,11 @@ pt_semantic_type (PARSER_CONTEXT * parser, PT_NODE * tree, SEMANTIC_CHK_INFO * s
}
/* do type checking */
tree = parser_walk_tree (parser, tree, pt_eval_type_pre, sc_info_ptr, pt_eval_type, sc_info_ptr);
if (pt_has_error (parser))
{
tree = NULL;
return tree;
}
ctshim marked this conversation as resolved.
Show resolved Hide resolved
/* do constant folding */
tree = parser_walk_tree (parser, tree, pt_fold_constants_pre, NULL, pt_fold_constants_post, sc_info_ptr);
if (pt_has_error (parser))
Expand Down Expand Up @@ -20377,6 +20423,8 @@ pt_is_op_hv_late_bind (PT_OP_TYPE op)
case PT_HOURF:
case PT_MINUTEF:
case PT_SECONDF:
case PT_BIT_LENGTH:
case PT_OCTET_LENGTH:
case PT_TO_DATE:
case PT_TO_DATETIME:
case PT_TO_DATETIME_TZ:
Expand Down
65 changes: 64 additions & 1 deletion src/query/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
#include "dbtype.h"
// XXX: SHOULD BE THE LAST INCLUDE HEADER
#include "memory_wrapper.hpp"

static int fetch_peek_arith (THREAD_ENTRY * thread_p, REGU_VARIABLE * regu_var, val_descr * vd, OID * obj_oid,
QFILE_TUPLE tpl, DB_VALUE ** peek_dbval);
static int fetch_peek_dbval_pos (REGU_VARIABLE * regu_var, QFILE_TUPLE tpl, int pos, DB_VALUE ** peek_dbval,
Expand Down Expand Up @@ -1210,6 +1209,37 @@ fetch_peek_arith (THREAD_ENTRY * thread_p, REGU_VARIABLE * regu_var, val_descr *
{
PRIM_SET_NULL (arithptr->value);
}
else if (DB_VALUE_DOMAIN_TYPE (peek_right) == DB_TYPE_BLOB)
{
DB_VALUE tval;

db_make_null (&tval);
dom_status = tp_value_cast (peek_right, &tval, &tp_VarBit_domain, false);
if (dom_status != DOMAIN_COMPATIBLE)
{
(void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, peek_right, &tp_VarBit_domain);
db_value_clear (&tval);
goto error;
}

db_make_int (arithptr->value, db_get_string_size (&tval));
db_value_clear (&tval);
}
else if (!TP_IS_STRING_TYPE (DB_VALUE_TYPE (peek_right)))
{
DB_VALUE tval;

db_make_null (&tval);
dom_status = tp_value_cast (peek_right, &tval, &tp_Char_domain, false);
if (dom_status != DOMAIN_COMPATIBLE)
{
(void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, peek_right, &tp_Char_domain);
ctshim marked this conversation as resolved.
Show resolved Hide resolved
db_value_clear (&tval);
goto error;
}
db_make_int (arithptr->value, db_get_string_size (&tval));
db_value_clear (&tval);
}
else
{
db_make_int (arithptr->value, db_get_string_size (peek_right));
Expand All @@ -1228,6 +1258,39 @@ fetch_peek_arith (THREAD_ENTRY * thread_p, REGU_VARIABLE * regu_var, val_descr *
db_get_bit (peek_right, &len);
db_make_int (arithptr->value, len);
}
else if (DB_VALUE_DOMAIN_TYPE (peek_right) == DB_TYPE_BLOB)
{
DB_VALUE tval;
int len = 0;

db_make_null (&tval);
dom_status = tp_value_cast (peek_right, &tval, &tp_VarBit_domain, false);
if (dom_status != DOMAIN_COMPATIBLE)
{
(void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, peek_right, &tp_VarBit_domain);
db_value_clear (&tval);
goto error;
}

db_get_bit (&tval, &len);
db_make_int (arithptr->value, len);
db_value_clear (&tval);
}
else if (!TP_IS_CHAR_TYPE (DB_VALUE_TYPE (peek_right)))
{
DB_VALUE tval;

db_make_null (&tval);
dom_status = tp_value_cast (peek_right, &tval, &tp_Char_domain, false);
if (dom_status != DOMAIN_COMPATIBLE)
{
(void) tp_domain_status_er_set (dom_status, ARG_FILE_LINE, peek_right, &tp_Char_domain);
db_value_clear (&tval);
goto error;
ctshim marked this conversation as resolved.
Show resolved Hide resolved
}
db_make_int (arithptr->value, 8 * db_get_string_size (&tval));
db_value_clear (&tval);
}
else
{
/* must be a char string type */
Expand Down
26 changes: 24 additions & 2 deletions src/query/string_opfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -26659,6 +26659,7 @@ db_hex (const DB_VALUE * param, DB_VALUE * result)
const char *str = NULL;
char *hexval = NULL;
int str_size = 0, hexval_len = 0, i = 0, error_code = NO_ERROR;
DB_VALUE tval, *ptval = NULL;

/* check parameters for NULL values */
if (param == NULL || result == NULL)
Expand All @@ -26676,6 +26677,7 @@ db_hex (const DB_VALUE * param, DB_VALUE * result)
/* compute hex representation */
param_type = DB_VALUE_DOMAIN_TYPE (param);

coerce_pos:
if (TP_IS_CHAR_TYPE (param_type) || TP_IS_BIT_TYPE (param_type))
{
if (TP_IS_CHAR_TYPE (param_type))
Expand Down Expand Up @@ -26776,14 +26778,34 @@ db_hex (const DB_VALUE * param, DB_VALUE * result)
}
else
{
error_code = ER_QSTR_INVALID_DATA_TYPE;
goto error;
db_make_null (&tval);
ptval = &tval;
if (tp_value_cast (param, &tval, &tp_Char_domain, false) != DOMAIN_COMPATIBLE)
{
error_code = ER_QSTR_INVALID_DATA_TYPE;
goto error;
}

param = &tval;
ctshim marked this conversation as resolved.
Show resolved Hide resolved
param_type = DB_VALUE_DOMAIN_TYPE (param);
assert (TP_IS_CHAR_TYPE (param_type));
goto coerce_pos;
}

if (ptval)
{
db_value_clear (ptval);
}

/* all ok */
return NO_ERROR;

error:
if (ptval)
{
db_value_clear (ptval);
}

if (result)
{
db_make_null (result);
Expand Down
Loading