From 260430f25e56c2fe41324e12a669b2aa0acd1853 Mon Sep 17 00:00:00 2001 From: chenzhikai <895543892@qq.com> Date: Sat, 14 Sep 2024 16:20:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E9=83=A8=E5=88=86=E5=86=85?= =?UTF-8?q?=E5=AD=98=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/pg_rewind/parsexlog.cpp | 3 ++- src/common/backend/utils/error/fatal_err.cpp | 5 +++++ src/common/port/gs_thread.cpp | 3 ++- .../keymgr/localkms/security_file_enc.cpp | 17 ++++++++++++++--- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/bin/pg_rewind/parsexlog.cpp b/src/bin/pg_rewind/parsexlog.cpp index 97dc64dd8..f53205174 100644 --- a/src/bin/pg_rewind/parsexlog.cpp +++ b/src/bin/pg_rewind/parsexlog.cpp @@ -732,9 +732,10 @@ bool CheckIfEanbedSaveSlots() securec_check_c(ret, "", ""); if ((strcmp(optvalue, "1") == 0) || (strcmp(optvalue, "true") == 0) || (strcmp(optvalue, "on") == 0)) { pg_log(PG_PROGRESS, _("Enable saving confirmed_lsn in target %s\n"), config_file); + freefile(optlines); return true; } } - + freefile(optlines); return false; } diff --git a/src/common/backend/utils/error/fatal_err.cpp b/src/common/backend/utils/error/fatal_err.cpp index f7b74cafe..f491b1ce2 100644 --- a/src/common/backend/utils/error/fatal_err.cpp +++ b/src/common/backend/utils/error/fatal_err.cpp @@ -303,6 +303,11 @@ static void print_top_stack(int fd, uintptr_t sp) { output(fd, "====== Top of stack ======\nsp = 0x016%lx\n", sp); + if (sp == 0) { + output(fd, "Invalid stack pointer\n"); + return; + } + uint64 *start = (uint64 *)sp; uint64 *end = start + 64; diff --git a/src/common/port/gs_thread.cpp b/src/common/port/gs_thread.cpp index 225373b46..c5c495403 100644 --- a/src/common/port/gs_thread.cpp +++ b/src/common/port/gs_thread.cpp @@ -758,7 +758,6 @@ int gs_thread_create_ex(gs_thread_t* th, void* (*taskRoutine)(void*), int argc, int error_code = 0; bool needFree = false; - pArg = (ThreadArg*)argv; if (argv == NULL) { /* * just special thread which not exit at gaussdb runtime, so the pArg no need to free. for example: signal @@ -778,6 +777,8 @@ int gs_thread_create_ex(gs_thread_t* th, void* (*taskRoutine)(void*), int argc, */ pArg->next = (struct ThreadArg*)INVALID_NEXT_ADDR; needFree = true; + } else { + pArg = (ThreadArg*)argv; } pArg->m_taskRoutine = taskRoutine; diff --git a/src/gausskernel/security/keymgr/localkms/security_file_enc.cpp b/src/gausskernel/security/keymgr/localkms/security_file_enc.cpp index 2978504ff..6af452596 100644 --- a/src/gausskernel/security/keymgr/localkms/security_file_enc.cpp +++ b/src/gausskernel/security/keymgr/localkms/security_file_enc.cpp @@ -146,6 +146,7 @@ static CmkemErrCode create_file_and_write(const char *real_path, const unsigned int fd = 0; char head[KEY_FILE_HEADER_LEN] = {0}; errno_t rc = 0; + ssize_t written = 0; fd = open(real_path, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if (fd == -1) { @@ -156,12 +157,22 @@ static CmkemErrCode create_file_and_write(const char *real_path, const unsigned if (is_write_header) { rc = sprintf_s(head, sizeof(head), "%lu", content_len); securec_check_ss_c(rc, "", ""); - write(fd, head, sizeof(head)); + written = write(fd, head, sizeof(head)); + if (written != sizeof(head)) { + cmkem_errmsg("failed to write header to file '%s'.\n", real_path); + (void)close(fd); + return CMKEM_WRITE_FILE_ERR; + } } - write(fd, content, content_len); - close(fd); + written = write(fd, content, content_len); + if (written != content_len) { + cmkem_errmsg("failed to write content to file '%s'.\n", real_path); + (void)close(fd); + return CMKEM_WRITE_FILE_ERR; + } + (void)close(fd); return CMKEM_SUCCEED; }