diff --git a/contrib/mppdb_decoding/mppdb_decoding.cpp b/contrib/mppdb_decoding/mppdb_decoding.cpp index f28a909fd49d4c8953ee2748013be52836860752..61d692f208f366a99d8d2f1e39dbc6752187e255 100755 --- a/contrib/mppdb_decoding/mppdb_decoding.cpp +++ b/contrib/mppdb_decoding/mppdb_decoding.cpp @@ -241,6 +241,7 @@ static void print_literal(StringInfo s, Oid typid, char* outputstr) const char* valptr = NULL; switch (typid) { + case INT1OID: case INT2OID: case INT4OID: case INT8OID: @@ -366,6 +367,7 @@ static void pg_decode_change( MemoryContext old; char* res = NULL; data = (TestDecodingData*)ctx->output_plugin_private; + u_sess->attr.attr_common.extra_float_digits = 0; /* output BEGIN if we haven't yet */ if (data->skip_empty_xacts && !data->xact_wrote_changes) { diff --git a/contrib/test_decoding/test_decoding.cpp b/contrib/test_decoding/test_decoding.cpp index b341453c26002fe0677c385c60a5b94e559cbeb0..10372f7c160abf1ed6eb546cad2f6c51158870ff 100644 --- a/contrib/test_decoding/test_decoding.cpp +++ b/contrib/test_decoding/test_decoding.cpp @@ -224,6 +224,7 @@ static void print_literal(StringInfo s, Oid typid, char* outputstr) const char* valptr = NULL; switch (typid) { + case INT1OID: case INT2OID: case INT4OID: case INT8OID: @@ -351,6 +352,7 @@ static void pg_decode_change( MemoryContext old; data = (TestDecodingData*)ctx->output_plugin_private; + u_sess->attr.attr_common.extra_float_digits = 0; /* output BEGIN if we haven't yet */ if (data->skip_empty_xacts && !data->xact_wrote_changes) { diff --git a/src/gausskernel/storage/replication/walsender.cpp b/src/gausskernel/storage/replication/walsender.cpp index ed3ba47a58d3d9a701f1a1a5bfac28297f0927fd..3545b69c160d18e4ac0d61a6042aef57a0651b4c 100755 --- a/src/gausskernel/storage/replication/walsender.cpp +++ b/src/gausskernel/storage/replication/walsender.cpp @@ -1617,6 +1617,58 @@ bool cmdStringCheck(const char* cmd_string) return false; } +/* + * Check cmdString length. + */ +static bool cmdStringLengthCheck(const char* cmd_string) +{ + const size_t cmd_length_limit = 200; + const size_t slotname_limit = 64; + char comd[cmd_length_limit] = {'\0'}; + char* sub_cmd = NULL; + char* rm_cmd = NULL; + char* slot_name = NULL; + + size_t cmd_length = strlen(cmd_string); + if (cmd_length == 0) { + return true; + } + if (cmd_length >= cmd_length_limit) { + return false; + } + errno_t ret = memset_s(comd, cmd_length_limit, 0, cmd_length_limit); + securec_check_c(ret, "\0", "\0"); + ret = strncpy_s(comd, cmd_length_limit, cmd_string, cmd_length); + securec_check_c(ret, "\0", "\0"); + + if (cmd_length > strlen("START_REPLICATION") && + strncmp(cmd_string, "START_REPLICATION", strlen("START_REPLICATION")) == 0) { + sub_cmd = strtok_r(comd, " ", &rm_cmd); + sub_cmd = strtok_r(NULL, " ", &rm_cmd); + if (strlen(sub_cmd) != strlen("SLOT") || + strncmp(sub_cmd, "SLOT", strlen("SLOT")) != 0) { + return true; + } else { + slot_name = strtok_r(NULL, " ", &rm_cmd); + } + } else if (cmd_length > strlen("CREATE_REPLICATION_SLOT") && + strncmp(cmd_string, "CREATE_REPLICATION_SLOT", strlen("CREATE_REPLICATION_SLOT")) == 0) { + sub_cmd = strtok_r(comd, " ", &rm_cmd); + slot_name = strtok_r(NULL, " ", &rm_cmd); + } else if (cmd_length > strlen("DROP_REPLICATION_SLOT") && + strncmp(cmd_string, "DROP_REPLICATION_SLOT", strlen("DROP_REPLICATION_SLOT")) == 0) { + sub_cmd = strtok_r(comd, " ", &rm_cmd); + slot_name = strtok_r(NULL, " ", &rm_cmd); + } else { + return true; + } + + if (strlen(slot_name) >= slotname_limit) { + return false; + } + return true; +} + /* * Execute an incoming replication command. */ @@ -1642,6 +1694,11 @@ static bool HandleWalReplicationCommand(const char* cmd_string) (errmsg_internal("replication command, syntax error.")))); } + if (cmdStringLengthCheck(cmd_string) == false) { + ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), + (errmsg_internal("replication slot name should be shorter than %d.", NAMEDATALEN)))); + } + cmd_context = AllocSetContextCreate(CurrentMemoryContext, "Replication command context", ALLOCSET_DEFAULT_MINSIZE,