fix: real path optimization in case of invalid read

This commit is contained in:
kailixu 2022-11-17 10:56:24 +08:00
parent a186cc4491
commit 6515c9c7c5
2 changed files with 8 additions and 6 deletions

View File

@ -49,7 +49,7 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKee
pTsdb->path = (char *)&pTsdb[1]; pTsdb->path = (char *)&pTsdb[1];
snprintf(pTsdb->path, TD_PATH_MAX, "%s%s%s", pVnode->path, TD_DIRSEP, dir); 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; pTsdb->pVnode = pVnode;
taosThreadRwlockInit(&pTsdb->rwLock, NULL); taosThreadRwlockInit(&pTsdb->rwLock, NULL);
if (!pKeepCfg) { if (!pKeepCfg) {

View File

@ -336,6 +336,7 @@ int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) {
#else #else
if (realpath(dirname, tmp) != NULL) { if (realpath(dirname, tmp) != NULL) {
#endif #endif
if (strlen(tmp) < maxlen) {
if (realPath == NULL) { if (realPath == NULL) {
strncpy(dirname, tmp, maxlen); strncpy(dirname, tmp, maxlen);
} else { } else {
@ -343,6 +344,7 @@ int32_t taosRealPath(char *dirname, char *realPath, int32_t maxlen) {
} }
return 0; return 0;
} }
}
return -1; return -1;
} }