From 51928e862a7fa202087cb8bfc5429886993d9e7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Sat, 3 Dec 2022 06:51:27 +0000 Subject: [PATCH 1/7] update interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../mod_fileio/class_dir/dir_n_exporter.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp index b94cfe121..5d0fad556 100644 --- a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp @@ -167,14 +167,20 @@ napi_value DirNExporter::Read(napi_env env, napi_callback_info info) } DIR *dir = dirEntity->dir_.get(); + int totalBuffSize = 0; auto arg = make_shared(NVal(env, funcArg.GetThisVar())); - auto cbExec = [arg, dir, dirEntity](napi_env env) -> UniError { + auto cbExec = [arg, dir, dirEntity, totalBuffSize](napi_env env) -> UniError { struct dirent tmpDirent; lock_guard(dirEntity->lock_); errno = 0; dirent *res = nullptr; do { res = readdir(dir); + totalBuffSize += sizeof(dirent); + if(totalBuffSize > MAX_DIR_BUFF) { + return NVal::CreateUndefined(env).val_; + } + if (res == nullptr && errno) { return UniError(errno); } else if (res == nullptr) { @@ -216,14 +222,20 @@ napi_value DirNExporter::ReadSync(napi_env env, napi_callback_info info) UniError(EBADF).ThrowErr(env, "Dir has been closed yet"); return nullptr; } - + DIR *dir = dirEntity->dir_.get(); + int totalBuffSize = 0; struct dirent tmpDirent; { lock_guard(dirEntity->lock_); errno = 0; dirent *res = nullptr; do { - res = readdir(dirEntity->dir_.get()); + res = readdir(dir); + totalBuffSize += sizeof(dirent); + if(totalBuffSize > MAX_DIR_BUFF) { + return NVal::CreateUndefined(env).val_; + } + if (res == nullptr && errno) { UniError(errno).ThrowErr(env); return nullptr; -- Gitee From 89310cd04da69d25a067e5c0b8baf280c9d6dec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Sat, 3 Dec 2022 06:52:02 +0000 Subject: [PATCH 2/7] update interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.h b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.h index a40ed03d2..ed84e127c 100644 --- a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.h +++ b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.h @@ -17,9 +17,10 @@ #define INTERFACES_KITS_JS_SRC_MOD_FILEIO_CLASS_DIR_DIR_N_EXPORTER_H #include - #include "../../common/napi/n_exporter.h" +#define MAX_DIR_BUFF 2048 + namespace OHOS { namespace DistributedFS { namespace ModuleFileIO { -- Gitee From fba1690bd92766a96f5d1d3fcc0da750d896fe4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Sat, 3 Dec 2022 07:15:24 +0000 Subject: [PATCH 3/7] update interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp index 5d0fad556..3a6cf5ef3 100644 --- a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp @@ -167,10 +167,10 @@ napi_value DirNExporter::Read(napi_env env, napi_callback_info info) } DIR *dir = dirEntity->dir_.get(); - int totalBuffSize = 0; auto arg = make_shared(NVal(env, funcArg.GetThisVar())); auto cbExec = [arg, dir, dirEntity, totalBuffSize](napi_env env) -> UniError { struct dirent tmpDirent; + int totalBuffSize = 0; lock_guard(dirEntity->lock_); errno = 0; dirent *res = nullptr; @@ -178,7 +178,7 @@ napi_value DirNExporter::Read(napi_env env, napi_callback_info info) res = readdir(dir); totalBuffSize += sizeof(dirent); if(totalBuffSize > MAX_DIR_BUFF) { - return NVal::CreateUndefined(env).val_; + return UniError(ERRNO_NOERR); } if (res == nullptr && errno) { -- Gitee From 34e7b400c08f45df9b3984361db914362e6ca2eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Sat, 3 Dec 2022 07:16:36 +0000 Subject: [PATCH 4/7] update interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp index 3a6cf5ef3..82fcb5544 100644 --- a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp @@ -168,7 +168,7 @@ napi_value DirNExporter::Read(napi_env env, napi_callback_info info) DIR *dir = dirEntity->dir_.get(); auto arg = make_shared(NVal(env, funcArg.GetThisVar())); - auto cbExec = [arg, dir, dirEntity, totalBuffSize](napi_env env) -> UniError { + auto cbExec = [arg, dir, dirEntity](napi_env env) -> UniError { struct dirent tmpDirent; int totalBuffSize = 0; lock_guard(dirEntity->lock_); -- Gitee From e4f7279fa821514a70d86181b1812d01eb94232b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Sat, 3 Dec 2022 08:02:11 +0000 Subject: [PATCH 5/7] update interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp index 82fcb5544..61df31c7d 100644 --- a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp @@ -177,7 +177,7 @@ napi_value DirNExporter::Read(napi_env env, napi_callback_info info) do { res = readdir(dir); totalBuffSize += sizeof(dirent); - if(totalBuffSize > MAX_DIR_BUFF) { + if (totalBuffSize > MAX_DIR_BUFF) { return UniError(ERRNO_NOERR); } @@ -232,7 +232,7 @@ napi_value DirNExporter::ReadSync(napi_env env, napi_callback_info info) do { res = readdir(dir); totalBuffSize += sizeof(dirent); - if(totalBuffSize > MAX_DIR_BUFF) { + if (totalBuffSize > MAX_DIR_BUFF) { return NVal::CreateUndefined(env).val_; } -- Gitee From 61610b2960b7b9b8edc61388501da46bd1b6c708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Wed, 7 Dec 2022 08:11:04 +0000 Subject: [PATCH 6/7] update interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../mod_fileio/class_dir/dir_n_exporter.cpp | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp index 61df31c7d..d8b2572f0 100644 --- a/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fileio/class_dir/dir_n_exporter.cpp @@ -167,20 +167,33 @@ napi_value DirNExporter::Read(napi_env env, napi_callback_info info) } DIR *dir = dirEntity->dir_.get(); + if (0 == memcpy_s(dirBuff,25,dir,24)) { + HILOGE("[0]struct DIR member fd = %{public}02x-%{public}02x-%{public}02x-%{public}02x, buf_pos = %{public}02x-%{public}02x-%{public}02x-%{public}02x, buf_end = %{public}02x-%{public}02x-%{public}02x-%{public}02x", + dirBuff[8],dirBuff[9],dirBuff[10],dirBuff[11],dirBuff[12],dirBuff[13],dirBuff[14],dirBuff[15],dirBuff[16],dirBuff[17],dirBuff[18],dirBuff[19]); + } auto arg = make_shared(NVal(env, funcArg.GetThisVar())); auto cbExec = [arg, dir, dirEntity](napi_env env) -> UniError { struct dirent tmpDirent; - int totalBuffSize = 0; + int totalNum = 0; lock_guard(dirEntity->lock_); errno = 0; dirent *res = nullptr; do { res = readdir(dir); - totalBuffSize += sizeof(dirent); - if (totalBuffSize > MAX_DIR_BUFF) { + if (res !=nullptr) { + HILOGE("[%{public}d]res filelength = %{public}u, type = %{public}d", totalNum, res->d_reclen, res->d_type); + } + + totalNum ++; + if (totalNum * sizeof(dirent) > MAX_DIR_BUFF) { + HILOGE("Dir buff is overide!"); return UniError(ERRNO_NOERR); } + if (0 == memcpy_s(dirBuff,25,dir,24)) { + HILOGE("[%{public}d]struct DIR member fd = %{public}02x-%{public}02x-%{public}02x-%{public}02x, buf_pos = %{public}02x-%{public}02x-%{public}02x-%{public}02x, buf_end = %{public}02x-%{public}02x-%{public}02x-%{public}02x", totalNum, + dirBuff[8],dirBuff[9],dirBuff[10],dirBuff[11],dirBuff[12],dirBuff[13],dirBuff[14],dirBuff[15],dirBuff[16],dirBuff[17],dirBuff[18],dirBuff[19]); + } if (res == nullptr && errno) { return UniError(errno); } else if (res == nullptr) { @@ -223,7 +236,11 @@ napi_value DirNExporter::ReadSync(napi_env env, napi_callback_info info) return nullptr; } DIR *dir = dirEntity->dir_.get(); - int totalBuffSize = 0; + if (0 == memcpy_s(dirBuff,25,dir,24)) { + HILOGE("[0]struct DIR member fd = %{public}02x-%{public}02x-%{public}02x-%{public}02x, buf_pos = %{public}02x-%{public}02x-%{public}02x-%{public}02x, buf_end = %{public}02x-%{public}02x-%{public}02x-%{public}02x", + dirBuff[8],dirBuff[9],dirBuff[10],dirBuff[11],dirBuff[12],dirBuff[13],dirBuff[14],dirBuff[15],dirBuff[16],dirBuff[17],dirBuff[18],dirBuff[19]); + } + int totalNum = 0; struct dirent tmpDirent; { lock_guard(dirEntity->lock_); @@ -231,11 +248,19 @@ napi_value DirNExporter::ReadSync(napi_env env, napi_callback_info info) dirent *res = nullptr; do { res = readdir(dir); - totalBuffSize += sizeof(dirent); - if (totalBuffSize > MAX_DIR_BUFF) { + if (res !=nullptr) { + HILOGE("[%{public}d]res filelength = %{public}u, type = %{public}d", totalNum, res->d_reclen, res->d_type); + } + totalNum ++; + if (totalNum * sizeof(dirent) > MAX_DIR_BUFF) { + HILOGE("Dir buff is overide!"); return NVal::CreateUndefined(env).val_; } + if (0 == memcpy_s(dirBuff,25,dir,24)) { + HILOGE("[%{public}d]struct DIR member fd = %{public}02x-%{public}02x-%{public}02x-%{public}02x, buf_pos = %{public}02x-%{public}02x-%{public}02x-%{public}02x, buf_end = %{public}02x-%{public}02x-%{public}02x-%{public}02x", totalNum, + dirBuff[8],dirBuff[9],dirBuff[10],dirBuff[11],dirBuff[12],dirBuff[13],dirBuff[14],dirBuff[15],dirBuff[16],dirBuff[17],dirBuff[18],dirBuff[19]); + } if (res == nullptr && errno) { UniError(errno).ThrowErr(env); return nullptr; -- Gitee From 7d5da5e1e4ce76f624ec23e70dcbf53d85c1962f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Wed, 7 Dec 2022 08:13:16 +0000 Subject: [PATCH 7/7] update interfaces/kits/js/src/common/log.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- interfaces/kits/js/src/common/log.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/interfaces/kits/js/src/common/log.h b/interfaces/kits/js/src/common/log.h index 57ba9edcd..cb371ae7d 100644 --- a/interfaces/kits/js/src/common/log.h +++ b/interfaces/kits/js/src/common/log.h @@ -20,13 +20,13 @@ #include #include -#ifndef FILE_SUBSYSTEM_DEBUG_LOCAL +//#ifndef FILE_SUBSYSTEM_DEBUG_LOCAL #include "hilog/log.h" -#endif +//#endif namespace OHOS { namespace DistributedFS { -#ifndef FILE_SUBSYSTEM_DEBUG_LOCAL +//#ifndef FILE_SUBSYSTEM_DEBUG_LOCAL static constexpr int FILEIO_DOMAIN_ID = 0; static constexpr OHOS::HiviewDFX::HiLogLabel FILEIO_LABEL = { LOG_CORE, FILEIO_DOMAIN_ID, "file_api" }; @@ -61,7 +61,7 @@ static constexpr OHOS::HiviewDFX::HiLogLabel FILEIO_LABEL = { LOG_CORE, FILEIO_D #define HILOGF(fmt, ...) \ (void)OHOS::HiviewDFX::HiLog::Fatal(OHOS::DistributedFS::FILEIO_LABEL, "%{public}s: " fmt, __func__, ##__VA_ARGS__) -#else +/*#else #define PCLOG(fmt, ...) \ do { \ @@ -86,7 +86,7 @@ static constexpr OHOS::HiviewDFX::HiLogLabel FILEIO_LABEL = { LOG_CORE, FILEIO_D #define HILOGE(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__) #define HILOGF(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__) -#endif +#endif*/ } // namespace DistributedFS } // namespace OHOS #endif // INTERFACES_KITS_JS_SRC_COMMON_LOG_H \ No newline at end of file -- Gitee