From 2e1b94ff87567ddd2c80b71e99eaf96a8fdc87de Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Tue, 10 Dec 2024 11:33:03 +0800 Subject: [PATCH] Fix review errors. --- docs/en/14-reference/09-error-code.md | 2 ++ docs/zh/14-reference/09-error-code.md | 1 + include/util/taoserror.h | 1 + source/common/src/msg/tmsg.c | 3 +++ source/common/src/tglobal.c | 39 +++++++++++++++++++++------ source/util/src/terror.c | 1 + 6 files changed, 39 insertions(+), 8 deletions(-) diff --git a/docs/en/14-reference/09-error-code.md b/docs/en/14-reference/09-error-code.md index 46f8687843..bf211156ef 100644 --- a/docs/en/14-reference/09-error-code.md +++ b/docs/en/14-reference/09-error-code.md @@ -72,6 +72,8 @@ This document details the server error codes that may be encountered when using | 0x80000133 | Invalid operation | Invalid or unsupported operation | 1. Modify to confirm the current operation is legal and supported, check parameter validity 2. If the problem persists, preserve the scene and logs, report issue on github | | 0x80000134 | Invalid value | Invalid value | Preserve the scene and logs, report issue on github | | 0x80000135 | Invalid fqdn | Invalid FQDN | Check if the configured or input FQDN value is correct | +| 0x8000013C | Invalid disk id | Invalid disk id | Check users whether the mounted disk is invalid or use the parameter diskIDCheckEnabled to skip the disk check. | + ## tsc diff --git a/docs/zh/14-reference/09-error-code.md b/docs/zh/14-reference/09-error-code.md index 4bd495129e..72d4897763 100644 --- a/docs/zh/14-reference/09-error-code.md +++ b/docs/zh/14-reference/09-error-code.md @@ -75,6 +75,7 @@ description: TDengine 服务端的错误码列表和详细说明 | 0x80000133 | Invalid operation | 无效的或不支持的操作 | 1. 修改确认当前操作为合法有效支持的操作,检查参数有效性 2. 如果问题还未解决,保留现场和日志,github上报issue | | 0x80000134 | Invalid value | 无效值 | 保留现场和日志,github上报issue | | 0x80000135 | Invalid fqdn | 无效FQDN | 检查配置或输入的FQDN值是否正确 | +| 0x8000013C | Invalid disk id | 不合法的disk id | 建议用户检查挂载磁盘是否失效或者使用参数 diskIDCheckEnabled 来跳过磁盘检查 | diff --git a/include/util/taoserror.h b/include/util/taoserror.h index a01bbf66a6..ca349425d2 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -159,6 +159,7 @@ int32_t taosGetErrSize(); #define TSDB_CODE_SOCKET_ERROR TAOS_DEF_ERROR_CODE(0, 0x0139) #define TSDB_CODE_UNSUPPORT_OS TAOS_DEF_ERROR_CODE(0, 0x013A) #define TSDB_CODE_TIME_ERROR TAOS_DEF_ERROR_CODE(0, 0x013B) +#define TSDB_CODE_INVALID_DISK_ID TAOS_DEF_ERROR_CODE(0, 0x013C) //client #define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200) diff --git a/source/common/src/msg/tmsg.c b/source/common/src/msg/tmsg.c index aa53b4a022..deb1cbf843 100644 --- a/source/common/src/msg/tmsg.c +++ b/source/common/src/msg/tmsg.c @@ -1636,6 +1636,9 @@ int32_t tDeserializeSConfigReq(void *buf, int32_t bufLen, SConfigReq *pReq) { TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pReq->forceReadConfig)); if (pReq->forceReadConfig) { pReq->array = taosArrayInit(128, sizeof(SConfigItem)); + if (pReq->array == NULL) { + TAOS_CHECK_EXIT(terrno); + } TAOS_CHECK_EXIT(tDeserializeSConfigArray(&decoder, pReq->array)); } tEndDecode(&decoder); diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 0c5c762bcd..cefdb1b544 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -1947,6 +1947,8 @@ _exit: } int32_t cfgDeserialize(SArray *array, char *buf, bool isGlobal) { + int32_t code = TSDB_CODE_SUCCESS; + cJSON *pRoot = cJSON_Parse(buf); if (pRoot == NULL) { return TSDB_CODE_OUT_OF_MEMORY; @@ -1954,8 +1956,8 @@ int32_t cfgDeserialize(SArray *array, char *buf, bool isGlobal) { if (isGlobal) { cJSON *pItem = cJSON_GetObjectItem(pRoot, "version"); if (pItem == NULL) { - cJSON_Delete(pRoot); - return TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; } tsdmConfigVersion = pItem->valueint; } @@ -1963,9 +1965,8 @@ int32_t cfgDeserialize(SArray *array, char *buf, bool isGlobal) { int32_t sz = taosArrayGetSize(array); cJSON *configs = cJSON_GetObjectItem(pRoot, "configs"); if (configs == NULL) { - uError("failed to get configs from json, since %s", cJSON_GetErrorPtr()); - cJSON_Delete(pRoot); - return TSDB_CODE_OUT_OF_MEMORY; + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; } for (int i = 0; i < sz; i++) { SConfigItem *pItem = (SConfigItem *)taosArrayGet(array, i); @@ -1982,15 +1983,31 @@ int32_t cfgDeserialize(SArray *array, char *buf, bool isGlobal) { // check disk id for each dir for (int j = 0; j < sz; j++) { cJSON *diskCfgJson = cJSON_GetArrayItem(pJson, j); + if (diskCfgJson == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + filed = cJSON_GetObjectItem(diskCfgJson, "dir"); + if (filed == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + char *dir = cJSON_GetStringValue(filed); filed = cJSON_GetObjectItem(diskCfgJson, "disk_id"); + if (filed == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _exit; + } + int64_t actDiskID = 0; - int64_t expDiskID = atoll(cJSON_GetStringValue(filed)); + int64_t expDiskID = taosStr2Int64(cJSON_GetStringValue(filed), NULL, 10); if (!taosCheckFileDiskID(dir, &actDiskID, expDiskID)) { uError("failed to check disk id for dir:%s, actDiskID%" PRId64 ", expDiskID%" PRId64, dir, actDiskID, expDiskID); - return TSDB_CODE_FAILED; + code = TSDB_CODE_INVALID_DISK_ID; + goto _exit; } } continue; @@ -2020,13 +2037,19 @@ int32_t cfgDeserialize(SArray *array, char *buf, bool isGlobal) { case CFG_DTYPE_TIMEZONE: taosMemoryFree(pItem->str); pItem->str = taosStrdup(pJson->valuestring); + if (pItem->str == NULL) { + code = terrno; + } break; } } } _exit: + if (code != TSDB_CODE_SUCCESS) { + uError("failed to deserialize config since %s", tstrerror(code)); + } cJSON_Delete(pRoot); - return TSDB_CODE_SUCCESS; + return code; } int32_t readCfgFile(const char *path, bool isGlobal) { diff --git a/source/util/src/terror.c b/source/util/src/terror.c index d2be62f56a..f1cb8fcb0b 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -118,6 +118,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MSG_PREPROCESSED, "Message has been proc TAOS_DEFINE_ERROR(TSDB_CODE_OUT_OF_BUFFER, "Out of buffer") TAOS_DEFINE_ERROR(TSDB_CODE_INTERNAL_ERROR, "Internal error") TAOS_DEFINE_ERROR(TSDB_CODE_TIME_ERROR, "Internal error in time") +TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_DISK_ID, "Internal error invalid disk id") //client TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_OPERATION, "Invalid operation")