diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 18ff2af067..1507cbf14d 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -1027,15 +1027,18 @@ static int32_t taosSetClientLogCfg(SConfig *pCfg) { if ((pEnd = strrchr(pLog, '/')) || (pEnd = strrchr(pLog, '\\'))) { int32_t pathLen = POINTER_DISTANCE(pEnd, pLog) + 1; if (*pLog == '/' || *pLog == '\\') { - tstrncpy(tsLogDir, pLog, TMIN(pathLen, PATH_MAX)); + if (pathLen >= PATH_MAX) TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE); + tstrncpy(tsLogDir, pLog, pathLen); } else { int32_t len = strlen(tsLogDir); if (tsLogDir[len - 1] != '/' && tsLogDir[len - 1] != '\\') { tsLogDir[len++] = TD_DIRSEP_CHAR; } - tstrncpy(tsLogDir + len, pLog, TMIN(PATH_MAX - len - 1, pathLen)); + int32_t remain = PATH_MAX - len - 1; + if (remain < pathLen) TAOS_RETURN(TSDB_CODE_OUT_OF_RANGE); + tstrncpy(tsLogDir + len, pLog, pathLen); } - cfgSetItem(pCfg, "logDir", tsLogDir, CFG_STYPE_DEFAULT, true); + TAOS_CHECK_RETURN(cfgSetItem(pCfg, "logDir", tsLogDir, CFG_STYPE_DEFAULT, true)); } } } diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index 8ee0e74d4f..486215c335 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -292,11 +292,11 @@ int32_t taosStatFile(const char *path, int64_t *size, int64_t *mtime, int64_t *a } if (mtime != NULL) { - *mtime = fileStat.st_mtim.tv_sec; + *mtime = fileStat.st_mtime; } if (atime != NULL) { - *atime = fileStat.st_atim.tv_sec; + *atime = fileStat.st_atime; } return 0; @@ -960,7 +960,7 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int64_t *mtime) { } if (mtime != NULL) { - *mtime = fileStat.st_mtim.tv_sec; + *mtime = fileStat.st_mtime; } return 0;