fix dolphin back-quote bug
This commit is contained in:
committed by
zhang_xubo
parent
02a2071a65
commit
e7506870c7
@ -161,7 +161,6 @@ static void setup_formatted_log_time(void);
|
||||
static void setup_formatted_start_time(void);
|
||||
extern void send_only_message_to_frontend(const char* message, bool is_putline);
|
||||
static char* mask_Password_internal(const char* query_string);
|
||||
static char* mask_error_password(const char* query_string, int str_len);
|
||||
static void truncate_identified_by(char* query_string, int query_len);
|
||||
static char* mask_execute_direct_cmd(const char* query_string);
|
||||
static bool is_execute_cmd(const char* query_string);
|
||||
@ -3021,7 +3020,11 @@ static void send_message_to_server_log(ErrorData* edata)
|
||||
char* randomPlanInfo = NULL;
|
||||
char* mask_string = NULL;
|
||||
mask_string = maskPassword(t_thrd.postgres_cxt.debug_query_string);
|
||||
if (edata->sqlerrcode == ERRCODE_SYNTAX_ERROR) {
|
||||
/*
|
||||
* For B-compatible database with dolphin, there're some scenarios that
|
||||
* maskPassword couldn't cover.
|
||||
*/
|
||||
if (edata->sqlerrcode == ERRCODE_SYNTAX_ERROR || u_sess->attr.attr_sql.dolphin) {
|
||||
if (mask_string != NULL) {
|
||||
truncate_identified_by(mask_string, strlen(mask_string));
|
||||
} else {
|
||||
@ -4016,6 +4019,8 @@ static char* mask_word(char* query_string, int query_len, const char* word, int
|
||||
char* lower_string = (char*)palloc0(query_len + 1);
|
||||
rc = memcpy_s(lower_string, query_len, query_string, query_len);
|
||||
securec_check(rc, "\0", "\0");
|
||||
bool truncate = false;
|
||||
int set_password_len = 0;
|
||||
|
||||
tolower_func(lower_string);
|
||||
|
||||
@ -4037,16 +4042,30 @@ static char* mask_word(char* query_string, int query_len, const char* word, int
|
||||
}
|
||||
token_len++;
|
||||
}
|
||||
|
||||
/* set password for user=password */
|
||||
if (strncmp(token_ptr, "for", token_len) == 0) {
|
||||
token_ptr += token_len;
|
||||
set_password_len = token_len + 1;
|
||||
for (int i = 0; i < query_len - head_len - token_len; i++) {
|
||||
if (token_ptr[i] == '=') {
|
||||
truncate = true;
|
||||
break;
|
||||
}
|
||||
set_password_len++;
|
||||
}
|
||||
}
|
||||
tail_ptr = token_ptr + token_len;
|
||||
tail_len = query_len - head_len - token_len;
|
||||
|
||||
rc = memcpy_s(mask_string, query_len + mask_len + 1, query_string, head_len);
|
||||
rc = memcpy_s(mask_string, query_len + mask_len + 1, query_string, head_len + set_password_len);
|
||||
securec_check(rc, "\0", "\0");
|
||||
rc = memset_s(mask_string + head_len, query_len + mask_len + 1 - head_len, '*', mask_len);
|
||||
rc = memset_s(mask_string + head_len + set_password_len, query_len + mask_len + 1 - head_len - set_password_len,
|
||||
'*', mask_len);
|
||||
securec_check(rc, "\0", "\0");
|
||||
bool is_identified_by = ((strstr(word, " identified by ") == NULL) ? false : true);
|
||||
if (is_identified_by) {
|
||||
mask_string[head_len + mask_len] = '\0';
|
||||
truncate = truncate || ((strstr(word, " identified by ") == NULL) ? false : true);
|
||||
if (truncate) {
|
||||
mask_string[head_len + mask_len + set_password_len] = '\0';
|
||||
} else {
|
||||
rc = memcpy_s(mask_string + head_len + mask_len, query_len + 1 - head_len, tail_ptr, tail_len);
|
||||
securec_check(rc, "\0", "\0");
|
||||
@ -4091,7 +4110,7 @@ static void truncate_identified_by(char* query_string, int query_len)
|
||||
pfree_ext(lower_string);
|
||||
}
|
||||
|
||||
static char* mask_error_password(const char* query_string, int str_len)
|
||||
char* mask_error_password(const char* query_string, int str_len)
|
||||
{
|
||||
char* mask_string = NULL;
|
||||
errno_t rc = EOK;
|
||||
@ -4664,7 +4683,7 @@ static char* mask_Password_internal(const char* query_string)
|
||||
idx = 0;
|
||||
break;
|
||||
case REPLACE:
|
||||
isPassword = (curStmtType == 3 || curStmtType == 4 || curStmtType == 17);
|
||||
isPassword = (curStmtType == 3 || curStmtType == 4);
|
||||
if (isPassword)
|
||||
idx = 0;
|
||||
break;
|
||||
|
||||
@ -942,6 +942,7 @@ void UniqueSql::fill_in_constant_lengths(pgssJumbleState* jstate, const char* qu
|
||||
/* initialize the flex scanner --- should match raw_parser() */
|
||||
yyscanner = scanner_init(query, &yyextra, &ScanKeywords, ScanKeywordTokens);
|
||||
|
||||
void* coreYYlex = u_sess->hook_cxt.coreYYlexHook ? u_sess->hook_cxt.coreYYlexHook : (void*)core_yylex;
|
||||
/* Search for each constant, in sequence */
|
||||
for (i = 0; i < jstate->clocations_count; i++) {
|
||||
int loc = locs[i].location;
|
||||
@ -954,7 +955,7 @@ void UniqueSql::fill_in_constant_lengths(pgssJumbleState* jstate, const char* qu
|
||||
}
|
||||
/* Lex tokens until we find the desired constant */
|
||||
for (;;) {
|
||||
tok = core_yylex(&yylval, &yylloc, yyscanner);
|
||||
tok = ((coreYYlexFunc)coreYYlex)(&yylval, &yylloc, yyscanner);
|
||||
/* We should not hit end-of-string, but if we do, behave sanely */
|
||||
if (tok == 0) {
|
||||
break; /* out of inner for-loop */
|
||||
@ -977,7 +978,7 @@ void UniqueSql::fill_in_constant_lengths(pgssJumbleState* jstate, const char* qu
|
||||
* where bar = 1" and "select * from foo where bar = -2"
|
||||
* will have identical normalized query strings.
|
||||
*/
|
||||
tok = core_yylex(&yylval, &yylloc, yyscanner);
|
||||
tok = ((coreYYlexFunc)coreYYlex)(&yylval, &yylloc, yyscanner);
|
||||
if (tok == 0) {
|
||||
break; /* out of inner for-loop */
|
||||
}
|
||||
|
||||
@ -373,7 +373,11 @@ static void pgaudit_ddl_database_object(
|
||||
Assert(cmdtext != NULL);
|
||||
char* mask_string = maskPassword(cmdtext);
|
||||
if (mask_string == NULL) {
|
||||
mask_string = (char*)cmdtext;
|
||||
if (u_sess->attr.attr_sql.dolphin) {
|
||||
mask_string = mask_error_password(cmdtext, strlen(cmdtext));
|
||||
} else {
|
||||
mask_string = (char*)cmdtext;
|
||||
}
|
||||
}
|
||||
|
||||
switch (audit_type) {
|
||||
|
||||
@ -2736,6 +2736,7 @@ typedef struct knl_u_hook_context {
|
||||
void *pluginSearchCatHook;
|
||||
void *pluginCCHashEqFuncs;
|
||||
void *plpgsqlParserSetHook;
|
||||
void *coreYYlexHook;
|
||||
} knl_u_hook_context;
|
||||
|
||||
typedef struct knl_u_libsw_context {
|
||||
|
||||
@ -162,5 +162,7 @@ extern int scanner_errposition(int location, core_yyscan_t yyscanner);
|
||||
extern void scanner_yyerror(const char* message, core_yyscan_t yyscanner);
|
||||
extern void addErrorList(const char* message, int lines);
|
||||
|
||||
typedef int (*coreYYlexFunc)(core_YYSTYPE* lvalp, YYLTYPE* llocp, core_yyscan_t yyscanner);
|
||||
|
||||
#endif /* SCANNER_H */
|
||||
|
||||
|
||||
@ -158,6 +158,7 @@ extern int errcode_for_socket_access(void);
|
||||
extern int errmodule(ModuleId id);
|
||||
extern const char* mask_encrypted_key(const char* query_string, int str_len);
|
||||
extern char* maskPassword(const char* query_string);
|
||||
extern char* mask_error_password(const char* query_string, int str_len);
|
||||
|
||||
#define MASK_PASSWORD_START(mask_string, query_string) \
|
||||
do { \
|
||||
|
||||
@ -93,7 +93,7 @@ class Pterodb():
|
||||
def __modify_conf_port(self, conf_file, port):
|
||||
file_handler = open(conf_file,"a")
|
||||
|
||||
string = "port = " + str(port) + "\n"
|
||||
string = "\n" + "port = " + str(port) + "\n"
|
||||
file_handler.write(string)
|
||||
|
||||
file_handler.close()
|
||||
|
||||
Reference in New Issue
Block a user