From 6515c9c7c524e59556288dbfe527ecf68b5a0842 Mon Sep 17 00:00:00 2001 From: kailixu Date: Thu, 17 Nov 2022 10:56:24 +0800 Subject: [PATCH] fix: real path optimization in case of invalid read --- source/dnode/vnode/src/tsdb/tsdbOpen.c | 2 +- source/os/src/osDir.c | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbOpen.c b/source/dnode/vnode/src/tsdb/tsdbOpen.c index bb20a9b012..f71b5b6706 100644 --- a/source/dnode/vnode/src/tsdb/tsdbOpen.c +++ b/source/dnode/vnode/src/tsdb/tsdbOpen.c @@ -49,7 +49,7 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKee pTsdb->path = (char *)&pTsdb[1]; snprintf(pTsdb->path, TD_PATH_MAX, "%s%s%s", pVnode->path, TD_DIRSEP, dir); - taosRealPath(pTsdb->path, NULL, slen); + // taosRealPath(pTsdb->path, NULL, slen); pTsdb->pVnode = pVnode; taosThreadRwlockInit(&pTsdb->rwLock, NULL); if (!pKeepCfg) { diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index 5e85e40594..421901184b 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -336,12 +336,14 @@ int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) { #else if (realpath(dirname, tmp) != NULL) { #endif - if (realPath == NULL) { - strncpy(dirname, tmp, maxlen); - } else { - strncpy(realPath, tmp, maxlen); + if (strlen(tmp) < maxlen) { + if (realPath == NULL) { + strncpy(dirname, tmp, maxlen); + } else { + strncpy(realPath, tmp, maxlen); + } + return 0; } - return 0; } return -1; -- GitLab