From 3815fa851e671c31aba54dec6de404fede07459f Mon Sep 17 00:00:00 2001 From: liang Date: Mon, 28 Sep 2020 16:13:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=89=E5=85=A8=E5=87=BD=E6=95=B0=E6=95=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/pg_dump/pg_dump_sort.cpp | 5 +++-- src/bin/psql/tab-complete.cpp | 12 ++++++++---- src/common/backend/utils/adt/rowtypes.cpp | 16 ++++++++++------ src/gausskernel/storage/access/transam/xlog.cpp | 2 +- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/bin/pg_dump/pg_dump_sort.cpp b/src/bin/pg_dump/pg_dump_sort.cpp index 8825073eb..22e012237 100644 --- a/src/bin/pg_dump/pg_dump_sort.cpp +++ b/src/bin/pg_dump/pg_dump_sort.cpp @@ -1127,8 +1127,9 @@ static void describeDumpableObject(DumpableObject* obj, char* buf, int bufsize) securec_check_ss_c(nRet, "\0", "\0"); return; case DO_REFRESH_MATVIEW: - nRet = snprintf( - buf, bufsize, "REFRESH MATERIALIZED VIEW %s (ID %d OID %u)", obj->name, obj->dumpId, obj->catId.oid); + nRet = snprintf_s( + buf, bufsize, bufsize - 1, "REFRESH MATERIALIZED VIEW %s (ID %d OID %u)", + obj->name, obj->dumpId, obj->catId.oid); securec_check_ss_c(nRet, "\0", "\0"); return; case DO_RULE: diff --git a/src/bin/psql/tab-complete.cpp b/src/bin/psql/tab-complete.cpp index 5c5a2cea5..b1672fe98 100644 --- a/src/bin/psql/tab-complete.cpp +++ b/src/bin/psql/tab-complete.cpp @@ -937,9 +937,11 @@ static char **PsqlCompletion(const char *text, int start, int end) COMPLETE_WITH_LIST(listAlterAgg); } else { - char *tmpBuf = (char *)malloc(strlen(Query_for_list_of_arguments) + strlen(PREV2_WD)); + size_t tmpLength = strlen(Query_for_list_of_arguments) + strlen(PREV2_WD); + char *tmpBuf = (char *)pg_malloc(tmpLength); - sprintf(tmpBuf, Query_for_list_of_arguments, PREV2_WD); + int rc = sprintf_s(tmpBuf, tmpLength, Query_for_list_of_arguments, PREV2_WD); + securec_check_c(rc, "", ""); COMPLETE_WITH_QUERY(tmpBuf); free(tmpBuf); } @@ -1971,9 +1973,11 @@ static char **PsqlCompletion(const char *text, int start, int end) } else if (pg_strcasecmp(PREV4_WD, "DROP") == 0 && (pg_strcasecmp(PREV3_WD, "AGGREGATE") == 0 || pg_strcasecmp(PREV3_WD, "FUNCTION") == 0) && pg_strcasecmp(PREV_WD, "(") == 0) { - char *tmpBuf = (char *)malloc(strlen(Query_for_list_of_arguments) + strlen(PREV2_WD)); + size_t tmpLength = strlen(Query_for_list_of_arguments) + strlen(PREV2_WD); + char *tmpBuf = (char *)pg_malloc(tmpLength); - sprintf(tmpBuf, Query_for_list_of_arguments, PREV2_WD); + int rc = sprintf_s(tmpBuf, tmpLength, Query_for_list_of_arguments, PREV2_WD); + securec_check_c(rc,"",""); COMPLETE_WITH_QUERY(tmpBuf); free(tmpBuf); } diff --git a/src/common/backend/utils/adt/rowtypes.cpp b/src/common/backend/utils/adt/rowtypes.cpp index 9c1cc8881..8bb6b9f42 100755 --- a/src/common/backend/utils/adt/rowtypes.cpp +++ b/src/common/backend/utils/adt/rowtypes.cpp @@ -990,9 +990,9 @@ Datum record_eq(PG_FUNCTION_ARGS) if (my_extra->record1_type != tupType1 || my_extra->record1_typmod != tupTypmod1 || my_extra->record2_type != tupType2 || my_extra->record2_typmod != tupTypmod2) { - errno_t rc = EOK; - rc = memset_s(my_extra->columns, ncols * sizeof(ColumnCompareData), 0, ncols * sizeof(ColumnCompareData)); - securec_check(rc, "\0", "\0"); + errno_t rc = memset_s(my_extra->columns, ncols * sizeof(ColumnCompareData), 0, + ncols * sizeof(ColumnCompareData)); + securec_check(rc, "", ""); my_extra->record1_type = tupType1; my_extra->record1_typmod = tupTypmod1; my_extra->record2_type = tupType2; @@ -1226,7 +1226,9 @@ static int record_image_cmp(PG_FUNCTION_ARGS) if (my_extra->record1_type != tupType1 || my_extra->record1_typmod != tupTypmod1 || my_extra->record2_type != tupType2 || my_extra->record2_typmod != tupTypmod2) { - MemSet(my_extra->columns, 0, ncols * sizeof(ColumnCompareData)); + errno_t rc = memset_s(my_extra->columns, ncols * sizeof(ColumnCompareData), 0, + ncols * sizeof(ColumnCompareData)); + securec_check(rc, "", ""); my_extra->record1_type = tupType1; my_extra->record1_typmod = tupTypmod1; my_extra->record2_type = tupType2; @@ -1429,7 +1431,9 @@ Datum record_image_eq(PG_FUNCTION_ARGS) if (my_extra->record1_type != tupType1 || my_extra->record1_typmod != tupTypmod1 || my_extra->record2_type != tupType2 || my_extra->record2_typmod != tupTypmod2) { - MemSet(my_extra->columns, 0, ncols * sizeof(ColumnCompareData)); + errno_t rc = memset_s(my_extra->columns, ncols * sizeof(ColumnCompareData), 0, + ncols * sizeof(ColumnCompareData)); + securec_check(rc, "", ""); my_extra->record1_type = tupType1; my_extra->record1_typmod = tupTypmod1; my_extra->record2_type = tupType2; @@ -1593,7 +1597,7 @@ void record_set_extra(RecordIOData **my_extra, int ncolumns, Oid tupType, int32 errno_t rc = memset_s((*my_extra), sizeof(RecordIOData) - sizeof(ColumnIOData) + ncolumns * sizeof(ColumnIOData), 0, sizeof(RecordIOData) - sizeof(ColumnIOData) + ncolumns * sizeof(ColumnIOData)); - securec_check(rc, "\0", "\0"); + securec_check(rc, "", ""); (*my_extra)->record_type = tupType; (*my_extra)->record_typmod = tupTypmod; (*my_extra)->ncolumns = ncolumns; diff --git a/src/gausskernel/storage/access/transam/xlog.cpp b/src/gausskernel/storage/access/transam/xlog.cpp index 21bbcf746..2356fb666 100755 --- a/src/gausskernel/storage/access/transam/xlog.cpp +++ b/src/gausskernel/storage/access/transam/xlog.cpp @@ -13838,7 +13838,7 @@ static bool read_tablespace_map(List** tablespaces) while ((ch = fgetc(lfp)) != EOF) { if ((ch == '\n' || ch == '\r') && prevCh != '\\') { str[i] = '\0'; - if (sscanf(str, "%s %n", tbsoid, &n) != 1) + if (sscanf_s(str, "%s %n", tbsoid, MAXPGPATH, &n) != 1) ereport(FATAL, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("invalid data in file \"%s\"", TABLESPACE_MAP)));