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-25762] When a general user performs a trigger unload, remove [user_schema] from condition and action_definition if the owner is the user themselves. #5731

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
86 changes: 84 additions & 2 deletions src/object/trigger_description.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ tr_dump_trigger (extract_context &ctxt, print_output &output_ctx, DB_OBJECT *tri
char owner_name[DB_MAX_USER_LENGTH] = { '\0' };
const char *trigger_name = NULL;
const char *class_name = NULL;
PARSER_CONTEXT *parser;
PT_NODE **action_node = nullptr, **condition_node = nullptr;
char *query_action_result, *query_condition_result;

AU_DISABLE (save);

Expand Down Expand Up @@ -314,7 +317,65 @@ tr_dump_trigger (extract_context &ctxt, print_output &output_ctx, DB_OBJECT *tri

if (trigger->condition != NULL)
{
output_ctx ("IF %s\n", trigger->condition->source);
char *text;
int length;
const char *eval_prefix = "EVALUATE ( ";
const char *eval_suffix = " ) ";
Comment on lines +322 to +323

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trigger_manager.c 에 EVAL_PREFIX 와 EVAL_SUFFIX 가 static const char 로 선언되어 있는데, 이것을 활용할 수 있도록 수정하는 것이 더 좋을 거 같습니다.

https://github.com/jongmin-won/cubrid/blob/be32f5eab076f699c955defe8db2da98a13462e9/src/object/trigger_manager.c#L128-L129

char *p = NULL;
const char *remove_eval_prefix = "evaluate (";
size_t remove_eval_suffix_len;

length = strlen (eval_prefix) + strlen (trigger->condition->source) + strlen (eval_suffix) + 1;
text = (char *) malloc (length);
if (text == NULL)
{
output_ctx ("/* ERROR : IF %s */\n", trigger->condition->source);
error = ER_OUT_OF_VIRTUAL_MEMORY;
er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, (size_t) length);
free_and_init (text);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
free_and_init (text);

text == NULL 이기 때문에 free_and_init 을 하지 않아도 될 것 같습니다.

return error;
}
strcpy (text, eval_prefix);
strcat (text, trigger->condition->source);
strcat (text, eval_suffix);

parser = parser_create_parser ();
if (parser == NULL)
{
output_ctx ("/* ERROR : IF %s */\n", trigger->condition->source);
}
Comment on lines +342 to +346

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래 로직에서 parser 에 접근하기 때문에, parser == NULL 이면 함수를 종료해야 할 필요가 있어 보입니다.


if (ctxt.is_dba_user == false && ctxt.is_dba_group_member == false)
{
parser->custom_print |= PT_PRINT_NO_CURRENT_USER_NAME;
}

condition_node = parser_parse_string (parser, text);
if (condition_node != NULL)
{
query_condition_result = parser_print_tree_with_quotes (parser, *condition_node);

/* remove appended trigger evaluate info */
p = strstr (query_condition_result, remove_eval_prefix);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p == NULL 을 처리해야 할 필요가 있어 보입니다.

if (p != NULL)
{
p = (char *) memmove (p, p + strlen (remove_eval_prefix), strlen (p) - strlen (remove_eval_prefix) + 1);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else 구문으로 P가 NULL인 경우에 대한 처리가 필요합니다.


remove_eval_suffix_len = strlen (p);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

362라인이 잘 수행된 후에는
remove_eval_suffix_len는 strlen (p) - strlen (remove_eval_prefix) 와 같아야겠지요?

if (remove_eval_suffix_len > 0 && p[remove_eval_suffix_len - 1] == ')')
{
p[remove_eval_suffix_len - 1] = '\0';
}
Comment on lines +366 to +369
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. remove_eval_prefix로 시작했는데 끝에 ')'가 오지 않는 경우가 있을 수 있나요?

  2. " ... ) " 와 같이 ')' 이후에 공백 문자가 포함되어 있을 가능성은 없나요?


output_ctx ("IF %s\n", query_condition_result);
}
else
{
output_ctx ("/* ERROR : IF %s */\n", trigger->condition->source);
}
parser_free_parser (parser);
free_and_init (text);
}

if (trigger->action != NULL)
Expand All @@ -327,7 +388,28 @@ tr_dump_trigger (extract_context &ctxt, print_output &output_ctx, DB_OBJECT *tri
switch (trigger->action->type)
{
case TR_ACT_EXPRESSION:
output_ctx ("%s", trigger->action->source);
parser = parser_create_parser ();
if (parser == NULL)
{
output_ctx ("\n/* ERROR : EXECUTE %s */\n", trigger->action->source);
}
Comment on lines +392 to +395

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래 로직에서 parser 에 접근하기 때문에, parser == NULL 이면 함수를 종료해야 할 필요가 있어 보입니다.


if (ctxt.is_dba_user == false && ctxt.is_dba_group_member == false)
{
parser->custom_print |= PT_PRINT_NO_CURRENT_USER_NAME;
}

action_node = parser_parse_string (parser, trigger->action->source);
if (action_node != NULL)
{
query_action_result = parser_print_tree_with_quotes (parser, *action_node);
output_ctx ("%s", query_action_result);
}
else
{
output_ctx ("\n/* ERROR : EXECUTE %s */\n", trigger->action->source);
}
parser_free_parser (parser);
break;
case TR_ACT_REJECT:
output_ctx ("REJECT");
Expand Down
Loading